├── README.md ├── sketchbook ├── UdpTempController │ ├── UdpTempController.ino │ ├── findChips.ino │ ├── getState.ino │ ├── getTemp.ino │ ├── mdnsUpdate.ino │ ├── printWifiStatus.ino │ ├── processUDP.ino │ ├── scanChips.ino │ ├── setState.ino │ ├── showEEPROM.ino │ ├── udpStatusUpdate.ino │ ├── updateLCD.ino │ └── updateState.ino └── libraries │ ├── EEPROMAnything │ └── EEPROMAnything.h │ └── ESP8266LCD │ ├── ESP8266LCD.cpp │ ├── ESP8266LCD.h │ ├── ESP8266MCP23017.cpp │ └── ESP8266MCP23017.h ├── sql └── esp8266.sql ├── utilities ├── DigitalPinTest │ └── DigitalPinTest.ino ├── EEPROM │ ├── eeprom_clear │ │ └── eeprom_clear.ino │ ├── eeprom_read │ │ └── eeprom_read.ino │ └── eeprom_write │ │ └── eeprom_write.ino ├── MacAddress │ └── MacAddress.ino ├── RGBLCDTest │ └── RGBLCDTest.ino ├── TestUdpTempController.php └── TestUdpTempControllerStatus.php └── web ├── PHP_GnuPlot.php ├── SensorStatus.php ├── accessDatabase.php ├── header.html ├── modifySettings.php ├── plotData.php ├── udpRequest.php └── updateStatus.php /README.md: -------------------------------------------------------------------------------- 1 | #UDPTempController 2 | An ESP8266-based WiFi Temperature Controller that uses Avahi for network discovery, 1-Wire DS18B20 Digital Thermometers, DS2406+ Digital Switches, and an I2C-controlled 20x4 LCD. 3 | 4 | ##Programming Environment 5 | All of my coding was done using an ESP-12 board and the ESP8266 Arduino IDE described at https://github.com/esp8266/Arduino and using a simple Black PL2303HX USB To TTL To UART RS232 COM Cable Module Converter to upload the program. 6 | 7 | The code also works with the ESP-01 board, but the I2C lines are not physically available, so the LCD monitor is not used with that configuration. 8 | 9 | ##Setup 10 | Before using the code for the first time, I recommend clearing the EEPROM on the ESP8266 to insure that it can be set up properly. I've included 'eeprom_clear.ino' in the utilities folder for that reason. 11 | 12 | Attach your DS18B20 Digital Thermometer and DS2406+ switches, and I2C 20x4 LCD. 13 | 14 | Once the EEPROM has been cleared, compile and upload the 'UdpTempController.ino' files. Once uploaded, make surethat the Serial monitor is open and set to '112500 baud', and 'Newline' for any text sent. 15 | 16 | The Serial Monitor will ask for an SSID, PASSWD. Set these values to match your WiFi Network. 17 | 18 | The Serial Monitor will then ask is you want to use DHCP to get an IP address. If you answer "Y", the ESP8266 will attempt to negotiate an IP address via DHCP. A "N" answer will result in a request for an IP address, Gateway address and Subnet Mask. These values MUST be enterd as "XXX.XXX.XXX.XXX" with leading zeros where the "XXX" value is less than 100, ie "002". 19 | 20 | The Serial Monitor will then ask for a udpPort value. This is the port address that the board will use when communicating with the network. 21 | 22 | If all goes well, the Serial Monitor should show the results of the attempt to access your WiFi Network. 23 | 24 | ##Using the UDPTempController 25 | 26 | I've also included a short PHP utility that will communicate with the UdpTempController and allow the state of the chips to be monitored and set. 27 | 28 | To use it, you'll need PHP5 and avahi-resolve installed. 29 | 30 | On the command line enter: 31 | `php TestUdpTempController.php esp8266.local` 32 | 33 | The program will attempt to locate the UdpTempController, and if successful, will display the IP address of the UdpTempController, and prompt for input. 34 | 35 | ##Commands 36 | In general, commands take the form of a single Uppercase Letter command, followed by a numeric or alpha value. single character values immediately proceed the command with no intervening spaces. 37 | As an example, to turn on the first switch in maual mode (more about modes in a moment), the command would be `AN`. 38 | 39 | Commands that include a numeric value have no intervening spaces. An example would be setting the Upper Temperature Value in Automatic mode: `UF80`, which sets the Upper Temperature Value to 80°F 40 | 41 | Commands that require a multi-character alpha-numeric string have an intervening space. 42 | As an example, to re-name the local url of the UdpTempController, the command would be `N "DomainName"`. 43 | 44 | ##Web Page and MySql 45 | Included are web pages and a MySql file which can be used to create a web page that can monitor multiple ESP boards, display the results on a web page, save the results into a set of MySQL tables, and display a graph of the results. The updates to the page occur every two seconds, and updated data is inserted into the database every minute. 46 | -------------------------------------------------------------------------------- /sketchbook/UdpTempController/UdpTempController.ino: -------------------------------------------------------------------------------- 1 | /* 2 | UdpTempController.ino 3 | 4 | Version 0.0.14 5 | Last Modified 9/03/2015 6 | By Jim Mayhugh 7 | 8 | V0.0.3 - added upper and lower temp control to UDP commands 9 | added updateState.ino 10 | 11 | V0.0.4 - added findChips.ino to discover chips and set DS18B20 12 | to 9-bit resolution 13 | added setDebug for serial debug output 0 = no debug, 1 or higher = debug 14 | 15 | V0.0.5 - Added mode control 16 | 17 | V0.0.6 - using Ticker.h for DS18B20 reads 18 | 19 | V0.0.7 - Added Debug Mode and set domain name 20 | Added setting initial SSID, PASSWD and UDP port via Serial Monitor 21 | and saving to EEPROM. 22 | 23 | V0.0.8 - Added time delay in seconds for switches. 24 | Added additional UDP Commands. 25 | Added individual debug values for troubleshooting purposes. 26 | 27 | V0.0.9 - Added logging to remote port 28 | Display Error message on LCD if unit fails to connect to intranet 29 | Show ESP8266 MAC Address in Serial Monitor 30 | Display EEPROM Values in Serial Monitor on startup 31 | 32 | V0.0.10 - Changed 1-Wire Data line to GPIO12, as GPIO2 is also the Alternate TX 33 | pin when loading software. 34 | 35 | V0.0.11 - Added staticIP, staticGateway, and staticSubnet in EPROM to prevent 36 | connection loss when DHCP expires. Values MUST be entered as 37 | "xxx.xxx.xxx.xxx", using leading zeros. 38 | 39 | V0.0.12 - Can select Static IP or DHCP on initial power-up via Serial monitor. 40 | 1-Wire data line reset to GPIO2 to accomodate ESP-01 board 41 | 42 | V0.0.13 - Removed tempName and switchName from 1-wire structures 43 | 44 | V0.0.14 - Added code to read temp and switch settings 45 | 46 | Permission is hereby granted, free of charge, to any person obtaining 47 | a copy of this software and associated documentation files (the 48 | "Software"), to deal in the Software without restriction, including 49 | without limitation the rights to use, copy, modify, merge, publish, 50 | distribute, sublicense, and/or sell copies of the Software, and to 51 | permit persons to whom the Software is furnished to do so, subject to 52 | the following conditions: 53 | 54 | The above copyright notice and this permission notice shall be 55 | included in all copies or substantial portions of the Software. 56 | 57 | This software uses multiple libraries that are subject to additional 58 | licenses as defined by the author of that software. It is the user's 59 | and developer's responsibility to determine and adhere to any additional 60 | requirements that may arise. 61 | 62 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 63 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 64 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 65 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 66 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 67 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 68 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 69 | 70 | Configuration : 71 | Enter the ssid and password of your Wifi AP. 72 | Enter the port number your server is listening on. 73 | 74 | */ 75 | 76 | #include 77 | #include 78 | #include 79 | #include 80 | #include 81 | #include 82 | #include 83 | #include 84 | #include 85 | //#include 86 | #include 87 | #include 88 | #include 89 | 90 | int status = WL_IDLE_STATUS; 91 | const uint8_t domainCnt = 15; 92 | const uint8_t bonjourCnt = 50; 93 | const uint8_t usemDNS = 0xAA; 94 | 95 | const uint16_t udpDebug = 0x0001; 96 | const uint16_t tempDebug = 0x0002; 97 | const uint16_t switchDebug = 0x0004; 98 | const uint16_t lcdDebug = 0x0008; 99 | const uint16_t eepromDebug = 0x0010; 100 | const uint16_t findChipsDebug = 0x0020; 101 | const uint16_t mdnsDebug = 0x0040; 102 | 103 | uint16_t setDebug = 0x0000; 104 | 105 | char packetBuffer[512]; // buffer to hold incoming and outgoing packets 106 | char updateBuffer[128]; // buffer to hold updateStatus 107 | char lcdBuffer[21]; 108 | 109 | int16_t noBytes, packetCnt; 110 | int16_t delayVal = 25, sDelayVal = 5000, uDelayVal = 60; 111 | int16_t lowerC, lowerF, upperC, upperF; 112 | uint32_t lowerDelay, upperDelay, tempDelay, startUpperTimer, startLowerTimer; 113 | int8_t i; 114 | uint8_t udpAddr[5]; 115 | uint8_t data[15]; 116 | uint8_t chip[8]; 117 | uint8_t chipStatus[3]; 118 | char *delim =","; 119 | char *result = NULL; 120 | char mDNSdomain[domainCnt] = "ESP8266"; 121 | char bonjourBuf[bonjourCnt] = ""; 122 | uint8_t chipCnt = 0; 123 | uint8_t mode = 0xFF, mDNSset; 124 | 125 | // EEPROM Storage locations 126 | const uint16_t EEPROMsize = 512; 127 | const uint16_t EEMode = 0x0008; // 'M' = Manual, 'A' = Automatic, anything else = uninitialized 128 | const uint16_t EELowerC = 0x0010; 129 | const uint16_t EELowerF = 0x0020; 130 | const uint16_t EEUpperC = 0x0030; 131 | const uint16_t EEUpperF = 0x0040; 132 | const uint16_t EEmDNSset = 0x0050; // 0xAA = set, anything else is uninitialized 133 | const uint16_t EEmDNSdomain = 0x0060; // mDNS domain name 134 | const uint16_t EEWiFiSet = 0x0080; // 0xAA = set, anything else is unitialized 135 | const uint16_t EEssid = 0x0090; // WiFi SSID string 136 | const uint16_t EEpasswd = 0x00B0; // WiFi PASSWD string 137 | const uint16_t EEuseUDPport = 0x00E0; // 0xAA = set, anything else is uninitialized 138 | const uint16_t EEudpPort = 0x00F0; // UDP port address 139 | const uint16_t EEs0DelaySet = 0x0100; // 0xAA = set, anything else is uninitialized 140 | const uint16_t EEs0Delay = 0x0110; // Switch1 Delay 141 | const uint16_t EEs1DelaySet = 0x0120; // 0xAA = set, anything else is uninitialized 142 | const uint16_t EEs1Delay = 0x0130; // Switch1 Delay 143 | const uint16_t EEipSet = 0x0140; // 0xAA = set, anything else is uninitialized 144 | const uint16_t EEipAddress = 0x0150; // static IP Address 145 | const uint16_t EEipGateway = 0x0160; // static IP gateway 146 | const uint16_t EEipSubnet = 0x0170; // static IP subnet 147 | 148 | const uint8_t useS0 = 0xAA; 149 | const uint8_t useS1 = 0xAA; 150 | uint8_t s0Set = 0, s1Set = 0; 151 | 152 | // WiFi stuff 153 | const uint8_t WiFiStrCnt = 32; // max string length 154 | const uint8_t ipStrCnt = 20; 155 | const uint8_t useWiFi = 0xAA; 156 | const uint8_t useUDPport = 0xAA; 157 | const uint8_t udpPortCnt = 4; 158 | const uint8_t macCnt = 6; 159 | uint8_t wifiSet = 0, udpSet = 0; 160 | uint8_t macAddress[macCnt] = {0,0,0,0,0,0}; 161 | char ssid[WiFiStrCnt] = "SSID"; // your network SSID (name) 162 | char passwd[WiFiStrCnt] = "PASSWD"; // your network password 163 | char *ipBuf = "255,255,255,255"; 164 | char *gwBuf = "255,255,255,255"; 165 | char *snBuf = "255,255,255,255"; 166 | uint16_t udpPort = 0x0000; // local port to listen for UDP packets 167 | 168 | const uint8_t useStaticIP = 0xAA; 169 | const uint8_t useDHCP = 0x55; 170 | uint8_t staticIPset = 0; 171 | uint8_t ipArray[4] = {0 ,0, 0, 0}; 172 | uint8_t gwArray[4] = {0 ,0, 0, 0}; 173 | uint8_t snArray[4] = {0 ,0, 0, 0}; 174 | 175 | /* 176 | IPAddress staticIP(192, 168, 1, 164); 177 | IPAddress staticGateway(192, 168, 1, 1); 178 | IPAddress staticSubnet(255, 255, 255, 0); 179 | */ 180 | 181 | IPAddress staticIP(255,255,255,255); 182 | IPAddress staticGateway(255,255,255,255); 183 | IPAddress staticSubnet(255, 255, 255, 255); 184 | 185 | // LCD Stuff 186 | 187 | // The shield uses the I2C SCL pin 5 and SDA pin 4 on the ESP8266. 188 | // Make sure that SDA and SCA use 4.7K pullup resistors 189 | // You can connect other I2C sensors to the I2C bus and share 190 | // the I2C bus. 191 | 192 | uint8_t const lcdChars = 20; 193 | uint8_t const lcdRows = 4; 194 | 195 | ESP8266LCD lcd = ESP8266LCD(7); 196 | 197 | // A UDP instance to let us send and receive packets over UDP 198 | WiFiUDP Udp; 199 | 200 | // A UDP instance to allow interval updates to be sent 201 | IPAddress statusIP; 202 | uint16_t statusPort; 203 | WiFiUDP udpStatus; 204 | 205 | // OneWire Stuff 206 | // Family codes 207 | const uint8_t t3tcID = 0xAA; // Teensy 3.0 1-wire slave with MAX31855 K-type Thermocouple chip 208 | const uint8_t dsLCD = 0x47; // Teensy 3.x 1-wire slave 4x20 HD44780 LCD 209 | const uint8_t dsGLCDP = 0x45; // Teensy 3.1 1-wire slave 800x400 7" GLCD with Paging 210 | const uint8_t dsGLCD = 0x44; // Teensy 3.1 1-wire slave 800x400 7" GLCD 211 | const uint8_t max31850ID = 0x3B; // MAX31850 K-type Thermocouple chip 212 | const uint8_t ds2762ID = 0x30; // Maxim 2762 digital k-type thermocouple 213 | const uint8_t ds18b20ID = 0x28; // Maxim DS18B20 digital Thermometer device 214 | const uint8_t ds2406ID = 0x12; // Maxim DS2406+ digital switch 215 | 216 | // DS2406+ Digital Switch Family Code and registers 217 | const uint8_t dsPIO_A = 0x20; 218 | const uint8_t dsPIO_B = 0x40; 219 | const uint8_t ds2406MemWr = 0x55; 220 | const uint8_t ds2406MemRd = 0xaa; 221 | const uint8_t ds2406AddLow = 0x07; 222 | const uint8_t ds2406AddHi = 0x00; 223 | const uint8_t ds2406PIOAoff = 0x3f; 224 | const uint8_t ds2406PIOAon = 0x1f; 225 | const uint8_t ds2406End = 0xff; 226 | 227 | const uint8_t switchStatusON = 'N'; 228 | const uint8_t switchStatusOFF = 'F'; 229 | 230 | const uint8_t oneWireAddress = 12; // OneWire Bus Address - use pin GPIO12 for ESP-12 and ESP-07 boards 231 | //const uint8_t oneWireAddress = 2; // OneWire Bus Address - use pin GPIO2 for ESP-01 board 232 | 233 | const uint8_t chipAddrSize = 8; // 64bit OneWire Address 234 | const uint8_t tempDataSize = 9; // temp data 235 | const uint8_t switchDataSize = 13; // switch data 236 | const uint8_t chipNameSize = 15; 237 | const uint8_t cDelayVal = 150; //delay reading DS18B20 238 | 239 | bool tempConversion = FALSE; 240 | bool sendStatus = FALSE; 241 | bool softReset = FALSE; 242 | bool udpStatusSet = FALSE; 243 | bool mdnsUpdateStatus = FALSE; 244 | // Temp Stuff 245 | typedef struct 246 | { 247 | uint8_t tempAddr[chipAddrSize]; 248 | uint8_t tempData[tempDataSize]; 249 | int16_t tempFahrenheit; 250 | int16_t tempCelsius; 251 | }tempStruct; 252 | 253 | const tempStruct tempClear = { {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}, 0, 0}; 254 | 255 | tempStruct ds18b20 = { {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}, 0, 0}; 256 | 257 | // SwitchStuff 258 | const uint8_t maxSwitches = 2; 259 | const uint8_t upper = 0, lower = 1; 260 | 261 | typedef struct 262 | { 263 | uint8_t switchAddr[chipAddrSize]; 264 | uint8_t switchData[switchDataSize]; 265 | char switchStatus; 266 | uint32_t switchDelay; 267 | bool switchDelaySet; 268 | }switchStruct; 269 | 270 | const switchStruct switchClear = { {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0}, 'F', 0, FALSE}; 271 | 272 | switchStruct ds2406[maxSwitches] = 273 | { 274 | { {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0}, 'F', 0, FALSE}, 275 | { {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0}, 'F', 0, FALSE} 276 | }; 277 | 278 | OneWire ds(oneWireAddress); // on pin 2 (a 4.7K resistor is necessary) 279 | Ticker ds18; // timer to allow DS18B20 to be read 280 | Ticker ds2406_0; 281 | Ticker ds2406_1; 282 | Ticker update; 283 | Ticker mdnsServer; 284 | 285 | // mDNS stuff 286 | // multicast DNS responder 287 | MDNSResponder mdns; 288 | uint16_t mdnsUpdateDelay = 10; 289 | char bonjourNameBuf[25]; 290 | 291 | 292 | void setup(void) 293 | { 294 | // Open serial communications and wait for port to open: 295 | ESP.wdtDisable(); // disable the watchdog Timer 296 | 297 | Serial.begin(115200); 298 | delay(sDelayVal); 299 | 300 | setDebug |= eepromDebug; // disply eeprom statue during startup 301 | EEPROM.begin(EEPROMsize); 302 | showEEPROM(); 303 | setDebug &= ~eepromDebug; 304 | 305 | Serial.print("MAC Address = "); 306 | uint8_t *mac = WiFi.macAddress(macAddress); 307 | for(uint8_t q = 0; q < macCnt; q++) 308 | { 309 | if(mac[q] < 0x10) 310 | Serial.print("0"); 311 | Serial.print(mac[q], HEX); 312 | if(q < (macCnt - 1)) 313 | Serial.print(":"); 314 | } 315 | Serial.println(); 316 | 317 | lcd.begin(lcdChars, lcdRows); 318 | lcd.clear(); 319 | lcd.home(); 320 | 321 | if(wifiSet != useWiFi) 322 | { 323 | uint8_t z = 0; 324 | 325 | for(uint8_t z = 0; z < WiFiStrCnt; z++) // clear ssid and passwd string 326 | { 327 | ssid[z] = 0xFF; 328 | passwd[z] = 0xFF; 329 | } 330 | 331 | Serial.print("Enter SSID:"); 332 | while(1) 333 | { 334 | while(Serial.available()) 335 | { 336 | ssid[z] = Serial.read(); 337 | if( (ssid[z] == 0x0A) || (ssid[z] == 0x0D) || (ssid[z] == 0x00) ) 338 | { 339 | ssid[z] = 0x00; 340 | break; 341 | } 342 | z++; 343 | if(z == 30) 344 | { 345 | ssid[z] = 0x00; 346 | break; 347 | } 348 | } 349 | if(ssid[z] == 0x00) 350 | break; 351 | } 352 | Serial.println(ssid); 353 | 354 | z = 0; 355 | Serial.print("Enter PASSWD:"); 356 | while(1) 357 | { 358 | while(Serial.available()) 359 | { 360 | passwd[z] = Serial.read(); 361 | if( (passwd[z] == 0x0A) || (passwd[z] == 0x0D) || (passwd[z] == 0x00) ) 362 | { 363 | passwd[z] = 0x00; 364 | break; 365 | } 366 | z++; 367 | if(z == 30) 368 | { 369 | passwd[z] = 0x00; 370 | break; 371 | } 372 | } 373 | if(passwd[z] == 0x00) 374 | break; 375 | } 376 | Serial.println(passwd); 377 | wifiSet = useWiFi; 378 | updateEEPROM(EEWiFiSet); 379 | } 380 | 381 | if( (staticIPset != useStaticIP) && (staticIPset != useDHCP) ) 382 | { 383 | char c = 0x00; 384 | Serial.print("Use DHCP?:"); 385 | while(1) 386 | { 387 | while(Serial.available()) 388 | { 389 | c = Serial.read(); 390 | break; 391 | } 392 | if(c != 0x00) 393 | { 394 | Serial.println(c); 395 | break; 396 | } 397 | } 398 | 399 | delay(100); 400 | while(Serial.available()) 401 | Serial.read(); // flush the buffer 402 | 403 | switch(c) 404 | { 405 | case 'N': 406 | case 'n': 407 | { 408 | uint8_t z = 0; 409 | 410 | delay(100); 411 | while(Serial.available()) 412 | Serial.read(); // flush the buffer 413 | 414 | Serial.print("Enter Static IP:"); 415 | while(1) 416 | { 417 | while(Serial.available()) 418 | { 419 | ipBuf[z] = Serial.read(); 420 | if( (ipBuf[z] == 0x0A) || (ipBuf[z] == 0x0D) || (ipBuf[z] == 0x00) ) 421 | { 422 | ipBuf[z] = 0x00; 423 | break; 424 | } 425 | z++; 426 | if(z >= ipStrCnt) 427 | { 428 | ipBuf[z] = 0x00; 429 | break; 430 | } 431 | } 432 | if(ipBuf[z] == 0x00) 433 | break; 434 | } 435 | Serial.println(ipBuf); 436 | strToIP(ipArray, ipBuf); 437 | staticIP[0] = ipArray[0]; 438 | staticIP[1] = ipArray[1]; 439 | staticIP[2] = ipArray[2]; 440 | staticIP[3] = ipArray[3]; 441 | Serial.print("staticIP = "); 442 | Serial.println(staticIP); 443 | 444 | z = 0; 445 | 446 | while(Serial.available()) 447 | Serial.read(); // flush the buffer 448 | 449 | Serial.print("Enter Static Gateway:"); 450 | while(1) 451 | { 452 | while(Serial.available()) 453 | { 454 | gwBuf[z] = Serial.read(); 455 | Serial.write(gwBuf[z]); 456 | if( (gwBuf[z] == 0x0A) || (gwBuf[z] == 0x0D) || (gwBuf[z] == 0x00) ) 457 | { 458 | Serial.print("gwBuf["); 459 | Serial.print(z); 460 | Serial.print("] = 0x"); 461 | Serial.println(gwBuf[z], HEX); 462 | gwBuf[z] = 0x00; 463 | Serial.println("EOT"); 464 | break; 465 | } 466 | z++; 467 | if(z >= ipStrCnt) 468 | { 469 | Serial.println("String Too Long"); 470 | gwBuf[z] = 0x00; 471 | break; 472 | } 473 | } 474 | if(gwBuf[z] == 0x00) 475 | { 476 | Serial.println("EOL"); 477 | break; 478 | } 479 | } 480 | Serial.println(gwBuf); 481 | strToIP(gwArray, gwBuf); 482 | staticGateway[0] = gwArray[0]; 483 | staticGateway[1] = gwArray[1]; 484 | staticGateway[2] = gwArray[2]; 485 | staticGateway[3] = gwArray[3]; 486 | Serial.print("staticGateway = "); 487 | Serial.println(staticGateway); 488 | 489 | z = 0; 490 | 491 | while(Serial.available()) 492 | Serial.read(); // flush the buffer 493 | 494 | Serial.print("Enter Static subnet:"); 495 | while(1) 496 | { 497 | while(Serial.available()) 498 | { 499 | snBuf[z] = Serial.read(); 500 | if( (snBuf[z] == 0x0A) || (snBuf[z] == 0x0D) || (snBuf[z] == 0x00) ) 501 | { 502 | snBuf[z] = 0x00; 503 | break; 504 | } 505 | z++; 506 | if(z >= ipStrCnt) 507 | { 508 | snBuf[z] = 0x00; 509 | break; 510 | } 511 | } 512 | if(snBuf[z] == 0x00) 513 | break; 514 | } 515 | Serial.println(snBuf); 516 | strToIP(snArray, snBuf); 517 | staticSubnet[0] = snArray[0]; 518 | staticSubnet[1] = snArray[1]; 519 | staticSubnet[2] = snArray[2]; 520 | staticSubnet[3] = snArray[3]; 521 | Serial.print("staticSubnet = "); 522 | Serial.println(staticSubnet); 523 | staticIPset = useStaticIP; 524 | updateEEPROM(EEipSet); 525 | break; 526 | } 527 | 528 | case 'Y': 529 | case 'y': 530 | default: 531 | { 532 | staticIPset = useDHCP; 533 | updateEEPROM(EEipSet); 534 | break; 535 | } 536 | 537 | } 538 | } 539 | 540 | while(Serial.available()) 541 | Serial.read(); // flush the buffer 542 | 543 | if(udpSet != useUDPport) 544 | { 545 | uint8_t z = 0; 546 | 547 | for(uint8_t z = 0; z < udpPortCnt; z++) // clear UDP Port Address string 548 | { 549 | udpAddr[z] = 0xFF; 550 | } 551 | 552 | Serial.print("Enter UDP Port:"); 553 | while(1) 554 | { 555 | while(Serial.available()) 556 | { 557 | udpAddr[z] = Serial.read(); 558 | if( (udpAddr[z] == 0x0A) || (udpAddr[z] == 0x0D) || (udpAddr[z] == 0x00) ) 559 | { 560 | udpAddr[z] = 0x00; 561 | break; 562 | } 563 | z++; 564 | if(z == 30) 565 | { 566 | udpAddr[z] = 0x00; 567 | break; 568 | } 569 | } 570 | if(udpAddr[z] == 0x00) 571 | break; 572 | } 573 | udpPort = atoi( (char *) udpAddr); 574 | udpSet = useUDPport; 575 | Serial.println(udpPort); 576 | updateEEPROM(EEuseUDPport); 577 | } 578 | 579 | // setting up Station AP 580 | WiFi.begin(ssid, passwd); 581 | 582 | // Wait for connect to AP 583 | Serial.print("[Connecting]"); 584 | Serial.print(ssid); 585 | int tries=0; 586 | while (WiFi.status() != WL_CONNECTED) { 587 | delay(500); 588 | Serial.print("."); 589 | tries++; 590 | if (tries > 30) 591 | { 592 | Serial.println(); 593 | Serial.println("Unable to Connect - Check and restart"); 594 | lcd.clear(); 595 | lcd.home(); 596 | lcd.print(" UNABLE TO CONNECT "); 597 | lcd.setCursor(0, 1); 598 | lcd.print(" PLEASE CHECK "); 599 | lcd.setCursor(0, 2); 600 | lcd.print(" AND RESET "); 601 | while(1) 602 | { 603 | lcd.noDisplay(); 604 | delay(1000); 605 | lcd.display(); 606 | delay(1000); 607 | } 608 | // break; 609 | } 610 | } 611 | Serial.println(); 612 | 613 | if(staticIPset == useStaticIP) 614 | { 615 | WiFi.config(staticIP, staticGateway, staticSubnet); 616 | Serial.print("Using Static IP - "); 617 | }else{ 618 | Serial.print("Using DHCP - "); 619 | } 620 | IPAddress ip = WiFi.localIP(); 621 | Serial.print("Connected to wifi at IP Address: "); 622 | Serial.println(ip); 623 | 624 | /* 625 | if(ESP8266Bonjour.begin(bonjourNameBuf)) 626 | { 627 | Serial.println("Bonjour Service started"); 628 | sprintf(bonjourBuf, "%s._discover", bonjourNameBuf); 629 | ESP8266Bonjour.addServiceRecord(bonjourBuf, udpPort, MDNSServiceUDP); 630 | // I2CEEPROM_writeAnything(I2CEEPROMbjAddr, bonjourNameBuf, I2C0x50); 631 | }else{ 632 | Serial.println(F("Bonjour Service failed")); 633 | } 634 | ESP8266Bonjour.run(); 635 | */ 636 | // Set up mDNS responder: 637 | // - first argument is the domain name, in this example 638 | // the fully-qualified domain name is "esp8266.local" 639 | // - second argument is the IP address to advertise 640 | // we send our IP address on the WiFi network 641 | 642 | 643 | if(mDNSset != usemDNS) 644 | { 645 | sprintf(mDNSdomain, "%s%d", mDNSdomain, ip[3]); 646 | } 647 | 648 | if (!mdns.begin(mDNSdomain, WiFi.localIP())) 649 | { 650 | Serial.println("Error setting up MDNS responder!"); 651 | while(1) { 652 | delay(1000); 653 | } 654 | } 655 | startMDNSupdate(); 656 | Serial.print("mDNS responder started with "); 657 | Serial.println(mDNSdomain); 658 | 659 | if(setDebug > 0) 660 | { 661 | printWifiStatus(); 662 | } 663 | 664 | Serial.print("Udp server started at port at "); 665 | Serial.println(udpPort); 666 | Udp.begin(udpPort); 667 | findChips(); 668 | } 669 | 670 | void loop(void) 671 | { 672 | noBytes = Udp.parsePacket(); 673 | 674 | scanChips(); 675 | updateState(); 676 | updateLCD(); 677 | 678 | if ( noBytes ) 679 | processUDP(); 680 | 681 | if ( sendStatus == TRUE ) 682 | { 683 | statusUpdate(); 684 | sendStatus = FALSE; 685 | } 686 | 687 | if ( mdnsUpdateStatus == TRUE ) 688 | startMDNSupdate(); 689 | } 690 | 691 | 692 | -------------------------------------------------------------------------------- /sketchbook/UdpTempController/findChips.ino: -------------------------------------------------------------------------------- 1 | /* 2 | UdpTempController - findChips.ino 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | This software uses multiple libraries that are subject to additional 16 | licenses as defined by the author of that software. It is the user's 17 | and developer's responsibility to determine and adhere to any additional 18 | requirements that may arise. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | void findChips(void) 30 | { 31 | chipCnt = 0; 32 | while(1) 33 | { 34 | if ( !ds.search(chip)) { 35 | if(setDebug & findChipsDebug) 36 | { 37 | Serial.println("No more addresses."); 38 | Serial.println(); 39 | } 40 | ds.reset_search(); 41 | delay(250); 42 | chipCnt = 0; 43 | return; 44 | } 45 | 46 | if(setDebug & findChipsDebug) 47 | { 48 | Serial.print("ROM ="); 49 | for( i = 0; i < 8; i++) 50 | { 51 | Serial.write(' '); 52 | Serial.print(chip[i], HEX); 53 | } 54 | } 55 | 56 | if (ds.crc8(chip, 7) != chip[7]) 57 | { 58 | if(setDebug & findChipsDebug) 59 | { 60 | Serial.println("CRC is not valid!"); 61 | } 62 | return; 63 | } 64 | 65 | if(setDebug & findChipsDebug) 66 | { 67 | Serial.println(); 68 | } 69 | 70 | switch(chip[0]) // set DS18B20 to 9-bit resolution 71 | { 72 | case ds18b20ID: 73 | { 74 | for(i = 0; i < chipAddrSize; i++) 75 | ds18b20.tempAddr[i] = chip[i]; 76 | ds.reset(); 77 | ds.select(ds18b20.tempAddr); 78 | ds.write(0x4E); // write to scratchpad; 79 | ds.write(0x00); // low alarm 80 | ds.write(0x00); // high alarm 81 | ds.write(0x1F); // configuration register - 9 bit accuracy (0.5deg C) 82 | delay(5); 83 | ds.reset(); 84 | ds.select(ds18b20.tempAddr); 85 | ds.write(0x48); // copy scratchpad to EEPROM; 86 | delay(5); 87 | if(setDebug & findChipsDebug) 88 | { 89 | Serial.println("DS18B20 resolution set to 9-bit"); 90 | } 91 | for(i = 0; i < chipAddrSize; i++) 92 | chip[i] = 0; 93 | break; 94 | } 95 | 96 | case ds2406ID: 97 | { 98 | for(i = 0; i < chipAddrSize; i++) 99 | ds2406[chipCnt].switchAddr[i] = chip[i]; 100 | setState(chipCnt, ds2406PIOAoff); 101 | if(setDebug & findChipsDebug) 102 | { 103 | Serial.print("DS2406["); 104 | Serial.print(chipCnt); 105 | Serial.println("] Turned OFF"); 106 | } 107 | for(i = 0; i < chipAddrSize; i++) 108 | chip[i] = 0; 109 | chipCnt++; 110 | break; 111 | } 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /sketchbook/UdpTempController/getState.ino: -------------------------------------------------------------------------------- 1 | /* 2 | UdpTempController - getstate.ino 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | This software uses multiple libraries that are subject to additional 16 | licenses as defined by the author of that software. It is the user's 17 | and developer's responsibility to determine and adhere to any additional 18 | requirements that may arise. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | void getState(uint8_t x) 30 | { 31 | uint16_t chipCRCval, chipBufferCRC; 32 | ds.reset(); 33 | ds.select(ds2406[x].switchAddr); 34 | ds.write(ds2406MemRd); 35 | ds2406[x].switchData[0] = ds2406MemRd; 36 | ds.write(0x0); //2406 Addr Low 37 | ds2406[x].switchData[1] = 0; 38 | ds.write(0x0); //2406 Addr Hgh 39 | ds2406[x].switchData[2] = 0; 40 | for(int i = 3; i < switchDataSize; i++) 41 | { 42 | ds2406[x].switchData[i] = ds.read(); 43 | } 44 | ds.reset(); 45 | 46 | chipCRCval = ~(ds.crc16(ds2406[x].switchData, 11)) & 0xFFFF; 47 | chipBufferCRC = ((ds2406[x].switchData[12] << 8) | ds2406[x].switchData[11]); 48 | 49 | if(setDebug & switchDebug) 50 | { 51 | Serial.print("ds2406["); 52 | Serial.print(x); 53 | Serial.print("].switchData = "); 54 | for(int i = 0; i < switchDataSize; i++) 55 | { 56 | if(ds2406[x].switchData[i] < 0x0f) 57 | { 58 | Serial.print("0x0"); 59 | }else{ 60 | Serial.print("0x"); 61 | } 62 | Serial.print(ds2406[x].switchData[i], HEX); 63 | Serial.print(", "); 64 | } 65 | Serial.println(); 66 | Serial.print("chipCRCval = 0x"); 67 | Serial.print(chipCRCval, HEX); 68 | Serial.print(", chipBufferCRC = 0x"); 69 | Serial.println(chipBufferCRC, HEX); 70 | } 71 | 72 | if(ds2406[x].switchData[10] & dsPIO_A) 73 | { 74 | ds2406[x].switchStatus = switchStatusOFF; 75 | }else{ 76 | ds2406[x].switchStatus = switchStatusON; 77 | } 78 | 79 | if(setDebug & switchDebug) 80 | { 81 | Serial.print(", ds2406["); 82 | Serial.print(x); 83 | Serial.print("].switchStatus = "); 84 | Serial.println( (char) ds2406[x].switchStatus ); 85 | } 86 | } 87 | 88 | -------------------------------------------------------------------------------- /sketchbook/UdpTempController/getTemp.ino: -------------------------------------------------------------------------------- 1 | /* 2 | UdpTempController - getTemp.ino 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | This software uses multiple libraries that are subject to additional 16 | licenses as defined by the author of that software. It is the user's 17 | and developer's responsibility to determine and adhere to any additional 18 | requirements that may arise. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | void getTemp(void) 30 | { 31 | if(tempConversion == FALSE) 32 | { 33 | if(setDebug & tempDebug) 34 | Serial.println("tempConversion is FALSE, Starting Temp Conversion"); 35 | ds.reset(); 36 | ds.select(ds18b20.tempAddr); 37 | ds.write(0x44, 1); // start conversion, with parasite power on at the end 38 | tempConversion = TRUE; 39 | tempDelay = millis(); 40 | ds18.attach_ms(cDelayVal, tempReady); 41 | }else{ 42 | if(setDebug & tempDebug) 43 | Serial.println("tempConversion is TRUE"); 44 | } 45 | } 46 | 47 | void tempReady(void) 48 | { 49 | ds18.detach(); 50 | readTemp(); 51 | } 52 | 53 | void readTemp(void) 54 | { 55 | if(setDebug & tempDebug) 56 | { 57 | Serial.print("tempDelay = "); 58 | Serial.println(millis() - tempDelay); 59 | Serial.println("Reading Temp"); 60 | } 61 | ds.reset(); 62 | ds.select(ds18b20.tempAddr); 63 | ds.write(0xBE); // Read Scratchpad 64 | 65 | for ( i = 0; i < tempDataSize; i++) // we need 9 int8_ts 66 | { 67 | ds18b20.tempData[i] = ds.read(); 68 | } 69 | 70 | if(setDebug & tempDebug) 71 | { 72 | Serial.print(" Data = "); 73 | for ( i = 0; i < tempDataSize; i++) // we need 9 int8_ts 74 | { 75 | if(ds18b20.tempData[i] < 0x0f) 76 | { 77 | Serial.print("0x0"); 78 | }else{ 79 | Serial.print("0x"); 80 | } 81 | Serial.print(ds18b20.tempData[i], HEX); 82 | Serial.print(", "); 83 | } 84 | Serial.print("CRC="); 85 | Serial.print(ds.crc8(ds18b20.tempData, 8), HEX); 86 | Serial.println(); 87 | } 88 | 89 | // Convert the data to actual temperature 90 | // because the result is a 16 bit signed integer, it should 91 | // be stored to an "int16_t" type, which is always 16 bits 92 | // even when compiled on a 32 bit processor. 93 | int16_t raw = (ds18b20.tempData[1] << 8) | ds18b20.tempData[0]; 94 | 95 | int8_t cfg = (ds18b20.tempData[4] & 0x60); 96 | 97 | // at lower res, the low bits are undefined, so let's zero them 98 | if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms 99 | else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms 100 | else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms 101 | //// default is 12 bit resolution, 750 ms conversion time 102 | 103 | ds18b20.tempCelsius = raw >> 4; 104 | ds18b20.tempFahrenheit = (((raw >> 4) * 9)/5) + 32; 105 | 106 | if(setDebug & tempDebug) 107 | { 108 | Serial.print(" Temperature = "); 109 | Serial.print(ds18b20.tempCelsius); 110 | Serial.print(" Celsius, "); 111 | Serial.print(ds18b20.tempFahrenheit); 112 | Serial.println(" Fahrenheit"); 113 | } 114 | tempConversion = FALSE; 115 | 116 | } 117 | 118 | -------------------------------------------------------------------------------- /sketchbook/UdpTempController/mdnsUpdate.ino: -------------------------------------------------------------------------------- 1 | /* 2 | UdpTempController - mdnsUpdate.ino 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software.0 14 | This software uses multiple libraries that are subject to additional 15 | licenses as defined by the author of that software. It is the user's 16 | and developer's responsibility to determine and adhere to any additional 17 | requirements that may arise. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 23 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | */ 27 | 28 | 29 | void startMDNSupdate(void) 30 | { 31 | if(setDebug & mdnsDebug) 32 | Serial.println("Enter startMDNSupdate"); 33 | mdns.update(); 34 | mdnsServer.attach(mdnsUpdateDelay, mdnsStatus); 35 | mdnsUpdateStatus = FALSE; 36 | if(setDebug & mdnsDebug) 37 | Serial.println("Exit startMDNSupdate"); 38 | } 39 | 40 | 41 | void mdnsStatus(void) 42 | { 43 | mdnsServer.detach(); 44 | mdnsUpdateStatus = TRUE; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /sketchbook/UdpTempController/printWifiStatus.ino: -------------------------------------------------------------------------------- 1 | /* 2 | UdpTempController - printWifiStatus.ino 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | This software uses multiple libraries that are subject to additional 16 | licenses as defined by the author of that software. It is the user's 17 | and developer's responsibility to determine and adhere to any additional 18 | requirements that may arise. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | void printWifiStatus() 30 | { 31 | // print the SSID of the network you're attached to: 32 | Serial.print("SSID: "); 33 | Serial.println(WiFi.SSID()); 34 | 35 | // print your WiFi shield's IP address: 36 | IPAddress ip = WiFi.localIP(); 37 | Serial.print("IP Address: "); 38 | Serial.println(ip); 39 | } 40 | 41 | void strToIP(uint8_t *ipArray, char *str) 42 | { 43 | ipArray[0] = (uint8_t) atoi(str); 44 | ipArray[1] = (uint8_t) atoi((char *) &str[4]); 45 | ipArray[2] = (uint8_t) atoi((char *) &str[8]); 46 | ipArray[3] = (uint8_t) atoi((char *) &str[12]); 47 | } 48 | -------------------------------------------------------------------------------- /sketchbook/UdpTempController/processUDP.ino: -------------------------------------------------------------------------------- 1 | /* 2 | UdpTempController - processUDP.ino 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | This software uses multiple libraries that are subject to additional 16 | licenses as defined by the author of that software. It is the user's 17 | and developer's responsibility to determine and adhere to any additional 18 | requirements that may arise. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | void processUDP(void) 30 | { 31 | if(setDebug & udpDebug) 32 | { 33 | Serial.print(millis() / 1000); 34 | Serial.print(":Packet of "); 35 | Serial.print(noBytes); 36 | Serial.print(" received from "); 37 | Serial.print(Udp.remoteIP()); 38 | Serial.print(":"); 39 | Serial.println(Udp.remotePort(), HEX); 40 | } 41 | 42 | // We've received a packet, read the data from it 43 | Udp.read(packetBuffer,noBytes); // read the packet into the buffer 44 | 45 | // display the packet contents in HEX 46 | if(setDebug & udpDebug) 47 | { 48 | for (int i = 1;i <= noBytes; i++) 49 | { 50 | Serial.print(packetBuffer[i-1]); 51 | if (i % 32 == 0) 52 | { 53 | Serial.println(); 54 | } 55 | } // end for 56 | Serial.println(); 57 | } 58 | 59 | switch(packetBuffer[0]) 60 | { 61 | case 'A': 62 | { 63 | if(packetBuffer[1] == 'N') 64 | { 65 | setState(upper, ds2406PIOAon); 66 | packetCnt = sprintf(packetBuffer, "%s", "Turning Upper LED ON"); 67 | }else{ 68 | setState(upper, ds2406PIOAoff); 69 | packetCnt = sprintf(packetBuffer, "%s", "Turning Upper LED OFF"); 70 | } 71 | break; 72 | } 73 | 74 | case 'B': 75 | { 76 | if(packetBuffer[1] == 'N') 77 | { 78 | setState(lower, ds2406PIOAon); 79 | packetCnt = sprintf(packetBuffer, "%s", "Turning Lower LED ON"); 80 | }else{ 81 | setState(lower, ds2406PIOAoff); 82 | packetCnt = sprintf(packetBuffer, "%s", "Turning Lower LED OFF"); 83 | } 84 | break; 85 | } 86 | 87 | case 'D': 88 | { 89 | if(setDebug & udpDebug) 90 | Serial.print("Setting setDebug to 0x"); 91 | setDebug = atoi(&packetBuffer[1]); 92 | Serial.println(setDebug, HEX); 93 | packetCnt = sprintf(packetBuffer, "setDebug = %0X", setDebug); 94 | break; 95 | } 96 | 97 | case 'M': 98 | { 99 | switch(packetBuffer[1]) 100 | { 101 | case 'A': 102 | { 103 | mode = 'A'; 104 | packetCnt = sprintf(packetBuffer, "Mode is %c - Automatic", mode); 105 | break; 106 | } 107 | 108 | case 'M': 109 | { 110 | mode = 'M'; 111 | packetCnt = sprintf(packetBuffer, "Mode is %c - Manual", mode); 112 | break; 113 | } 114 | 115 | default: 116 | { 117 | packetCnt = sprintf(packetBuffer, "Invalid Option - mode is %c", mode); 118 | break; 119 | } 120 | } 121 | updateEEPROM(EEMode); 122 | break; 123 | } 124 | 125 | case 'N': 126 | { 127 | uint8_t setDomain = 0, y; 128 | 129 | if((packetBuffer[1] == ' ') && (isalnum(packetBuffer[2])) ) 130 | { 131 | for(y = 0; y < domainCnt; y++) 132 | { 133 | if(isalnum(packetBuffer[y+2])) 134 | { 135 | if(setDebug & udpDebug) 136 | Serial.print(packetBuffer[y+2]); 137 | continue; 138 | }else if( ((packetBuffer[y+2] == 0x00) || 139 | (packetBuffer[y+2] == 0x0A) || 140 | (packetBuffer[y+2] == 0x0D)) && 141 | y > 0 142 | ){ 143 | if(setDebug & udpDebug) 144 | Serial.println(); 145 | setDomain = 1; 146 | break; 147 | } 148 | } 149 | 150 | if(setDomain == 1) 151 | { 152 | mDNSset = usemDNS; 153 | for(y = 0; y < domainCnt; y++) // clear domain name buffer 154 | mDNSdomain[y] = 0; 155 | for(y = 0; y < domainCnt; y++) 156 | { 157 | if(isalnum(packetBuffer[y+2])) // move domain name to domain buffer 158 | mDNSdomain[y] = packetBuffer[y+2]; 159 | } 160 | updateEEPROM(EEmDNSset); 161 | softReset = TRUE; 162 | } 163 | } 164 | packetCnt = sprintf(packetBuffer, "mDNSdomain = %s", mDNSdomain); 165 | break; 166 | } 167 | 168 | case 'R': 169 | { 170 | if(udpStatusSet == TRUE) 171 | { 172 | update.detach(); 173 | udpStatus.stop(); 174 | } 175 | statusIP = Udp.remoteIP(); 176 | statusPort = Udp.remotePort(); 177 | // statusPort = atoi(&packetBuffer[1]); 178 | udpStatus.begin(statusPort); 179 | startUdpStatusUpdate(); 180 | packetCnt = sprintf(packetBuffer, "udpStatusUpdate begun at IP %d.%d.%d.%d, port %d", statusIP[0], statusIP[1], statusIP[2], statusIP[3], statusPort); 181 | udpStatusSet = TRUE; 182 | break; 183 | } 184 | 185 | /* 186 | Process: Sets the appropriate temp value and delay for automatic temperature control 187 | Format: S,LOC,TYPE,TEMP,DELAY 188 | Where: 189 | S = The UDP command 'S' 190 | LOC = The First 'U' or second 'L' switch 191 | TYPE = Either Celsius 'C' or Fahrenheit 'F' 192 | TEMP = The Temperature in integer degrees, ie "100" 193 | DELAY = The Delay before activating the switch in seconds, ie "10" 194 | */ 195 | case 'S': 196 | { 197 | char *pos = strchr(packetBuffer, ','); 198 | char switchLOC = (char) *(pos+1); 199 | pos = strchr(pos+1, ','); 200 | char switchTYPE = (char) *(pos+1); 201 | pos = strchr(pos+1, ','); 202 | char *pos1 = strchr(pos+1, ','); 203 | *pos1 = NULL; 204 | char *switchTEMP = pos+1; 205 | char *switchDELAY = pos1+1; 206 | 207 | if(setDebug & udpDebug) 208 | { 209 | Serial.print("switchLOC = "); 210 | Serial.println(switchLOC); 211 | Serial.print("switchTYPE = "); 212 | Serial.println(switchTYPE); 213 | Serial.print("switchTEMP = "); 214 | Serial.println(switchTEMP); 215 | Serial.print("switchDELAY = "); 216 | Serial.println(switchDELAY); 217 | } 218 | 219 | uint8_t useUpper = 0, useLower = 0, sError = 0; 220 | int16_t useTemp = atoi(switchTEMP); 221 | uint16_t useDelay = atoi(switchDELAY); 222 | 223 | switch(switchLOC) 224 | { 225 | case 'U': 226 | { 227 | useUpper = 1; 228 | ds2406[upper].switchDelay = useDelay; 229 | s0Set = useS0; 230 | updateEEPROM(EEs0Delay); 231 | break; 232 | } 233 | 234 | case 'L': 235 | { 236 | useLower = 1; 237 | ds2406[lower].switchDelay = useDelay; 238 | s1Set = useS1; 239 | updateEEPROM(EEs1Delay); 240 | break; 241 | } 242 | 243 | default: 244 | { 245 | sError = 1; 246 | break; 247 | } 248 | } 249 | 250 | switch(switchTYPE) 251 | { 252 | 253 | case 'C': 254 | { 255 | if(useLower == 1) 256 | { 257 | lowerC = useTemp; 258 | lowerF = (((useTemp * 9) / 5) + 32); 259 | updateEEPROM(EELowerC); 260 | }else if(useUpper == 1) 261 | { 262 | upperC = useTemp; 263 | upperF = (((useTemp * 9) / 5) + 32); 264 | updateEEPROM(EEUpperC); 265 | }else{ 266 | sError = 1; 267 | } 268 | break; 269 | } 270 | 271 | case 'F': 272 | { 273 | if(useLower == 1) 274 | { 275 | lowerF = useTemp; 276 | lowerC = (((useTemp - 32) * 5) / 9); 277 | updateEEPROM(EELowerF); 278 | }else if(useUpper == 1) 279 | { 280 | upperF = useTemp; 281 | upperC = (((useTemp - 32) * 5) / 9); 282 | updateEEPROM(EEUpperF); 283 | }else{ 284 | sError = 1; 285 | } 286 | break; 287 | } 288 | 289 | default: 290 | { 291 | sError = 1; 292 | break; 293 | } 294 | } 295 | 296 | if(sError == 0) 297 | { 298 | packetCnt = sprintf(packetBuffer, "Upper is %d F, %d C, %d Sec, Lower is %d F, %d C, %d Sec", 299 | upperF, upperC, ds2406[upper].switchDelay, 300 | lowerF, lowerC, ds2406[lower].switchDelay 301 | ); 302 | }else{ 303 | packetCnt = sprintf(packetBuffer, "Invalid Option - Upper value is %d F, %d C, %d Sec, Lower is %d F, %d C, %d Sec", 304 | upperF, upperC, ds2406[upper].switchDelay, 305 | lowerF, lowerC, ds2406[lower].switchDelay 306 | ); 307 | 308 | } 309 | break; 310 | } 311 | 312 | case 'V': 313 | { 314 | sprintf(packetBuffer, "%d, %d, %d, %d, %d, %d", 315 | upperF, upperC, ds2406[upper].switchDelay, 316 | lowerF, lowerC, ds2406[lower].switchDelay 317 | ); 318 | break; 319 | } 320 | 321 | default: 322 | { 323 | packetCnt = sprintf(packetBuffer, "%d, %d, %c, %c, %s", ds18b20.tempCelsius, ds18b20.tempFahrenheit, 324 | ds2406[upper].switchStatus, ds2406[lower].switchStatus, mDNSdomain); 325 | break; 326 | } 327 | } 328 | 329 | if(setDebug & udpDebug) 330 | Serial.println(packetBuffer); 331 | Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); 332 | Udp.write(packetBuffer, packetCnt); 333 | Udp.endPacket(); 334 | } 335 | -------------------------------------------------------------------------------- /sketchbook/UdpTempController/scanChips.ino: -------------------------------------------------------------------------------- 1 | /* 2 | UdpTempController - scanChips.ino 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | This software uses multiple libraries that are subject to additional 16 | licenses as defined by the author of that software. It is the user's 17 | and developer's responsibility to determine and adhere to any additional 18 | requirements that may arise. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | void scanChips(void) 30 | { 31 | getState(0); 32 | getState(1); 33 | getTemp(); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /sketchbook/UdpTempController/setState.ino: -------------------------------------------------------------------------------- 1 | /* 2 | UdpTempController - setState.ino 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | This software uses multiple libraries that are subject to additional 16 | licenses as defined by the author of that software. It is the user's 17 | and developer's responsibility to determine and adhere to any additional 18 | requirements that may arise. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | void setState(uint8_t x, uint8_t state) 30 | { 31 | if(setDebug & switchDebug) 32 | { 33 | Serial.print("Setting "); 34 | switch(x) 35 | { 36 | case upper: 37 | { 38 | Serial.print("upper LED "); 39 | break; 40 | } 41 | 42 | case lower: 43 | { 44 | Serial.print("lower LED "); 45 | break; 46 | } 47 | 48 | default: 49 | { 50 | Serial.print(" UNKNOWN LED "); 51 | Serial.print(x); 52 | break; 53 | } 54 | } 55 | switch(state) 56 | { 57 | case ds2406PIOAon: 58 | { 59 | Serial.println("ON"); 60 | break; 61 | } 62 | 63 | case ds2406PIOAoff: 64 | { 65 | Serial.println("OFF"); 66 | break; 67 | } 68 | 69 | default: 70 | { 71 | Serial.println("UNKNOWN"); 72 | break; 73 | } 74 | } 75 | Serial.print("Switch["); 76 | if(x == lower) 77 | { 78 | Serial.print("lower] = "); 79 | }else{ 80 | Serial.print("upper] = "); 81 | } 82 | for(int q = 0; q < chipAddrSize; q++) 83 | { 84 | if(ds2406[x].switchAddr[q] < 0x10) 85 | { 86 | Serial.print("0x0"); 87 | }else{ 88 | Serial.print("0x"); 89 | } 90 | Serial.print(ds2406[x].switchAddr[q], HEX); 91 | if(q < chipAddrSize - 1) 92 | { 93 | Serial.print(", "); 94 | }else{ 95 | Serial.println(); 96 | } 97 | } 98 | } 99 | ds.reset(); 100 | ds.select(ds2406[x].switchAddr); 101 | ds.write(ds2406MemWr); 102 | ds.write(ds2406AddLow); 103 | ds.write(ds2406AddHi); 104 | ds.write(state); 105 | for ( int i = 0; i < 6; i++) 106 | { 107 | data[i] = ds.read(); 108 | } 109 | ds.write(ds2406End); 110 | ds.reset(); 111 | 112 | } 113 | -------------------------------------------------------------------------------- /sketchbook/UdpTempController/showEEPROM.ino: -------------------------------------------------------------------------------- 1 | /* 2 | UdpTempController - showEEPROM.ino 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | This software uses multiple libraries that are subject to additional 16 | licenses as defined by the author of that software. It is the user's 17 | and developer's responsibility to determine and adhere to any additional 18 | requirements that may arise. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | void showEEPROM(void) 30 | { 31 | EEPROM_readAnything(EELowerC, lowerC); 32 | EEPROM_readAnything(EELowerF, lowerF); 33 | EEPROM_readAnything(EEUpperC, upperC); 34 | EEPROM_readAnything(EEUpperF, upperF); 35 | EEPROM_readAnything(EEMode, mode); 36 | EEPROM_readAnything(EEmDNSset, mDNSset); 37 | EEPROM_readAnything(EEipSet, staticIPset); 38 | if(staticIPset == useStaticIP) 39 | { 40 | EEPROM_readAnything(EEipAddress, staticIP); 41 | EEPROM_readAnything(EEipGateway, staticGateway); 42 | EEPROM_readAnything(EEipSubnet, staticSubnet); 43 | } 44 | if(mDNSset == usemDNS) 45 | EEPROM_readAnything(EEmDNSdomain, mDNSdomain); 46 | EEPROM_readAnything(EEWiFiSet, wifiSet); 47 | if(wifiSet == useWiFi) 48 | { 49 | EEPROM_readAnything(EEssid, ssid); 50 | EEPROM_readAnything(EEpasswd, passwd); 51 | } 52 | EEPROM_readAnything(EEuseUDPport, udpSet); 53 | if(udpSet == useUDPport) 54 | { 55 | EEPROM_readAnything(EEudpPort, udpPort); 56 | } 57 | EEPROM_readAnything(EEs0DelaySet, s0Set); 58 | if(s0Set == useS0) 59 | { 60 | EEPROM_readAnything(EEs0Delay, ds2406[0].switchDelay); 61 | } 62 | EEPROM_readAnything(EEs1DelaySet, s1Set); 63 | if(s1Set == useS1) 64 | { 65 | EEPROM_readAnything(EEs1Delay, ds2406[1].switchDelay); 66 | } 67 | 68 | if(setDebug & eepromDebug) 69 | { 70 | Serial.print("lowerC = "); 71 | Serial.print(lowerC); 72 | Serial.print(", lowerF = "); 73 | Serial.print(lowerF); 74 | Serial.print(", upperC = "); 75 | Serial.print(upperC); 76 | Serial.print(", upperF = "); 77 | Serial.println(upperF); 78 | Serial.print("ds2406[0].switchDelay = "); 79 | Serial.print(ds2406[0].switchDelay); 80 | Serial.print(", ds2406[1].switchDelay = "); 81 | Serial.println(ds2406[1].switchDelay); 82 | Serial.print("mode = "); 83 | 84 | switch(mode) 85 | { 86 | case 'A': 87 | { 88 | Serial.print("Automatic"); 89 | break; 90 | } 91 | 92 | case 'M': 93 | { 94 | Serial.print("Manual"); 95 | break; 96 | } 97 | 98 | default: 99 | { 100 | Serial.print("Uninitialized"); 101 | break; 102 | } 103 | } 104 | Serial.println(); 105 | delay(100); 106 | Serial.print("mDNSdomain = "); 107 | Serial.println(mDNSdomain); 108 | delay(100); 109 | Serial.print("ssid = "); 110 | Serial.println(ssid); 111 | delay(100); 112 | Serial.print("passwd = "); 113 | Serial.println(passwd); 114 | delay(100); 115 | Serial.print("staticIP = "); 116 | Serial.println(staticIP); 117 | delay(100); 118 | Serial.print("staticGateway = "); 119 | Serial.println(staticGateway); 120 | delay(100); 121 | Serial.print("staticSubnet = "); 122 | Serial.println(staticSubnet); 123 | delay(100); 124 | Serial.print("udpPort = "); 125 | Serial.println(udpPort); 126 | } 127 | 128 | } 129 | 130 | void updateEEPROM(uint16_t level) 131 | { 132 | switch(level) 133 | { 134 | case EELowerC: 135 | case EELowerF: 136 | { 137 | EEPROM_writeAnything(EELowerC, lowerC); 138 | EEPROM_writeAnything(EELowerF, lowerF); 139 | break; 140 | } 141 | 142 | case EEUpperC: 143 | case EEUpperF: 144 | { 145 | EEPROM_writeAnything(EEUpperC, upperC); 146 | EEPROM_writeAnything(EEUpperF, upperF); 147 | break; 148 | } 149 | 150 | case EEMode: 151 | { 152 | EEPROM_writeAnything(EEMode, mode); 153 | break; 154 | } 155 | 156 | case EEmDNSset: 157 | { 158 | EEPROM_writeAnything(EEmDNSset, mDNSset); 159 | EEPROM_writeAnything(EEmDNSdomain, mDNSdomain); 160 | break; 161 | } 162 | 163 | case EEWiFiSet: 164 | { 165 | EEPROM_writeAnything(EEWiFiSet, wifiSet); 166 | EEPROM_writeAnything(EEssid, ssid); 167 | EEPROM_writeAnything(EEpasswd, passwd); 168 | break; 169 | } 170 | 171 | case EEipSet: 172 | { 173 | EEPROM_writeAnything(EEipSet, staticIPset); 174 | for(uint8_t x = 0; x < 4; x++) 175 | { 176 | EEPROM_writeAnything(EEipAddress, staticIP); 177 | EEPROM_writeAnything(EEipGateway, staticGateway); 178 | EEPROM_writeAnything(EEipSubnet, staticSubnet); 179 | } 180 | break; 181 | } 182 | 183 | case EEuseUDPport: 184 | { 185 | EEPROM_writeAnything(EEuseUDPport, udpSet); 186 | EEPROM_writeAnything(EEudpPort, udpPort); 187 | break; 188 | } 189 | 190 | case EEs0Delay: 191 | { 192 | EEPROM_writeAnything(EEs0DelaySet, s0Set); 193 | EEPROM_writeAnything(EEs0Delay, ds2406[0].switchDelay); 194 | break; 195 | } 196 | 197 | case EEs1Delay: 198 | { 199 | EEPROM_writeAnything(EEs1DelaySet, s1Set); 200 | EEPROM_writeAnything(EEs1Delay, ds2406[1].switchDelay); 201 | break; 202 | } 203 | } 204 | EEPROM.commit(); 205 | showEEPROM(); 206 | } 207 | -------------------------------------------------------------------------------- /sketchbook/UdpTempController/udpStatusUpdate.ino: -------------------------------------------------------------------------------- 1 | /* 2 | UdpTempController - updStatusUpdate.ino 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software.0 14 | This software uses multiple libraries that are subject to additional 15 | licenses as defined by the author of that software. It is the user's 16 | and developer's responsibility to determine and adhere to any additional 17 | requirements that may arise. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 23 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | */ 27 | 28 | void startUdpStatusUpdate(void) 29 | { 30 | update.attach(uDelayVal, udpSendStatus); 31 | } 32 | 33 | void udpSendStatus(void) 34 | { 35 | update.detach(); 36 | sendStatus = TRUE; 37 | update.attach(uDelayVal, udpSendStatus); 38 | } 39 | 40 | void statusUpdate(void) 41 | { 42 | uint16_t bufferCnt = sprintf(updateBuffer, "%d, %d, %c, %c", ds18b20.tempCelsius, ds18b20.tempFahrenheit, 43 | ds2406[upper].switchStatus, ds2406[lower].switchStatus); 44 | udpStatus.beginPacket(statusIP, statusPort); 45 | udpStatus.write(updateBuffer, bufferCnt); 46 | udpStatus.endPacket(); 47 | } 48 | -------------------------------------------------------------------------------- /sketchbook/UdpTempController/updateLCD.ino: -------------------------------------------------------------------------------- 1 | /* 2 | UdpTempController - updateLCD.ino 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software.0 14 | This software uses multiple libraries that are subject to additional 15 | licenses as defined by the author of that software. It is the user's 16 | and developer's responsibility to determine and adhere to any additional 17 | requirements that may arise. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 23 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | */ 27 | 28 | void updateLCD(void) 29 | { 30 | if(setDebug & lcdDebug) 31 | { 32 | Serial.println("Writing to LCD"); 33 | } 34 | lcd.home(); 35 | IPAddress ip = WiFi.localIP(); 36 | sprintf(lcdBuffer, "%d.%d.%d.%d:%d", ip[0], ip[1], ip[2], ip[3], udpPort); 37 | lcd.print(lcdBuffer); 38 | delay(delayVal); 39 | lcd.setCursor(0, 1); 40 | lcd.print(mDNSdomain); 41 | lcd.setCursor(16, 1); 42 | switch(mode) 43 | { 44 | case 'A': 45 | { 46 | lcd.print("Auto"); 47 | break; 48 | } 49 | 50 | case 'M': 51 | { 52 | lcd.print("Man "); 53 | break; 54 | } 55 | 56 | default: 57 | { 58 | lcd.print("None"); 59 | break; 60 | } 61 | } 62 | delay(delayVal); 63 | lcd.setCursor(0, 2); 64 | sprintf(lcdBuffer, "Temp: %d F, %d C", ds18b20.tempFahrenheit, ds18b20.tempCelsius); 65 | lcd.print(lcdBuffer); 66 | delay(delayVal); 67 | if(setDebug & lcdDebug) 68 | Serial.println(lcdBuffer); 69 | lcd.setCursor(0, 3); 70 | sprintf(lcdBuffer, "Switch1:%c Switch2:%c", ds2406[0].switchStatus, ds2406[1].switchStatus); 71 | lcd.print(lcdBuffer); 72 | delay(delayVal); 73 | if(setDebug & lcdDebug) 74 | { 75 | Serial.println(lcdBuffer); 76 | Serial.println("Finished writing to LCD"); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /sketchbook/UdpTempController/updateState.ino: -------------------------------------------------------------------------------- 1 | /* 2 | UdpTempController - updateState.ino 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | This software uses multiple libraries that are subject to additional 16 | licenses as defined by the author of that software. It is the user's 17 | and developer's responsibility to determine and adhere to any additional 18 | requirements that may arise. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | void updateState(void) 30 | { 31 | if(mode == 'A') 32 | { 33 | if(ds18b20.tempFahrenheit >= upperF) 34 | { 35 | if(ds2406[upper].switchDelay == 0) 36 | { 37 | setState(upper, ds2406PIOAon); // cool things off 38 | if(setDebug & switchDebug) 39 | Serial.println("Set upper Switch immediate- ON"); 40 | }else if(ds2406[upper].switchDelaySet == FALSE){ 41 | if(setDebug & switchDebug) 42 | { 43 | Serial.print("set upperDelay = "); 44 | Serial.println(ds2406[upper].switchDelay); 45 | } 46 | ds2406[upper].switchDelaySet = TRUE; 47 | ds2406_0.attach_ms((ds2406[upper].switchDelay * 1000), startUpper); 48 | startUpperTimer = millis(); 49 | } 50 | }else{ 51 | if(setDebug & switchDebug) 52 | Serial.println("Set upper - OFF, "); 53 | setState(upper, ds2406PIOAoff); 54 | } 55 | 56 | if(ds18b20.tempFahrenheit <= lowerF) 57 | { 58 | if(ds2406[lower].switchDelay == 0) 59 | { 60 | setState(lower, ds2406PIOAon); // heat things up 61 | if(setDebug & switchDebug) 62 | Serial.println("Set lower Switch immediate - ON"); 63 | }else if(ds2406[lower].switchDelaySet == FALSE){ 64 | if(setDebug & switchDebug) 65 | { 66 | Serial.print("set lowerDelay = "); 67 | Serial.println(ds2406[lower].switchDelay); 68 | } 69 | ds2406[lower].switchDelaySet = TRUE; 70 | ds2406_1.attach_ms((ds2406[lower].switchDelay * 1000), startLower); 71 | startLowerTimer = millis(); 72 | } 73 | }else{ 74 | if(setDebug & switchDebug) 75 | Serial.println("lower - OFF"); 76 | setState(lower, ds2406PIOAoff); 77 | } 78 | } 79 | } 80 | 81 | void startUpper(void) 82 | { 83 | ds2406_0.detach(); 84 | if(ds18b20.tempFahrenheit >= upperF) 85 | { 86 | setState(upper, ds2406PIOAon); // cool things off 87 | }else{ 88 | setState(upper, ds2406PIOAoff); 89 | } 90 | ds2406[upper].switchDelaySet = FALSE; 91 | if(setDebug & switchDebug) 92 | { 93 | Serial.printf("set upper switch ON after a "); 94 | Serial.print(millis() - startUpperTimer); 95 | Serial.println(" delay"); 96 | } 97 | } 98 | 99 | void startLower(void) 100 | { 101 | ds2406_1.detach(); 102 | if(ds18b20.tempFahrenheit <= lowerF) 103 | { 104 | setState(lower, ds2406PIOAon); // heat things up 105 | }else{ 106 | setState(lower, ds2406PIOAoff); 107 | } 108 | ds2406[lower].switchDelaySet = FALSE; 109 | if(setDebug & switchDebug) 110 | { 111 | Serial.printf("set lower switch ON after a "); 112 | Serial.print(millis() - startLowerTimer); 113 | Serial.println(" delay"); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /sketchbook/libraries/EEPROMAnything/EEPROMAnything.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include // for type definitions 3 | 4 | template int EEPROM_writeAnything(uint16_t ee, const T& value) 5 | { 6 | const byte* p = (const byte*)(const void*)&value; 7 | uint32_t i; 8 | for (i = 0; i < sizeof(value); i++) 9 | { 10 | const byte b = *p; 11 | if( EEPROM.read( ee ) != b ) 12 | EEPROM.write( ee++, b ), ++p; 13 | else 14 | ee++, p++; 15 | } 16 | return i; 17 | } 18 | 19 | template int EEPROM_readAnything(uint16_t ee, T& value) 20 | { 21 | byte* p = (byte*)(void*)&value; 22 | uint32_t i; 23 | for (i = 0; i < sizeof(value); i++) 24 | *p++ = EEPROM.read(ee++); 25 | return i; 26 | } 27 | -------------------------------------------------------------------------------- /sketchbook/libraries/ESP8266LCD/ESP8266LCD.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | Version 0.0.2 3 | Last Modified 04/05/2015 4 | By Jim Mayhugh 5 | 6 | This software borrows heavily from the Adafruit library, 7 | All text and attributions required are below. 8 | 9 | This is a library for the Adafruit RGB 16x2 LCD Shield 10 | Pick one up at the Adafruit shop! 11 | ---------> http://http://www.adafruit.com/products/714 12 | 13 | The shield uses I2C to communicate, 2 pins are required to 14 | interface 15 | Adafruit invests time and resources providing this open source code, 16 | please support Adafruit and open-source hardware by purchasing 17 | products from Adafruit! 18 | 19 | Written by Limor Fried/Ladyada for Adafruit Industries. 20 | BSD license, all text above must be included in any redistribution 21 | ****************************************************/ 22 | 23 | 24 | #include "ESP8266LCD.h" 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #if ( __MK20DX128__ ) || ( __MK20DX256__ ) 31 | //#include 32 | #include 33 | #else 34 | #include 35 | #endif 36 | 37 | #ifdef __AVR__ 38 | #define WIRE Wire 39 | #else // Arduino Due 40 | #define WIRE Wire 41 | #endif 42 | 43 | #if ARDUINO >= 100 44 | #include "Arduino.h" 45 | #else 46 | #include "WProgram.h" 47 | #endif 48 | 49 | // When the display powers up, it is configured as follows: 50 | // 51 | // 1. Display clear 52 | // 2. Function set: 53 | // DL = 1; 8-bit interface data 54 | // N = 0; 1-line display 55 | // F = 0; 5x8 dot character font 56 | // 3. Display on/off control: 57 | // D = 0; Display off 58 | // C = 0; Cursor off 59 | // B = 0; Blinking off 60 | // 4. Entry mode set: 61 | // I/D = 1; Increment by 1 62 | // S = 0; No shift 63 | // 64 | // Note, however, that resetting the Arduino doesn't reset the LCD, so we 65 | // can't assume that its in that state when a sketch starts (and the 66 | // RGBLCDShield constructor is called). 67 | 68 | ESP8266LCD::ESP8266LCD(uint8_t addr) { 69 | 70 | if(addr >= 0 && addr <= 7) 71 | { 72 | _i2cAddr = addr; 73 | }else{ 74 | _i2cAddr = 0; 75 | } 76 | 77 | _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS; 78 | 79 | // the I/O expander pinout 80 | _rs_pin = 15; 81 | _rw_pin = 14; 82 | _enable_pin = 13; 83 | _data_pins[0] = 12; // really d4 84 | _data_pins[1] = 11; // really d5 85 | _data_pins[2] = 10; // really d6 86 | _data_pins[3] = 9; // really d7 87 | 88 | _button_pins[0] = 0; 89 | _button_pins[1] = 1; 90 | _button_pins[2] = 2; 91 | _button_pins[3] = 3; 92 | _button_pins[4] = 4; 93 | // we can't begin() yet :( 94 | } 95 | 96 | ESP8266LCD::ESP8266LCD() { 97 | _i2cAddr = 0; 98 | 99 | _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS; 100 | 101 | // the I/O expander pinout 102 | _rs_pin = 15; 103 | _rw_pin = 14; 104 | _enable_pin = 13; 105 | _data_pins[0] = 12; // really d4 106 | _data_pins[1] = 11; // really d5 107 | _data_pins[2] = 10; // really d6 108 | _data_pins[3] = 9; // really d7 109 | 110 | _button_pins[0] = 0; 111 | _button_pins[1] = 1; 112 | _button_pins[2] = 2; 113 | _button_pins[3] = 3; 114 | _button_pins[4] = 4; 115 | // we can't begin() yet :( 116 | } 117 | 118 | 119 | 120 | 121 | void ESP8266LCD::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable, 122 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, 123 | uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) 124 | { 125 | _rs_pin = rs; 126 | _rw_pin = rw; 127 | _enable_pin = enable; 128 | 129 | _data_pins[0] = d0; 130 | _data_pins[1] = d1; 131 | _data_pins[2] = d2; 132 | _data_pins[3] = d3; 133 | _data_pins[4] = d4; 134 | _data_pins[5] = d5; 135 | _data_pins[6] = d6; 136 | _data_pins[7] = d7; 137 | 138 | // _i2cAddr = 255; 139 | 140 | _pinMode(_rs_pin, OUTPUT); 141 | // we can save 1 pin by not using RW. Indicate by passing 255 instead of pin# 142 | if (_rw_pin != 255) { 143 | _pinMode(_rw_pin, OUTPUT); 144 | } 145 | _pinMode(_enable_pin, OUTPUT); 146 | 147 | 148 | if (fourbitmode) 149 | _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS; 150 | else 151 | _displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS; 152 | 153 | begin(16, 1); 154 | } 155 | 156 | void ESP8266LCD::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { 157 | // check if i2c 158 | if (_i2cAddr != 255) { 159 | //_i2c.begin(_i2cAddr); 160 | WIRE.begin(); 161 | WIRE.setClock(400000); 162 | _i2c.begin(_i2cAddr); 163 | 164 | _i2c.pinMode(8, OUTPUT); 165 | _i2c.pinMode(6, OUTPUT); 166 | _i2c.pinMode(7, OUTPUT); 167 | setBacklight(0x7); 168 | 169 | if (_rw_pin) 170 | _i2c.pinMode(_rw_pin, OUTPUT); 171 | 172 | _i2c.pinMode(_rs_pin, OUTPUT); 173 | _i2c.pinMode(_enable_pin, OUTPUT); 174 | for (uint8_t i=0; i<4; i++) 175 | _i2c.pinMode(_data_pins[i], OUTPUT); 176 | 177 | for (uint8_t i=0; i<5; i++) { 178 | _i2c.pinMode(_button_pins[i], INPUT); 179 | _i2c.pullUp(_button_pins[i], 1); 180 | } 181 | } 182 | 183 | if (lines > 1) { 184 | _displayfunction |= LCD_2LINE; 185 | } 186 | _numlines = lines; 187 | _currline = 0; 188 | 189 | // for some 1 line displays you can select a 10 pixel high font 190 | if ((dotsize != 0) && (lines == 1)) { 191 | _displayfunction |= LCD_5x10DOTS; 192 | } 193 | 194 | // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! 195 | // according to datasheet, we need at least 40ms after power rises above 2.7V 196 | // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50 197 | delayMicroseconds(50000); 198 | // Now we pull both RS and R/W low to begin commands 199 | _digitalWrite(_rs_pin, LOW); 200 | _digitalWrite(_enable_pin, LOW); 201 | if (_rw_pin != 255) { 202 | _digitalWrite(_rw_pin, LOW); 203 | } 204 | 205 | //put the LCD into 4 bit or 8 bit mode 206 | if (! (_displayfunction & LCD_8BITMODE)) { 207 | // this is according to the hitachi HD44780 datasheet 208 | // figure 24, pg 46 209 | 210 | // we start in 8bit mode, try to set 4 bit mode 211 | write4bits(0x03); 212 | delayMicroseconds(4500); // wait min 4.1ms 213 | 214 | // second try 215 | write4bits(0x03); 216 | delayMicroseconds(4500); // wait min 4.1ms 217 | 218 | // third go! 219 | write4bits(0x03); 220 | delayMicroseconds(150); 221 | 222 | // finally, set to 8-bit interface 223 | write4bits(0x02); 224 | } else { 225 | // this is according to the hitachi HD44780 datasheet 226 | // page 45 figure 23 227 | 228 | // Send function set command sequence 229 | command(LCD_FUNCTIONSET | _displayfunction); 230 | delayMicroseconds(4500); // wait more than 4.1ms 231 | 232 | // second try 233 | command(LCD_FUNCTIONSET | _displayfunction); 234 | delayMicroseconds(150); 235 | 236 | // third go 237 | command(LCD_FUNCTIONSET | _displayfunction); 238 | } 239 | 240 | // finally, set # lines, font size, etc. 241 | command(LCD_FUNCTIONSET | _displayfunction); 242 | 243 | // turn the display on with no cursor or blinking default 244 | _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; 245 | display(); 246 | 247 | // clear it off 248 | clear(); 249 | 250 | // Initialize to default text direction (for romance languages) 251 | _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; 252 | // set the entry mode 253 | command(LCD_ENTRYMODESET | _displaymode); 254 | 255 | } 256 | 257 | /********** high level commands, for the user! */ 258 | void ESP8266LCD::clear() 259 | { 260 | command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero 261 | delayMicroseconds(2000); // this command takes a long time! 262 | } 263 | 264 | void ESP8266LCD::home() 265 | { 266 | command(LCD_RETURNHOME); // set cursor position to zero 267 | delayMicroseconds(2000); // this command takes a long time! 268 | } 269 | 270 | void ESP8266LCD::setCursor(uint8_t col, uint8_t row) 271 | { 272 | int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 }; 273 | if ( row > _numlines ) { 274 | row = _numlines-1; // we count rows starting w/0 275 | } 276 | 277 | command(LCD_SETDDRAMADDR | (col + row_offsets[row])); 278 | } 279 | 280 | // Turn the display on/off (quickly) 281 | void ESP8266LCD::noDisplay() { 282 | _displaycontrol &= ~LCD_DISPLAYON; 283 | command(LCD_DISPLAYCONTROL | _displaycontrol); 284 | } 285 | void ESP8266LCD::display() { 286 | _displaycontrol |= LCD_DISPLAYON; 287 | command(LCD_DISPLAYCONTROL | _displaycontrol); 288 | } 289 | 290 | // Turns the underline cursor on/off 291 | void ESP8266LCD::noCursor() { 292 | _displaycontrol &= ~LCD_CURSORON; 293 | command(LCD_DISPLAYCONTROL | _displaycontrol); 294 | } 295 | void ESP8266LCD::cursor() { 296 | _displaycontrol |= LCD_CURSORON; 297 | command(LCD_DISPLAYCONTROL | _displaycontrol); 298 | } 299 | 300 | // Turn on and off the blinking cursor 301 | void ESP8266LCD::noBlink() { 302 | _displaycontrol &= ~LCD_BLINKON; 303 | command(LCD_DISPLAYCONTROL | _displaycontrol); 304 | } 305 | void ESP8266LCD::blink() { 306 | _displaycontrol |= LCD_BLINKON; 307 | command(LCD_DISPLAYCONTROL | _displaycontrol); 308 | } 309 | 310 | // These commands scroll the display without changing the RAM 311 | void ESP8266LCD::scrollDisplayLeft(void) { 312 | command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT); 313 | } 314 | void ESP8266LCD::scrollDisplayRight(void) { 315 | command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT); 316 | } 317 | 318 | // This is for text that flows Left to Right 319 | void ESP8266LCD::leftToRight(void) { 320 | _displaymode |= LCD_ENTRYLEFT; 321 | command(LCD_ENTRYMODESET | _displaymode); 322 | } 323 | 324 | // This is for text that flows Right to Left 325 | void ESP8266LCD::rightToLeft(void) { 326 | _displaymode &= ~LCD_ENTRYLEFT; 327 | command(LCD_ENTRYMODESET | _displaymode); 328 | } 329 | 330 | // This will 'right justify' text from the cursor 331 | void ESP8266LCD::autoscroll(void) { 332 | _displaymode |= LCD_ENTRYSHIFTINCREMENT; 333 | command(LCD_ENTRYMODESET | _displaymode); 334 | } 335 | 336 | // This will 'left justify' text from the cursor 337 | void ESP8266LCD::noAutoscroll(void) { 338 | _displaymode &= ~LCD_ENTRYSHIFTINCREMENT; 339 | command(LCD_ENTRYMODESET | _displaymode); 340 | } 341 | 342 | // Allows us to fill the first 8 CGRAM locations 343 | // with custom characters 344 | void ESP8266LCD::createChar(uint8_t location, uint8_t charmap[]) { 345 | location &= 0x7; // we only have 8 locations 0-7 346 | command(LCD_SETCGRAMADDR | (location << 3)); 347 | for (int i=0; i<8; i++) { 348 | write(charmap[i]); 349 | } 350 | command(LCD_SETDDRAMADDR); // unfortunately resets the location to 0,0 351 | } 352 | 353 | /*********** mid level commands, for sending data/cmds */ 354 | 355 | inline void ESP8266LCD::command(uint8_t value) { 356 | send(value, LOW); 357 | } 358 | 359 | #if ARDUINO >= 100 360 | inline size_t ESP8266LCD::write(uint8_t value) { 361 | send(value, HIGH); 362 | return 1; 363 | } 364 | #else 365 | inline void ESP8266LCD::write(uint8_t value) { 366 | send(value, HIGH); 367 | } 368 | #endif 369 | 370 | /************ low level data pushing commands **********/ 371 | 372 | // little wrapper for i/o writes 373 | void ESP8266LCD::_digitalWrite(uint8_t p, uint8_t d) { 374 | if (_i2cAddr != 255) { 375 | // an i2c command 376 | _i2c.digitalWrite(p, d); 377 | } else { 378 | // straightup IO 379 | digitalWrite(p, d); 380 | } 381 | } 382 | 383 | // Allows to set the backlight, if the LCD backpack is used 384 | void ESP8266LCD::setBacklight(uint8_t status) { 385 | // check if i2c or SPI 386 | // Serial.print("Setting backlight to "); 387 | // Serial.println(status); 388 | _i2c.digitalWrite(8, ~(status >> 2) & 0x1); 389 | // Serial.println("_i2c.digitalWrite(8, ~(status >> 2) & 0x1) done"); 390 | _i2c.digitalWrite(7, ~(status >> 1) & 0x1); 391 | // Serial.println("_i2c.digitalWrite(7, ~(status >> 1) & 0x1) done"); 392 | _i2c.digitalWrite(6, ~status & 0x1); 393 | // Serial.println("_i2c.digitalWrite(6, ~status & 0x1) done"); 394 | // Serial.println("Exiting setBacklight"); 395 | } 396 | 397 | // little wrapper for i/o directions 398 | void ESP8266LCD::_pinMode(uint8_t p, uint8_t d) { 399 | if (_i2cAddr != 255) { 400 | // an i2c command 401 | _i2c.pinMode(p, d); 402 | } else { 403 | // straightup IO 404 | pinMode(p, d); 405 | } 406 | } 407 | 408 | // write either command or data, with automatic 4/8-bit selection 409 | void ESP8266LCD::send(uint8_t value, uint8_t mode) { 410 | _digitalWrite(_rs_pin, mode); 411 | 412 | // if there is a RW pin indicated, set it low to Write 413 | if (_rw_pin != 255) { 414 | _digitalWrite(_rw_pin, LOW); 415 | } 416 | 417 | if (_displayfunction & LCD_8BITMODE) { 418 | write8bits(value); 419 | } else { 420 | write4bits(value>>4); 421 | write4bits(value); 422 | } 423 | } 424 | 425 | void ESP8266LCD::pulseEnable(void) { 426 | _digitalWrite(_enable_pin, LOW); 427 | delayMicroseconds(1); 428 | _digitalWrite(_enable_pin, HIGH); 429 | delayMicroseconds(1); // enable pulse must be >450ns 430 | _digitalWrite(_enable_pin, LOW); 431 | delayMicroseconds(100); // commands need > 37us to settle 432 | } 433 | 434 | void ESP8266LCD::write4bits(uint8_t value) { 435 | if (_i2cAddr != 255) { 436 | uint16_t out = 0; 437 | 438 | out = _i2c.readGPIOAB(); 439 | 440 | // speed up for i2c since its sluggish 441 | for (int i = 0; i < 4; i++) { 442 | out &= ~(1 << _data_pins[i]); 443 | out |= ((value >> i) & 0x1) << _data_pins[i]; 444 | } 445 | 446 | // make sure enable is low 447 | out &= ~(1 << _enable_pin); 448 | 449 | _i2c.writeGPIOAB(out); 450 | 451 | // pulse enable 452 | delayMicroseconds(1); 453 | out |= (1 << _enable_pin); 454 | _i2c.writeGPIOAB(out); 455 | delayMicroseconds(1); 456 | out &= ~(1 << _enable_pin); 457 | _i2c.writeGPIOAB(out); 458 | delayMicroseconds(100); 459 | 460 | } else { 461 | for (int i = 0; i < 4; i++) { 462 | _pinMode(_data_pins[i], OUTPUT); 463 | _digitalWrite(_data_pins[i], (value >> i) & 0x01); 464 | } 465 | pulseEnable(); 466 | } 467 | } 468 | 469 | void ESP8266LCD::write8bits(uint8_t value) { 470 | for (int i = 0; i < 8; i++) { 471 | _pinMode(_data_pins[i], OUTPUT); 472 | _digitalWrite(_data_pins[i], (value >> i) & 0x01); 473 | } 474 | 475 | pulseEnable(); 476 | } 477 | 478 | uint8_t ESP8266LCD::readButtons(void) { 479 | uint8_t reply = 0x1F; 480 | 481 | for (uint8_t i=0; i<5; i++) { 482 | reply &= ~((_i2c.digitalRead(_button_pins[i])) << i); 483 | } 484 | return reply; 485 | } 486 | -------------------------------------------------------------------------------- /sketchbook/libraries/ESP8266LCD/ESP8266LCD.h: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | 3 | This software borrows heavily from the Adafruit library, 4 | All text and attributions required are below. 5 | 6 | This is a library for the Adafruit RGB 16x2 LCD Shield 7 | Pick one up at the Adafruit shop! 8 | ---------> http://http://www.adafruit.com/products/714 9 | 10 | The shield uses I2C to communicate, 2 pins are required to 11 | interface 12 | Adafruit invests time and resources providing this open source code, 13 | please support Adafruit and open-source hardware by purchasing 14 | products from Adafruit! 15 | 16 | Written by Limor Fried/Ladyada for Adafruit Industries. 17 | BSD license, all text above must be included in any redistribution 18 | ****************************************************/ 19 | 20 | #ifndef ESP8266_RGBLCD_h 21 | #define ESP8266_RGBLCD_h 22 | 23 | #include 24 | #include "Print.h" 25 | #include 26 | 27 | // commands 28 | #define LCD_CLEARDISPLAY 0x01 29 | #define LCD_RETURNHOME 0x02 30 | #define LCD_ENTRYMODESET 0x04 31 | #define LCD_DISPLAYCONTROL 0x08 32 | #define LCD_CURSORSHIFT 0x10 33 | #define LCD_FUNCTIONSET 0x20 34 | #define LCD_SETCGRAMADDR 0x40 35 | #define LCD_SETDDRAMADDR 0x80 36 | 37 | // flags for display entry mode 38 | #define LCD_ENTRYRIGHT 0x00 39 | #define LCD_ENTRYLEFT 0x02 40 | #define LCD_ENTRYSHIFTINCREMENT 0x01 41 | #define LCD_ENTRYSHIFTDECREMENT 0x00 42 | 43 | // flags for display on/off control 44 | #define LCD_DISPLAYON 0x04 45 | #define LCD_DISPLAYOFF 0x00 46 | #define LCD_CURSORON 0x02 47 | #define LCD_CURSOROFF 0x00 48 | #define LCD_BLINKON 0x01 49 | #define LCD_BLINKOFF 0x00 50 | 51 | // flags for display/cursor shift 52 | #define LCD_DISPLAYMOVE 0x08 53 | #define LCD_CURSORMOVE 0x00 54 | #define LCD_MOVERIGHT 0x04 55 | #define LCD_MOVELEFT 0x00 56 | 57 | // flags for function set 58 | #define LCD_8BITMODE 0x10 59 | #define LCD_4BITMODE 0x00 60 | #define LCD_2LINE 0x08 61 | #define LCD_1LINE 0x00 62 | #define LCD_5x10DOTS 0x04 63 | #define LCD_5x8DOTS 0x00 64 | 65 | #define BUTTON_UP 0x08 66 | #define BUTTON_DOWN 0x04 67 | #define BUTTON_LEFT 0x10 68 | #define BUTTON_RIGHT 0x02 69 | #define BUTTON_SELECT 0x01 70 | 71 | 72 | class ESP8266LCD : public Print { 73 | public: 74 | ESP8266LCD(uint8_t addr); 75 | ESP8266LCD(); 76 | 77 | void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable, 78 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, 79 | uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); 80 | 81 | void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS); 82 | 83 | void clear(); 84 | void home(); 85 | 86 | void noDisplay(); 87 | void display(); 88 | void noBlink(); 89 | void blink(); 90 | void noCursor(); 91 | void cursor(); 92 | void scrollDisplayLeft(); 93 | void scrollDisplayRight(); 94 | void leftToRight(); 95 | void rightToLeft(); 96 | void autoscroll(); 97 | void noAutoscroll(); 98 | 99 | // only if using backpack 100 | void setBacklight(uint8_t status); 101 | 102 | void createChar(uint8_t, uint8_t[]); 103 | void setCursor(uint8_t, uint8_t); 104 | #if ARDUINO >= 100 105 | virtual size_t write(uint8_t); 106 | #else 107 | virtual void write(uint8_t); 108 | #endif 109 | void command(uint8_t); 110 | uint8_t readButtons(); 111 | 112 | private: 113 | void send(uint8_t, uint8_t); 114 | void write4bits(uint8_t); 115 | void write8bits(uint8_t); 116 | void pulseEnable(); 117 | void _digitalWrite(uint8_t, uint8_t); 118 | void _pinMode(uint8_t, uint8_t); 119 | 120 | uint8_t _rs_pin; // LOW: command. HIGH: character. 121 | uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD. 122 | uint8_t _enable_pin; // activated by a HIGH pulse. 123 | uint8_t _data_pins[8]; 124 | uint8_t _button_pins[5]; 125 | uint8_t _displayfunction; 126 | uint8_t _displaycontrol; 127 | uint8_t _displaymode; 128 | 129 | uint8_t _initialized; 130 | 131 | uint8_t _numlines,_currline; 132 | 133 | uint8_t _i2cAddr; 134 | ESP8266MCP23017 _i2c; 135 | }; 136 | 137 | #endif 138 | -------------------------------------------------------------------------------- /sketchbook/libraries/ESP8266LCD/ESP8266MCP23017.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | Version 0.0.2 3 | Last Modified 04/05/2015 4 | By Jim Mayhugh 5 | 6 | This is a library for the MCP23017 i2c port expander 7 | 8 | This software borrows heavily from the Adafruit library, 9 | All text and attributions required are below. 10 | 11 | These displays use I2C to communicate, 2 pins are required to 12 | interface. 13 | 14 | Adafruit invests time and resources providing this open source code, 15 | please support Adafruit and open-source hardware by purchasing 16 | products from Adafruit! 17 | 18 | Written by Limor Fried/Ladyada for Adafruit Industries. 19 | BSD license, all text above must be included in any redistribution 20 | ****************************************************/ 21 | 22 | #if ( __MK20DX128__ ) || ( __MK20DX256__ ) 23 | //#include 24 | #include 25 | #include 26 | #else 27 | #include 28 | #endif 29 | 30 | #include "ESP8266MCP23017.h" 31 | #ifdef __AVR__ 32 | #define WIRE Wire 33 | #else // Arduino Due 34 | #define WIRE Wire 35 | #endif 36 | 37 | #if ARDUINO >= 100 38 | #include "Arduino.h" 39 | #else 40 | #include "WProgram.h" 41 | #endif 42 | 43 | // minihelper 44 | static inline void wiresend(uint8_t x) { 45 | #if ARDUINO >= 100 46 | WIRE.write((uint8_t)x); 47 | #else 48 | WIRE.send(x); 49 | #endif 50 | } 51 | 52 | static inline uint8_t wirerecv(void) { 53 | #if ARDUINO >= 100 54 | return WIRE.read(); 55 | #else 56 | return WIRE.receive(); 57 | #endif 58 | } 59 | 60 | //////////////////////////////////////////////////////////////////////////////// 61 | 62 | void ESP8266MCP23017::begin(uint8_t addr) { 63 | if (addr > 7) { 64 | addr = 7; 65 | } 66 | i2caddr = addr; 67 | 68 | WIRE.begin(); 69 | WIRE.setClock(400000); 70 | 71 | 72 | // set defaults! 73 | WIRE.beginTransmission(MCP23017_ADDRESS | i2caddr); 74 | wiresend(MCP23017_IODIRA); 75 | wiresend(0xFF); // all inputs on port A 76 | WIRE.endTransmission(); 77 | 78 | WIRE.beginTransmission(MCP23017_ADDRESS | i2caddr); 79 | wiresend(MCP23017_IODIRB); 80 | wiresend(0xFF); // all inputs on port B 81 | WIRE.endTransmission(); 82 | } 83 | 84 | 85 | void ESP8266MCP23017::begin(void) { 86 | begin(0); 87 | } 88 | 89 | void ESP8266MCP23017::pinMode(uint8_t p, uint8_t d) { 90 | uint8_t iodir; 91 | uint8_t iodiraddr; 92 | 93 | // only 16 bits! 94 | if (p > 15) 95 | return; 96 | 97 | if (p < 8) 98 | iodiraddr = MCP23017_IODIRA; 99 | else { 100 | iodiraddr = MCP23017_IODIRB; 101 | p -= 8; 102 | } 103 | 104 | // read the current IODIR 105 | WIRE.beginTransmission(MCP23017_ADDRESS | i2caddr); 106 | wiresend(iodiraddr); 107 | WIRE.endTransmission(); 108 | 109 | WIRE.requestFrom(MCP23017_ADDRESS | i2caddr, 1); 110 | iodir = wirerecv(); 111 | 112 | // set the pin and direction 113 | if (d == INPUT) { 114 | iodir |= 1 << p; 115 | } else { 116 | iodir &= ~(1 << p); 117 | } 118 | 119 | // write the new IODIR 120 | WIRE.beginTransmission(MCP23017_ADDRESS | i2caddr); 121 | wiresend(iodiraddr); 122 | wiresend(iodir); 123 | WIRE.endTransmission(); 124 | } 125 | 126 | uint16_t ESP8266MCP23017::readGPIOAB() { 127 | uint16_t ba = 0; 128 | uint8_t a; 129 | 130 | // read the current GPIO output latches 131 | WIRE.beginTransmission(MCP23017_ADDRESS | i2caddr); 132 | wiresend(MCP23017_GPIOA); 133 | WIRE.endTransmission(); 134 | 135 | WIRE.requestFrom(MCP23017_ADDRESS | i2caddr, 2); 136 | a = wirerecv(); 137 | ba = wirerecv(); 138 | ba <<= 8; 139 | ba |= a; 140 | 141 | return ba; 142 | } 143 | 144 | void ESP8266MCP23017::writeGPIOAB(uint16_t ba) { 145 | WIRE.beginTransmission(MCP23017_ADDRESS | i2caddr); 146 | wiresend(MCP23017_GPIOA); 147 | wiresend(ba & 0xFF); 148 | wiresend(ba >> 8); 149 | WIRE.endTransmission(); 150 | } 151 | 152 | void ESP8266MCP23017::digitalWrite(uint8_t p, uint8_t d) { 153 | uint8_t gpio; 154 | uint8_t gpioaddr, olataddr; 155 | 156 | // only 16 bits! 157 | if (p > 15) 158 | return; 159 | 160 | if (p < 8) { 161 | olataddr = MCP23017_OLATA; 162 | gpioaddr = MCP23017_GPIOA; 163 | } else { 164 | olataddr = MCP23017_OLATB; 165 | gpioaddr = MCP23017_GPIOB; 166 | p -= 8; 167 | } 168 | 169 | // read the current GPIO output latches 170 | WIRE.beginTransmission(MCP23017_ADDRESS | i2caddr); 171 | wiresend(olataddr); 172 | WIRE.endTransmission(); 173 | 174 | WIRE.requestFrom(MCP23017_ADDRESS | i2caddr, 1); 175 | gpio = wirerecv(); 176 | 177 | // set the pin and direction 178 | if (d == HIGH) { 179 | gpio |= 1 << p; 180 | } else { 181 | gpio &= ~(1 << p); 182 | } 183 | 184 | // write the new GPIO 185 | WIRE.beginTransmission(MCP23017_ADDRESS | i2caddr); 186 | wiresend(gpioaddr); 187 | wiresend(gpio); 188 | WIRE.endTransmission(); 189 | } 190 | 191 | void ESP8266MCP23017::pullUp(uint8_t p, uint8_t d) { 192 | uint8_t gppu; 193 | uint8_t gppuaddr; 194 | 195 | // only 16 bits! 196 | if (p > 15) 197 | return; 198 | 199 | if (p < 8) 200 | gppuaddr = MCP23017_GPPUA; 201 | else { 202 | gppuaddr = MCP23017_GPPUB; 203 | p -= 8; 204 | } 205 | 206 | 207 | // read the current pullup resistor set 208 | WIRE.beginTransmission(MCP23017_ADDRESS | i2caddr); 209 | wiresend(gppuaddr); 210 | WIRE.endTransmission(); 211 | 212 | WIRE.requestFrom(MCP23017_ADDRESS | i2caddr, 1); 213 | gppu = wirerecv(); 214 | 215 | // set the pin and direction 216 | if (d == HIGH) { 217 | gppu |= 1 << p; 218 | } else { 219 | gppu &= ~(1 << p); 220 | } 221 | 222 | // write the new GPIO 223 | WIRE.beginTransmission(MCP23017_ADDRESS | i2caddr); 224 | wiresend(gppuaddr); 225 | wiresend(gppu); 226 | WIRE.endTransmission(); 227 | } 228 | 229 | uint8_t ESP8266MCP23017::digitalRead(uint8_t p) { 230 | uint8_t gpioaddr; 231 | 232 | // only 16 bits! 233 | if (p > 15) 234 | return 0; 235 | 236 | if (p < 8) 237 | gpioaddr = MCP23017_GPIOA; 238 | else { 239 | gpioaddr = MCP23017_GPIOB; 240 | p -= 8; 241 | } 242 | 243 | // read the current GPIO 244 | WIRE.beginTransmission(MCP23017_ADDRESS | i2caddr); 245 | wiresend(gpioaddr); 246 | WIRE.endTransmission(); 247 | 248 | WIRE.requestFrom(MCP23017_ADDRESS | i2caddr, 1); 249 | return (wirerecv() >> p) & 0x1; 250 | } 251 | -------------------------------------------------------------------------------- /sketchbook/libraries/ESP8266LCD/ESP8266MCP23017.h: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is a library for the MCP23017 i2c port expander 3 | 4 | These displays use I2C to communicate, 2 pins are required to 5 | interface 6 | 7 | This software borrows heavily from the Adafruit library, 8 | All text and attributions required are below. 9 | 10 | Adafruit invests time and resources providing this open source code, 11 | please support Adafruit and open-source hardware by purchasing 12 | products from Adafruit! 13 | 14 | Written by Limor Fried/Ladyada for Adafruit Industries. 15 | BSD license, all text above must be included in any redistribution 16 | ****************************************************/ 17 | 18 | #ifndef _ESP8266_MCP23017_H_ 19 | #define _ESP8266_MCP23017_H_ 20 | 21 | // Don't forget the Wire library 22 | class ESP8266MCP23017 { 23 | public: 24 | void begin(uint8_t addr); 25 | void begin(void); 26 | 27 | void pinMode(uint8_t p, uint8_t d); 28 | void digitalWrite(uint8_t p, uint8_t d); 29 | void pullUp(uint8_t p, uint8_t d); 30 | uint8_t digitalRead(uint8_t p); 31 | 32 | void writeGPIOAB(uint16_t); 33 | uint16_t readGPIOAB(); 34 | 35 | private: 36 | uint8_t i2caddr; 37 | }; 38 | 39 | #define MCP23017_ADDRESS 0x20 40 | 41 | // registers 42 | #define MCP23017_IODIRA 0x00 43 | #define MCP23017_IPOLA 0x02 44 | #define MCP23017_GPINTENA 0x04 45 | #define MCP23017_DEFVALA 0x06 46 | #define MCP23017_INTCONA 0x08 47 | #define MCP23017_IOCONA 0x0A 48 | #define MCP23017_GPPUA 0x0C 49 | #define MCP23017_INTFA 0x0E 50 | #define MCP23017_INTCAPA 0x10 51 | #define MCP23017_GPIOA 0x12 52 | #define MCP23017_OLATA 0x14 53 | 54 | 55 | #define MCP23017_IODIRB 0x01 56 | #define MCP23017_IPOLB 0x03 57 | #define MCP23017_GPINTENB 0x05 58 | #define MCP23017_DEFVALB 0x07 59 | #define MCP23017_INTCONB 0x09 60 | #define MCP23017_IOCONB 0x0B 61 | #define MCP23017_GPPUB 0x0D 62 | #define MCP23017_INTFB 0x0F 63 | #define MCP23017_INTCAPB 0x11 64 | #define MCP23017_GPIOB 0x13 65 | #define MCP23017_OLATB 0x15 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /sql/esp8266.sql: -------------------------------------------------------------------------------- 1 | -- phpMyAdmin SQL Dump 2 | -- version 4.2.12deb2 3 | -- http://www.phpmyadmin.net 4 | -- 5 | -- Host: localhost 6 | -- Generation Time: Aug 29, 2015 at 10:06 AM 7 | -- Server version: 5.5.44-0+deb8u1 8 | -- PHP Version: 5.6.12-0+deb8u1 9 | 10 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; 11 | SET time_zone = "+00:00"; 12 | 13 | 14 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 15 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 16 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 17 | /*!40101 SET NAMES utf8 */; 18 | 19 | -- 20 | -- Database: `esp8266` 21 | -- 22 | 23 | -- -------------------------------------------------------- 24 | 25 | -- 26 | -- Table structure for table `Addresses` 27 | -- 28 | 29 | CREATE TABLE IF NOT EXISTS `Addresses` ( 30 | `ipAddress` varchar(20) NOT NULL, 31 | `udpPort` int(11) NOT NULL 32 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 33 | 34 | -- -------------------------------------------------------- 35 | 36 | -- 37 | -- Table structure for table `device` 38 | -- 39 | 40 | CREATE TABLE IF NOT EXISTS `device` ( 41 | `ipaddress` varchar(20) NOT NULL, 42 | `port` int(11) NOT NULL, 43 | `time` bigint(20) NOT NULL, 44 | `tempc` int(11) NOT NULL, 45 | `tempf` int(11) NOT NULL, 46 | `switch1` char(1) NOT NULL, 47 | `switch2` char(1) NOT NULL 48 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 49 | 50 | -- 51 | -- Indexes for dumped tables 52 | -- 53 | 54 | -- 55 | -- Indexes for table `Addresses` 56 | -- 57 | ALTER TABLE `Addresses` 58 | ADD UNIQUE KEY `ipAddress` (`ipAddress`); 59 | 60 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 61 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 62 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 63 | -------------------------------------------------------------------------------- /utilities/DigitalPinTest/DigitalPinTest.ino: -------------------------------------------------------------------------------- 1 | void setup() 2 | { 3 | pinMode(2, OUTPUT); 4 | pinMode(4, OUTPUT); 5 | pinMode(5, OUTPUT); 6 | pinMode(12, OUTPUT); 7 | pinMode(13, OUTPUT); 8 | pinMode(14, OUTPUT); 9 | pinMode(16, OUTPUT); 10 | } 11 | 12 | void loop() 13 | { 14 | digitalWrite(2, HIGH); 15 | digitalWrite(4, HIGH); 16 | digitalWrite(5, HIGH); 17 | digitalWrite(12, HIGH); 18 | digitalWrite(13, HIGH); 19 | digitalWrite(14, HIGH); 20 | digitalWrite(16, HIGH); 21 | delay(50); 22 | digitalWrite(2, LOW); 23 | digitalWrite(4, LOW); 24 | digitalWrite(5, LOW); 25 | digitalWrite(12, LOW); 26 | digitalWrite(13, LOW); 27 | digitalWrite(14, LOW); 28 | digitalWrite(16, LOW); 29 | delay(50); 30 | } 31 | -------------------------------------------------------------------------------- /utilities/EEPROM/eeprom_clear/eeprom_clear.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * EEPROM Clear 3 | * 4 | * Sets all of the bytes of the EEPROM to 0. 5 | * This example code is in the public domain. 6 | 7 | */ 8 | 9 | #include 10 | 11 | void setup() 12 | { 13 | Serial.begin(115200); 14 | delay(5000); 15 | Serial.print("EEPROM Clear Start"); 16 | EEPROM.begin(512); 17 | // write a 0xFF to all 512 bytes of the EEPROM 18 | for (int i = 0; i < 512; i++) 19 | EEPROM.write(i, 0xFF); 20 | 21 | // turn the LED on when we're done 22 | pinMode(13, OUTPUT); 23 | digitalWrite(13, HIGH); 24 | EEPROM.end(); 25 | Serial.print("EEPROM Clear End"); 26 | } 27 | 28 | void loop() 29 | { 30 | } 31 | -------------------------------------------------------------------------------- /utilities/EEPROM/eeprom_read/eeprom_read.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * EEPROM Read 3 | * 4 | * Reads the value of each byte of the EEPROM and prints it 5 | * to the computer. 6 | * This example code is in the public domain. 7 | */ 8 | 9 | #include 10 | 11 | // start reading from the first byte (address 0) of the EEPROM 12 | int address = 0; 13 | byte value; 14 | 15 | void setup() 16 | { 17 | // initialize serial and wait for port to open: 18 | Serial.begin(115200); 19 | while (!Serial) { 20 | ; // wait for serial port to connect. Needed for Leonardo only 21 | } 22 | EEPROM.begin(512); 23 | } 24 | 25 | void loop() 26 | { 27 | // read a byte from the current address of the EEPROM 28 | value = EEPROM.read(address); 29 | 30 | Serial.print(address); 31 | Serial.print("\t"); 32 | Serial.print(value, DEC); 33 | Serial.println(); 34 | 35 | // advance to the next address of the EEPROM 36 | address = address + 1; 37 | 38 | // there are only 512 bytes of EEPROM, from 0 to 511, so if we're 39 | // on address 512, wrap around to address 0 40 | if (address == 512) 41 | address = 0; 42 | 43 | delay(500); 44 | } 45 | -------------------------------------------------------------------------------- /utilities/EEPROM/eeprom_write/eeprom_write.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * EEPROM Write 3 | * 4 | * Stores values read from analog input 0 into the EEPROM. 5 | * These values will stay in the EEPROM when the board is 6 | * turned off and may be retrieved later by another sketch. 7 | */ 8 | 9 | #include 10 | 11 | // the current address in the EEPROM (i.e. which byte 12 | // we're going to write to next) 13 | int addr = 0; 14 | uint8_t val = 0; 15 | 16 | void setup() 17 | { 18 | // initialize serial and wait for port to open: 19 | Serial.begin(115200); 20 | while (!Serial) { 21 | ; // wait for serial port to connect. Needed for Leonardo only 22 | } 23 | EEPROM.begin(512); 24 | } 25 | 26 | void loop() 27 | { 28 | // write the value to the appropriate byte of the EEPROM. 29 | // these values will remain there when the board is 30 | // turned off. 31 | EEPROM.write(addr, val); 32 | 33 | if(val < 0x10) 34 | { 35 | Serial.print("0x0"); 36 | }else{ 37 | Serial.print("0x"); 38 | } 39 | Serial.print(val, HEX); 40 | Serial.print(" written to addr "); 41 | Serial.println(addr); 42 | 43 | // advance to the next address. there are 512 bytes in 44 | // the EEPROM, so go back to 0 when we hit 512. 45 | // save all changes to the flash. 46 | val++; 47 | addr = addr + 1; 48 | if (addr == 512) 49 | { 50 | addr = 0; 51 | EEPROM.commit(); 52 | Serial.println("FINISHED"); 53 | pinMode(13, OUTPUT); 54 | digitalWrite(13, HIGH); 55 | while(1); 56 | } 57 | 58 | delay(100); 59 | } 60 | -------------------------------------------------------------------------------- /utilities/MacAddress/MacAddress.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | uint8_t MAC_softAP[] = {0,0,0,0,0,0}; //not sure why we have to pass a MAC address to get a MAC address. 4 | uint8_t MAC_STA[] = {0,0,0,0,0,0}; 5 | 6 | void setup() { 7 | Serial.begin(115200); 8 | delay(5000); 9 | Serial.println("Get ESP8266 MAC Address"); 10 | delay(5000); 11 | Serial.println(); 12 | 13 | Serial.print("MAC[SoftAP]"); 14 | delay(1000); 15 | uint8_t* MAC = WiFi.softAPmacAddress(MAC_softAP); //get MAC address of softAP interface 16 | for (int i = 0; i < sizeof(MAC)+2; ++i){ //this line needs cleaning up. 17 | Serial.print(":"); 18 | Serial.print(MAC[i],HEX); 19 | MAC_softAP[i] = MAC[i]; //copy back to global variable 20 | } 21 | Serial.println(); 22 | Serial.print("MAC[STA]"); 23 | delay(1000); 24 | MAC = WiFi.macAddress(MAC_STA); //get MAC address of STA interface 25 | for (int i = 0; i < sizeof(MAC)+2; ++i){ 26 | Serial.print(":"); 27 | Serial.print(MAC[i],HEX); 28 | MAC_STA[i] = MAC[i]; //copy back to global variable 29 | } 30 | Serial.println(); 31 | } 32 | 33 | void loop(void) 34 | { 35 | } 36 | -------------------------------------------------------------------------------- /utilities/RGBLCDTest/RGBLCDTest.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // LCD Stuff 6 | 7 | // The shield uses the I2C SCL and SDA pins. 8 | // You can connect other I2C sensors to the I2C bus and share 9 | // the I2C bus. 10 | 11 | Teensy_RGBLCDShield lcd = Teensy_RGBLCDShield(7); 12 | 13 | 14 | // These #defines make it easy to set the backlight color 15 | #define RED 0x1 16 | #define YELLOW 0x3 17 | #define GREEN 0x2 18 | #define TEAL 0x6 19 | #define BLUE 0x4 20 | #define VIOLET 0x5 21 | #define WHITE 0x7 22 | 23 | const uint8_t color[] = { RED, GREEN, YELLOW, BLUE, VIOLET, TEAL, WHITE }; 24 | 25 | uint8_t const lcdChars = 20; 26 | uint8_t const lcdRows = 4; 27 | 28 | char lcdStr[lcdChars + 1]; 29 | char versionBuf[lcdChars + 1]; 30 | 31 | // End LCD Stuff 32 | 33 | const long baudRate = 115200; 34 | uint32_t cnt = 0; 35 | 36 | void setup() 37 | { 38 | Wire.begin(); 39 | Serial.begin(baudRate); 40 | 41 | delay(10000); 42 | 43 | Serial.print(F("Serial Debug starting at ")); 44 | Serial.print(baudRate); 45 | 46 | Serial.println(F("Setup LCD")); 47 | lcd.begin(lcdChars, lcdRows); 48 | lcd.clear(); 49 | lcd.home(); 50 | lcd.print(F("Serial Debug = ")); 51 | lcd.print(baudRate); 52 | lcd.setCursor(0, 1); 53 | lcd.print(F("LCD # 1")); 54 | lcd.setCursor(0, 2); 55 | lcd.print(F("LCD Address = 0x27")); 56 | Serial.println(F("Setup LCD complete")); 57 | } 58 | 59 | void loop() 60 | { 61 | Serial.println(F("Start LCD count")); 62 | lcd.setCursor(0, 3); 63 | lcd.print(F("Count = 0x")); 64 | lcd.print(cnt, HEX); 65 | lcd.setBacklight(WHITE); 66 | Serial.println(F("Stop LCD count")); 67 | cnt++; 68 | delay(500); 69 | } 70 | 71 | -------------------------------------------------------------------------------- /utilities/TestUdpTempController.php: -------------------------------------------------------------------------------- 1 | 10,'usec'=>0))) === FALSE) 56 | { 57 | echo "socket_set_option for SO_RCVTIMEO failed\n"; 58 | }else{ 59 | echo "SO_RCVTIMEO = 5 seconds\n"; 60 | } 61 | 62 | $localURL = "esp8266.local"; 63 | $count = 0; 64 | $remote_port = '2652'; 65 | $secCnt = 0; 66 | $outputArray = array(); 67 | $execRet; 68 | 69 | //Do some communication, this loop can handle multiple clients 70 | 71 | if(isset($argv[1])) 72 | { 73 | if(is_ipv4($argv[1])) 74 | { 75 | $remote_ip = $argv[1]; 76 | }else{ 77 | $execCmd = "avahi-resolve --name $argv[1]"; 78 | $execArray = explode("\t", exec($execCmd, $outputArray, $execRet)); 79 | //$outputCnt = count($outputArray); 80 | //echo "There are $outputCnt values in \$outputCnt\n"; 81 | //echo "\$outputArray[1] = $outputArray[1]\n"; 82 | //echo "\$execRet = $execRet\n"; 83 | $arrayCnt = count($execArray); 84 | //echo "There are $arrayCnt \$arrayCnt values\n"; 85 | for($z = 0; $z < $arrayCnt; $z++) 86 | { 87 | if( (!(isset($execArray[$z]))) || ($execArray[$z] == NULL ) ) 88 | die("Couldn't resolve $argv[1], exiting\n"); 89 | } 90 | $remote_ip = $execArray[1]; 91 | } 92 | }else{ 93 | die("ERROR - Requires IP Address or domain.local, UDP Port optional - EXITING\n"); 94 | } 95 | /* 96 | if(isset($execArray[2])) 97 | { 98 | $remote_port = $execArray[2]; 99 | } 100 | */ 101 | if(isset($argv[2])) 102 | { 103 | $remote_port = $argv[2]; 104 | } 105 | 106 | echo "Using address $remote_ip and port $remote_port\n"; 107 | 108 | 109 | 110 | while(1) 111 | { 112 | 113 | //Take some input to send 114 | echo 'Enter a message to send : '; 115 | $in = fgets(STDIN); 116 | if($in === "break\n" || $in === "quit\n") 117 | break; 118 | $out = $in."\n"; 119 | 120 | 121 | socket_sendto($sock, $in , 100 , 0 , $remote_ip , $remote_port); 122 | socket_recvfrom($sock, $buf, 2048, MSG_WAITALL, $remote_ip, $remote_port); 123 | 124 | $resultStr = ""; 125 | if($buf === "=") 126 | { 127 | $in = "="; 128 | socket_sendto($sock, $in , 100 , 0 , $remote_ip , $remote_port); 129 | socket_recvfrom($sock, $buf, 2048, MSG_WAITALL, $remote_ip, $remote_port); 130 | 131 | while($buf !== '+') 132 | { 133 | $resultStr .= $buf; 134 | socket_sendto($sock, $in , 100 , 0 , $remote_ip , $remote_port); 135 | socket_recvfrom($sock, $buf, 2048, MSG_WAITALL, $remote_ip, $remote_port); 136 | } 137 | }else{ 138 | $resultStr .= $buf; 139 | } 140 | echo "\$resultStr: \n$resultStr\n"; 141 | } 142 | 143 | echo "Closing socket and exiting\n"; 144 | socket_close($sock); 145 | 146 | function is_ipv4($str) 147 | { 148 | $ret = filter_var($str, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); 149 | 150 | return $ret; 151 | } 152 | ?> 153 | -------------------------------------------------------------------------------- /utilities/TestUdpTempControllerStatus.php: -------------------------------------------------------------------------------- 1 | 10,'usec'=>0))) === FALSE) 56 | { 57 | echo "socket_set_option for SO_RCVTIMEO failed\n"; 58 | }else{ 59 | echo "SO_RCVTIMEO = 5 seconds\n"; 60 | } 61 | 62 | $localURL = "esp8266.local"; 63 | $localIP; 64 | $localPort; 65 | $count = 0; 66 | $remote_port = '2652'; 67 | $secCnt = 0; 68 | $outputArray = array(); 69 | $execRet; 70 | 71 | //Do some communication, this loop can handle multiple clients 72 | 73 | if(isset($argv[1])) 74 | { 75 | if(is_ipv4($argv[1])) 76 | { 77 | $remote_ip = $argv[1]; 78 | }else{ 79 | $execCmd = "avahi-resolve --name $argv[1]"; 80 | $execArray = explode("\t", exec($execCmd, $outputArray, $execRet)); 81 | //$outputCnt = count($outputArray); 82 | //echo "There are $outputCnt values in \$outputCnt\n"; 83 | //echo "\$outputArray[1] = $outputArray[1]\n"; 84 | //echo "\$execRet = $execRet\n"; 85 | $arrayCnt = count($execArray); 86 | //echo "There are $arrayCnt \$arrayCnt values\n"; 87 | for($z = 0; $z < $arrayCnt; $z++) 88 | { 89 | if( (!(isset($execArray[$z]))) || ($execArray[$z] == NULL ) ) 90 | die("Couldn't resolve $argv[1], exiting\n"); 91 | } 92 | $remote_ip = $execArray[1]; 93 | } 94 | }else{ 95 | die("ERROR - Requires IP Address or domain.local, UDP Port optional - EXITING\n"); 96 | } 97 | 98 | if(isset($argv[2])) 99 | { 100 | $remote_port = $argv[2]; 101 | } 102 | 103 | exec('sudo ifconfig',$catch); 104 | 105 | foreach($catch as $line) 106 | { 107 | if(preg_match("/inet addr/i",$line)) 108 | { 109 | // echo $line."\n"; 110 | list($t, $ip) = preg_split("/:/", $line); 111 | list($ip, $t) = preg_split("/[\s,]+/", $ip); 112 | // echo 'IP is '.$ip."\n"; 113 | break; 114 | } 115 | } 116 | 117 | $in = "R\n"; 118 | 119 | socket_sendto($sock, $in , 100 , 0 , $remote_ip , $remote_port); 120 | 121 | socket_getsockname ( $sock, $localIP, $localPort ); 122 | echo "startUdpUpdateStatus at $remote_ip:$remote_port using $ip:$localPort\n"; 123 | 124 | 125 | while(1) 126 | { 127 | 128 | $result = socket_recvfrom($sock, $buf, 2048, MSG_WAITALL, $remote_ip, $remote_port); 129 | 130 | if( $result !== FALSE ) 131 | { 132 | $now = date("m/d/Y Hi"); 133 | echo "\$buf: $buf at $now\n"; 134 | } 135 | } 136 | 137 | echo "Closing socket and exiting\n"; 138 | socket_close($sock); 139 | 140 | function is_ipv4($str) 141 | { 142 | $ret = filter_var($str, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); 143 | 144 | return $ret; 145 | } 146 | ?> 147 | -------------------------------------------------------------------------------- /web/PHP_GnuPlot.php: -------------------------------------------------------------------------------- 1 | 2 | 8 | * 9 | * Website : http://celeste.cn 10 | * 11 | * The main purpose of this program is to facilitate plotting with data 12 | * generated from program. It is not a *Complete* interface to GNU Plot. 13 | * 14 | * This library is free software; you can redistribute it and/or 15 | * modify it under the terms of the GNU Lesser General Public 16 | * License as published by the Free Software Foundation; either 17 | * version 2.1 of the License, or (at your option) any later version. 18 | * 19 | * This library is distributed in the hope that it will be useful, 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | * Lesser General Public License for more details. 23 | * 24 | **/ 25 | 26 | error_reporting(E_ERROR); 27 | 28 | 29 | // change this if u need 30 | //$GNUPLOT = 'C:\gnuplot\bin\pgnuplot.exe'; // for Windows 31 | $GNUPLOT = "/usr/bin/gnuplot"; // for linux 32 | 33 | $tempDir = '/tmp'; // somewhere we can store the temporary data files 34 | 35 | // DONT change the code below if you dont know what you are doing 36 | $IDCounter = 0; 37 | 38 | /** 39 | * PGData is a general data unit for series plotting 40 | * 41 | * It can either be created from an external data file ( in this case, it is simply a wrapper to the file ) 42 | * or created with an empty list of entries ( You can append entries to the list ). 43 | * 44 | * Before it is plotted, if it is created in the 2nd way, it must have its data dumped into a file. 45 | * 46 | **/ 47 | 48 | class PGData { 49 | // privaite variables 50 | var $filename; // Name of the data file. Can be explicitly specified or automatically generated 51 | var $DataList; // This is only useful when $filename is not specified 52 | var $legend; // Title of the data you want to see on the graph 53 | 54 | function PGData($legend = '') { 55 | $this->legend = $legend; 56 | } 57 | 58 | /** 59 | * static method to initialize a data object from an external data file 60 | * the object is just a wrapper to the file 61 | **/ 62 | function createFromFile($filename, $legend = '') { 63 | $Data = new PGData($legend); 64 | if (!file_exists($filename) || !is_readable($filename)) { 65 | print "Error: $filename is not a readable datafile!\n"; 66 | return NULL; 67 | } 68 | $Data->filename = $filename; 69 | return $Data; 70 | } 71 | 72 | function changeLegend( $legend ) { $this->legend = $legend; } 73 | 74 | function addDataEntry( $entry ){ 75 | if (!$filename) $this->DataList[] = $entry; 76 | else print "Error: Cannot add an entry into file content [ $this->filename ] !\n"; 77 | 78 | } 79 | 80 | function dumpIntoFile( $filename='' ) { 81 | 82 | if ($this->filename) { print "Error: Data file exists [ $this->filename ] !\n"; return; } 83 | global $tempDir, $IDCounter; 84 | if (!$filename) { 85 | // generate a file name 86 | $filename = $tempDir.'/data_'. ( $IDCounter++ ) .'.txt'; 87 | global $toRemove; 88 | $toRemove[] = $filename; 89 | } 90 | $fp = fopen($filename, 'w'); 91 | foreach( $this->DataList as $entry ) fwrite($fp, implode("\t", $entry)."\n"); 92 | fclose($fp); 93 | $this->filename = $filename; // no longer changeable 94 | } 95 | } 96 | 97 | /** 98 | * The main class to communicate with GNU Plot 99 | * It opens a pipe to a GNU Plot process 100 | * 101 | * You can guess the idea from the names of the functions 102 | * Some of the parameters are explained in the comments 103 | **/ 104 | 105 | class GNUPlot { 106 | 107 | // private variables 108 | var $ph = NULL; 109 | var $toRemove; 110 | var $plot; 111 | var $splot; 112 | 113 | function GNUPlot() { 114 | global $GNUPLOT; 115 | $this->ph = popen($GNUPLOT, 'w'); 116 | $this->toRemove = array(); 117 | $this->plot = 'plot'; 118 | $this->splot = 'splot'; 119 | } 120 | 121 | // You can tell from the name of the function. 122 | function draw2DLine($x1,$y1, $x2, $y2) 123 | { 124 | $this->exe( "set arrow from $x1,$y1 to $x2,$y2 nohead\n" ); 125 | } 126 | function draw3DLine($x1,$y1,$z1, $x2, $y2,$z2) 127 | { 128 | $this->exe( "set arrow from $x1,$y1,$z1 to $x2,$y2,$z2 nohead\n" ); 129 | } 130 | 131 | function draw2DArrow($x1,$y1, $x2, $y2) 132 | { 133 | $this->exe( "set arrow from $x1,$y1 to $x2,$y2 head\n" ); 134 | } 135 | function draw3DArrow($x1,$y1,$z1, $x2, $y2,$z2) 136 | { 137 | $this->exe( "set arrow from $x1,$y1,$z1 to $x2,$y2,$z2 head\n" ); 138 | } 139 | 140 | function set2DLabel($labeltext, $x, $y, $justify='', $pre='', $extra='' ) 141 | { 142 | // $justify = {left | center | right} 143 | // $pre = { first|second|graph|screen } 144 | 145 | $this->exe( "set label \"". $labeltext ."\" at $pre $x,$y $extra\n"); 146 | } 147 | 148 | function set3DLabel($labeltext, $x, $y, $z, $justify='', $pre='', $extra='' ) 149 | { 150 | // $justify = {left | center | right} 151 | // $pre = { first|second|graph|screen } 152 | 153 | $this->exe( "set label \"". $labeltext ."\" at $pre $x,$y,$z $extra\n"); 154 | } 155 | 156 | function setRange( $dimension, $min, $max, $extra='' ) { 157 | // $dimension = x, y, z ...... 158 | if (!$dimension) $dimension = 'x'; 159 | $this->exe( "set ${dimension}range [$min:$max] $extra\n"); 160 | } 161 | 162 | // low level set command 163 | function set( $toSet ) { 164 | $this->exe( "set $toSet\n"); 165 | } 166 | 167 | function setTitle( $title, $extra='' ) { 168 | $this->exe( "set title \"$title\" $extra\n"); 169 | } 170 | 171 | // Set label for each axis 172 | function setDimLabel( $dimension, $text, $extra='' ) { 173 | // $dimension = x, y, z ...... 174 | $this->exe( "set ${dimension}label \"$text\" $extra\n"); 175 | } 176 | 177 | function setTics( $dimension, $option ) { 178 | // $dimension = x, y, z ...... 179 | $this->exe( "set ${dimension}tics $option \n" ); 180 | } 181 | 182 | function setSize( $x, $y, $extra='' ) { 183 | // $extra = {{no}square | ratio | noratio} 184 | $this->exe( "set size $extra $x,$y\n"); 185 | } 186 | 187 | function plotData( &$PGData, $method, $using, $axis='', $extra='' ) { 188 | /** 189 | * This function is for 2D plotting 190 | * 191 | * $method is `lines`, `points`, `linespoints`, `impulses`, `dots`, `steps`, `fsteps`, 192 | * `histeps`, errorbars, `xerrorbars`, `yerrorbars`, `xyerrorbars`, errorlines, 193 | * `xerrorlines`, `yerrorlines`, `xyerrorlines`, `boxes`, `filledcurves`, 194 | * `boxerrorbars`, `boxxyerrorbars`, `financebars`, `candlesticks`, `vectors` or pm3d 195 | * 196 | * $using is an expression controlling which data columns to use and how to use: 197 | * Example : $using = " 1:2 " means plotting column 2 against column 1 198 | * $using = " ($1):($2/2) " means use half of the value of column 2 to plot against column 1 199 | * You can introduce in more than 2 or 3 columns to enable styles like errorbars 200 | **/ 201 | 202 | $plot = $this->plot; 203 | if (!$PGData->filename) $PGData->dumpIntoFile(); 204 | if (!$PGData->filename) { print "Error: Empty dataset!\n"; return; } 205 | 206 | $fn = $PGData->filename; 207 | $title = $PGData->legend; 208 | 209 | if ($axis) $axis = " axis $axes "; 210 | $this->exe( "$plot '$fn' using $using title \"$title\" with $method $axis $extra\n"); 211 | //print "$plot '$fn' using $using title \"$title\" with $method $axis $extra\n"; 212 | $this->plot = 'replot'; 213 | 214 | } 215 | 216 | function splotData( &$PGData, $method, $using, $extra = '' ) { 217 | /** 218 | * This function is for 3D plotting 219 | * 220 | */ 221 | $splot = $this->splot; 222 | if (!$PGData->filename) $PGData->dumpIntoFile(); 223 | if (!$PGData->filename) { print "Error: Empty dataset!\n"; return; } 224 | 225 | $fn = $PGData->filename; 226 | $title = $PGData->legend; 227 | 228 | $this->exe( "$splot '$fn' using $using title \"$title\" with $method $extra\n"); 229 | $this->splot = 'replot'; 230 | 231 | } 232 | 233 | function export( $pic_filename ) { 234 | /** 235 | * export to $pic_filename 236 | * the file ext can be png, ps or eps 237 | */ 238 | 239 | if (preg_match("/\.png$/", $pic_filename)) $this->exe("set term png\n"); 240 | elseif (preg_match("/\.e?ps$/", $pic_filename)) $this->exe( "set term postscript\n"); 241 | // you can add more options here to support other formats 242 | else { $this->exe( "set term png\n"); $pic_filename.=".png"; } 243 | 244 | $this->exe( "set output \"$pic_filename\"\n"); 245 | $this->exe( "replot\n" ); 246 | } 247 | 248 | function reset() { 249 | /** 250 | * It is not a good idea to use this function in your program 251 | */ 252 | $this->exe( "reset\n" ); 253 | $this->plot = 'plot'; 254 | $this->splot = 'splot'; 255 | } 256 | 257 | function close() { 258 | flush($this->ph); 259 | pclose($this->ph); 260 | //sleep(count($this->toRemove) ); // allow gnu plot to finish so that we can safely remove the data files 261 | //foreach($this->toRemove as $filename) unlink($filename); 262 | } 263 | 264 | function exe( $command ) { 265 | fwrite($this->ph, $command); 266 | } 267 | 268 | } 269 | 270 | 271 | // in case you are using old PHP. just in case 272 | if (!function_exists('file_put_contents')) { 273 | function file_put_contents( $fn, $contents ) { 274 | $fp = fopen($fn, 'w'); 275 | fwrite($fp, $contents); 276 | fclose($fp); 277 | } 278 | } 279 | 280 | 281 | -------------------------------------------------------------------------------- /web/SensorStatus.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | "; 16 | 17 | if(mysqli_query($link, $queryStr)) 18 | { 19 | }else{ 20 | echo "Error: " . $queryStr . "
" . mysqli_error($link); 21 | } 22 | } 23 | 24 | if(isset($_POST["ip_address"]) && isset($_POST["udp_port"]) && isset($_POST["remove"])) 25 | { 26 | $deviceAddress = $_POST["ip_address"]; 27 | $devicePort = $_POST["udp_port"]; 28 | 29 | $queryStr = "DELETE FROM `Addresses` WHERE ipAddress='".$deviceAddress."'AND udpPort=".$devicePort; 30 | 31 | echo "\$queryStr = $queryStr
"; 32 | 33 | if(mysqli_query($link, $queryStr)) 34 | { 35 | }else{ 36 | echo "Error: " . $queryStr . "
" . mysqli_error($link); 37 | } 38 | } 39 | 40 | $headStr = " 41 | 42 | ESP8266 1-Wire Temperature / Switch Status 43 | 44 | 45 | 46 | 57 | 58 | "; 63 | echo $headStr; 64 | $dataTimer = 0; 65 | ?> 66 | 67 | 68 | 71 | 72 | 73 | 74 | 86 | 87 | 88 | 95 | 96 | 97 | 101 | 102 |
75 | 76 | 77 | 83 | 84 |
78 | ESP8266 1-Wire Temperature / Switch Status"; 80 | echo $titleStr; 81 | ?> 82 |
85 |
89 |
90 | New Device IP Address: 91 | New Device PORT Address: 92 | 93 |
94 |
98 |
99 |
100 |
103 | 104 | -------------------------------------------------------------------------------- /web/accessDatabase.php: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /web/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 |
4 | "> 5 | logo 6 | 7 |
10 | -------------------------------------------------------------------------------- /web/modifySettings.php: -------------------------------------------------------------------------------- 1 | "; 27 | 28 | //echo "\$upperTempc = $upperTempc, \$upperTempf = $upperTempf, \$upperDelay = $upperDelay
\$lowerTempc = $lowerTempc, \$lowerTempf = $lowerTempf, \$lowerDelay = $lowerDelay
"; 29 | 30 | if(isset($_POST["setUpdate"])) 31 | { 32 | $in = $setDomain." ".$deviceName."\n"; 33 | $udpStatus = udpRequest($ip_Address, $udp_Port, $in); 34 | if(isset($_POST["tempu"])) 35 | { 36 | if($_POST["tempu"] === "c") 37 | { 38 | if(isset($_POST["upperTemp"])) 39 | { 40 | $upperTemp = trim($_POST["upperTemp"]); 41 | }else{ 42 | $upperTemp = $upperTempc; 43 | } 44 | $in=$setAutoTemp.",U,C,".$upperTemp.",".$upperDelay."\n"; 45 | //echo "\$in = $in
"; 46 | $tempuStr = 47 | " 48 | °F 49 |
50 | °C 51 | "; 52 | }else{ 53 | if(isset($_POST["upperTemp"])) 54 | { 55 | $upperTemp = trim($_POST["upperTemp"]); 56 | }else{ 57 | $upperTemp = $upperTempf; 58 | } 59 | $in=$setAutoTemp.",U,F,".$upperTemp.",".$upperDelay."\n"; 60 | //echo "\$in = $in
"; 61 | $tempuStr = 62 | " 63 | °F 64 |
65 | °C 66 | "; 67 | } 68 | } 69 | $udpStatus = udpRequest($ip_Address, $udp_Port, $in); 70 | //echo "$udpStatus
"; 71 | 72 | if(isset($_POST["templ"])) 73 | { 74 | if($_POST["templ"] === "c") 75 | { 76 | if(isset($_POST["lowerTemp"])) 77 | { 78 | $lowerTemp = trim($_POST["lowerTemp"]); 79 | }else{ 80 | $lowerTemp = $lowerTempc; 81 | } 82 | $in=$setAutoTemp.",L,C,".$lowerTemp.",".$lowerDelay."\n"; 83 | //echo "\$in = $in
"; 84 | $templStr = 85 | " 86 | °F 87 |
88 | °C 89 | "; 90 | }else{ 91 | if(isset($_POST["lowerTemp"])) 92 | { 93 | $lowerTemp = trim($_POST["lowerTemp"]); 94 | }else{ 95 | $lowerTemp = $lowerTempf; 96 | } 97 | $in=$setAutoTemp.",L,F,".$lowerTemp.",".$lowerDelay."\n"; 98 | //echo "\$in = $in
"; 99 | $templStr = 100 | " 101 | °F 102 |
103 | °C 104 | "; 105 | } 106 | } 107 | $udpStatus = udpRequest($ip_Address, $udp_Port, $in); 108 | //echo "$udpStatus
"; 109 | 110 | $in = $setMode."A\n"; 111 | $udpStatus = udpRequest($ip_Address, $udp_Port, $in); 112 | //echo "$udpStatus
"; 113 | 114 | $in = $getStatus."\n"; 115 | $udpStatus = udpRequest($ip_Address, $udp_Port, $in); 116 | //echo "$udpStatus
"; 117 | 118 | $titleStr = "

Settings Updated

"; 119 | }else{ 120 | $in = $getStatus."\n"; 121 | //echo "\$in = $in
"; 122 | $udpStatus = udpRequest($ip_Address, $udp_Port, $in); 123 | //echo "\$udpStatus = $udpStatus
"; 124 | $udpType = explode(",", $udpStatus); 125 | $deviceName = trim($udpType[4]); 126 | //echo "\$deviceName = $deviceName
"; 127 | 128 | $in = $getMode."\n"; 129 | //echo "\$in = $in
"; 130 | 131 | $udpStatus = udpRequest($ip_Address, $udp_Port, $in); 132 | //echo "\$udpStatus = $udpStatus
"; 133 | $udpType = explode(",", $udpStatus); 134 | $upperTempf = $udpType[0]; 135 | $upperTempc = $udpType[1]; 136 | $upperDelay = trim($udpType[2]); 137 | $lowerTempf = $udpType[3]; 138 | $lowerTempc = $udpType[4]; 139 | $lowerDelay = trim($udpType[5]); 140 | $upperTemp = $upperTempf; 141 | $lowerTemp = $lowerTempf; 142 | $tempuStr = 143 | " 144 | °F 145 |
146 | °C 147 | "; 148 | 149 | $templStr = 150 | " 151 | °F 152 |
153 | °C 154 | "; 155 | $titleStr = "

Modify Settings

"; 156 | } 157 | 158 | //echo "updateStatus.php: \$ip_Address = $ip_Address, \$udp_Port = $udp_Port, \$deviceName = $deviceName
"; 159 | 160 | //echo "\$upperTempc = $upperTempc, \$upperTempf = $upperTempf, \$upperDelay = $upperDelay
\$lowerTempc = $lowerTempc, \$lowerTempf = $lowerTempf, \$lowerDelay = $lowerDelay
"; 161 | 162 | $headStr = 163 | " 164 | 165 | 166 | 167 | 168 | Temperature Data 169 | 170 | 171 | 172 | 176 | 177 | "; 178 | 179 | $headerStr = 180 | " 181 | 182 | 183 | 188 | 189 |
184 | 185 | \"logo\" 186 | 187 |
190 | "; 191 | 192 | $bodyStr = 193 | " 194 | 195 | 196 | 197 | 206 | 207 | 208 | 215 | 216 |
198 | 199 | 200 | 203 | 204 |
201 | $titleStr 202 |
205 |
209 |
210 | 211 | 212 | 213 | 214 |
217 | 218 | 219 | 222 | 223 | 224 | 227 | 228 | 229 | 232 | 235 | 238 | 239 | 240 | 243 | 246 | 249 | 250 | 251 | 254 | 255 |
220 | 221 |
225 | NAME: 226 |
230 | Upper Temperature
231 |
233 | $tempuStr 234 | 236 | Upper Delay (Seconds)
237 |
241 | Lower Temperature
242 |
244 | $templStr 245 | 247 | Lower Delay (Seconds)
248 |
252 | 253 |
256 | "; 257 | 258 | $footStr = 259 | " 260 | 261 | 262 | "; 263 | echo "$headStr$headerStr$bodyStr$footStr"; 264 | ?> 265 | -------------------------------------------------------------------------------- /web/plotData.php: -------------------------------------------------------------------------------- 1 | "; 13 | } 14 | 15 | if(isset($_POST["ip_address"])) 16 | { 17 | $ip_address=$_POST["ip_address"]; 18 | $deviceName=$_POST["device_name"]; 19 | $tempType=$_POST["temptype"]; 20 | // echo "updateStatus.php: \$ip_address = $ip_address, \$deviceName = $deviceName, \$tempType=$tempType
"; 21 | } 22 | 23 | 24 | set_time_limit(0); 25 | $hotTest = ""; 26 | $coldTest = ""; 27 | $pTemp = new GNUPlot(); 28 | $actionTime = date("U"); 29 | $rightNow = new DateTime(date()); 30 | // echo "rightNow = ".$rightNow->format("Y-m-d H:i")."\n"; 31 | switch($_POST["interval"]) 32 | { 33 | case "60": 34 | $interval = "Minutes"; 35 | break; 36 | 37 | case "86400": 38 | $interval = "Days"; 39 | break; 40 | 41 | case "2592000": 42 | $interval = "Months"; 43 | break; 44 | 45 | case "31104000": 46 | $interval = "Years"; 47 | break; 48 | 49 | case "3600": 50 | default: 51 | $interval = "Hours"; 52 | break; 53 | } 54 | if((is_numeric($_POST["cntBack"])) && (is_numeric($_POST["interval"]))) 55 | { 56 | // echo $_POST["cntBack"] * $_POST["interval"]."\n"; 57 | $startTime = $actionTime - ($_POST["cntBack"] * $_POST["interval"]); 58 | // echo $startTime."\n"; 59 | $query = "SELECT * FROM device WHERE ipaddress='".$ip_address."' AND time>='".$startTime."'"; 60 | }else if($_POST["cntBetween"] === "cntBetween"){ 61 | $startDate = new DateTime($_POST["startYear"]."/".$_POST["startMonth"]."/".$_POST["startDay"]." ".$_POST["startHour"].":".$_POST["startMinute"]); 62 | $endDate = new DateTime($_POST["endYear"]."/".$_POST["endMonth"]."/".$_POST["endDay"]." ".$_POST["endHour"].":".$_POST["endMinute"]); 63 | /* 64 | echo "startDate = ".$startDate->format("Y-m-d H:i")."\n"; 65 | echo "endDate = ".$endDate->format("Y-m-d H:i")."\n"; 66 | echo "startDate = ".$startDate->format("U")."\n"; 67 | echo "endDate = ".$endDate->format("U")."\n"; 68 | */ 69 | $query = "SELECT * FROM device WHERE ipaddress='".$ip_address."' AND time>='".$startDate->format("U")."' AND time<='".$endDate->format("U")."'"; 70 | // echo $query."\n"; 71 | $timeSpan = $endDate->format("U") - $startDate->format("U"); 72 | // echo "timeSpan = ".$timeSpan."\n"; 73 | }else{ 74 | $query = "SELECT * FROM device WHERE ipaddress='".$ip_address."'"; 75 | } 76 | // echo $query."\n"; 77 | $result = mysqli_query($link, $query); 78 | $rowCnt = mysqli_num_rows($result); 79 | 80 | // set line colors 81 | $pTemp->set("style line 1 linewidth 2 linecolor rgb \"#000\""); 82 | $pTemp->set("style line 2 linecolor rgb \"red\""); 83 | $pTemp->set("style line 3 linecolor rgb \"blue\""); 84 | 85 | // assign line values 86 | $tempData = new PGData('Temperature'); 87 | 88 | $oldTime = NULL; 89 | while ($obj = mysqli_fetch_object($result)) 90 | { 91 | if($hotTest ==="") 92 | { 93 | $hotTest = $obj->$tempType; 94 | }else if($obj->$tempType > $hotTest){ 95 | $hotTest = $obj->$tempType; 96 | } 97 | if($coldTest ==="") 98 | { 99 | $coldTest = $obj->$tempType; 100 | }else if($obj->$tempType < $coldTest){ 101 | $coldTest = $obj->$tempType; 102 | } 103 | if($oldTime != NULL) 104 | { 105 | $secCnt = ($obj->time) - $oldTime; 106 | $tempData->addDataEntry(array($obj->$tempType, $secCnt )); 107 | }else{ 108 | $tempData->addDataEntry(array($obj->$tempType, 0)); 109 | $oldTime = $obj->time; 110 | } 111 | } 112 | // echo "Select returned ".$rowCnt." rows.\n"; 113 | mysqli_free_result($result); 114 | $tempTitle = "$deviceName Temperature Graph"; 115 | $pTemp->setTitle($tempTitle); 116 | if(is_numeric($_POST["interval"])) 117 | { 118 | $tickMark = "($2/".$_POST["interval"]."):1"; 119 | }else if($_POST["cntBetween"] === "cntBetween"){ 120 | // echo "entering timeSpan Switch Statement\n"; 121 | switch($timeSpan) 122 | { 123 | case (($timeSpan >= 0) && ($timeSpan <= 3600)): 124 | $interval = "Minutes"; 125 | $tickMark = "($2/60):1"; 126 | break; 127 | 128 | case (($timeSpan >= 86401 ) && ($timeSpan <= 2592000)): 129 | $interval = "Days"; 130 | $tickMark = "($2/86400):1"; 131 | break; 132 | 133 | case (($timeSpan >= 2592001 ) && ($timeSpan <= 31104000)): 134 | $interval = "Months"; 135 | $tickMark = "($2/2592000):1"; 136 | break; 137 | 138 | case ($timeSpan >= 31104001) : 139 | $interval = "Years"; 140 | $tickMark = "($2/31104000):1"; 141 | break; 142 | 143 | default: 144 | case (($timeSpan >= 3601) && ($timeSpan <= 86400)): 145 | $interval = "Hours"; 146 | $tickMark = "($2/3600):1"; 147 | break; 148 | } 149 | 150 | }else{ 151 | $interval = "Hours"; 152 | $tickMark = "($2/3600):1"; 153 | } 154 | // echo "tickMark = ".$tickMark."\n"; 155 | $pTemp->setDimLabel(x, $interval); 156 | if($tempType === "tempc") 157 | { 158 | $pTemp->setDimLabel(y, "Degrees Celsius"); 159 | }else{ 160 | $pTemp->setDimLabel(y, "Degrees Fahrenheit"); 161 | } 162 | $pTemp->set("terminal png size 1280,400"); 163 | $pTemp->plotData( $tempData, 'lines', $tickMark,'','ls 1'); 164 | // $pTemp->plotData( $thData, 'lines', $tickMark,'','ls 2'); 165 | // $pTemp->plotData( $tcData, 'lines', $tickMark,'','ls 3'); 166 | /* 167 | $pTemp->plotData( $tempData, 'lines', '($2/3600):1','','ls 1'); 168 | $pTemp->plotData( $thData, 'lines', '($2/3600):1','','ls 2'); 169 | $pTemp->plotData( $tcData, 'lines', '($2/3600):1','','ls 3'); 170 | */ 171 | $pTemp->setRange('y', $coldTest-1, $hotTest+1); 172 | $pTemp->export('/var/www/images/pTemp.png'); 173 | $pTemp->close(); 174 | ?> 175 | 176 | 177 | 178 | 179 | 180 | Temperature Data 181 | 182 | 183 | 184 | 188 | 189 | 190 | time; 196 | // echo "startDateTime = ".date("Y m d H i", $startDateTime)."
"; 197 | mysqli_free_result($result); 198 | mysqli_close($link); 199 | ?> 200 | 201 | 202 | 203 | 208 | 209 | 210 | 213 | 214 | 215 | 236 | 364 | 365 | 366 | 369 | 370 | 371 | 376 | 377 |
204 | 207 |
211 |

Graph

212 |
216 | 217 | 220 | 221 | " 222 | ; 223 | echo $formStr; 224 | ?> 225 | Go Back: 226 | 233 | 234 | 235 | 237 | 238 | 239 | 251 | 361 | 362 |
240 |
241 | 244 | 245 | " 246 | ; 247 | echo $formStr; 248 | ?> 249 | 250 |
252 | 253 | 254 | 304 | 305 | 306 | 356 | 357 |
255 | Start: 256 | 261 | 276 | 285 | 294 | 303 |
307 | End:  308 | 313 | 328 | 337 | 346 | 355 |
358 |
359 | 360 |
363 |
367 | 368 |
372 | 375 |
378 | 379 | 380 | -------------------------------------------------------------------------------- /web/udpRequest.php: -------------------------------------------------------------------------------- 1 | "; 50 | 51 | $myPID = getmypid(); 52 | 53 | error_reporting(~E_WARNING); 54 | 55 | $fileName = "/var/log/esp8266/udp_".$ip_Address."_".$udp_Port.".log"; 56 | $socBufSize = 2048; 57 | 58 | if(!($socket = socket_create(AF_INET, SOCK_DGRAM, 0))) 59 | { 60 | $errorcode = socket_last_error(); 61 | $errormsg = socket_strerror($errorcode); 62 | 63 | die("Couldn't create socket: [$errorcode] $errormsg \n"); 64 | } 65 | 66 | 67 | if(!socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,array("sec"=>2,"usec"=>0))) 68 | { 69 | die("Couldn't set Socket Receive Timeout\n"); 70 | } 71 | 72 | if( ! $fr = fopen($fileName, "a+") ) 73 | { 74 | die("Could not open file:".$fileName."\n"); 75 | }else{ 76 | fwrite($fr, "\n"); 77 | fwrite($fr, date("D M j G:i:s Y")); 78 | } 79 | 80 | $maxTries = 5; 81 | 82 | do{ 83 | $result = ""; 84 | fwrite($fr, "\n\$ip_address = $ip_Address, \$udp_Port = $udp_Port, pid = $myPID\n"); 85 | socket_sendto($socket, $in , strlen($in) , 0 , $ip_Address , $udp_Port); 86 | fwrite($fr, "command sent: ".$in); 87 | 88 | if(socket_recvfrom($socket, $result, $socBufSize, MSG_WAITALL, $ip_Address, $udp_Port)) 89 | fwrite($fr, socket_strerror(socket_last_error($socket))); 90 | 91 | $resultStr = ""; 92 | 93 | if($result === "=") 94 | { 95 | $in = "="; 96 | fwrite($fr, "large packet started: ".$in."\n"); 97 | socket_sendto($socket, $in , strlen($in) , 0 , $ip_Address , $udp_Port); 98 | socket_recvfrom($socket, $result, $socBufSize, MSG_WAITALL, $ip_Address, $udp_Port); 99 | fwrite($fr, "first packet received: ".$result."\n"); 100 | 101 | 102 | do{ 103 | $resultStr .= $result; 104 | $result = ""; 105 | fwrite($fr, "requesting next segment: ".$in."\n"); 106 | socket_sendto($socket, $in , strlen($in), 0 , $ip_Address , $udp_Port); 107 | socket_recvfrom($socket, $result, $socBufSize, MSG_WAITALL, $ip_Address, $udp_Port); 108 | fwrite($fr, "next packet received: ".$result."\n"); 109 | }while($result !== '+'); 110 | 111 | if($result === '+') 112 | { 113 | fwrite($fr, "final segment received: ".$result."\n"); 114 | $result = ""; 115 | } 116 | 117 | $in = ""; 118 | }else{ 119 | $resultStr .= $result; 120 | $result = ""; 121 | } 122 | $trimmedResultStr = trim($resultStr); 123 | $maxTries--; 124 | }while($trimmedResultStr === "ERROR" && $maxTries > 0); 125 | 126 | if($maxTries === 0) 127 | { 128 | fwrite($fr, "maxTries exceeded on PID# $myPID, I'm killing myself\n"); 129 | fclose($fr); 130 | socket_close($socket); 131 | die(); 132 | } 133 | 134 | if($resultStr === "") 135 | { 136 | fwrite($fr, "NO Packet Received:\n"); 137 | }else{ 138 | fwrite($fr, "packet received:\n".$resultStr); 139 | } 140 | fclose($fr); 141 | 142 | socket_close($socket); 143 | return $resultStr; 144 | } 145 | ?> 146 | 147 | -------------------------------------------------------------------------------- /web/updateStatus.php: -------------------------------------------------------------------------------- 1 | "; 8 | if($result = mysqli_query($link, $query)) 9 | { 10 | $numAddresses = mysqli_num_rows($result); 11 | // printf("Select returned %d rows.\n", mysqli_num_rows($result)); 12 | } 13 | 14 | $dataTimer = date("s"); 15 | $setDebug = 0; 16 | 17 | for($x = 0; $x < $numAddresses; $x++) 18 | { 19 | $ipAddressObj = mysqli_fetch_object($result); 20 | $ip_Address = $ipAddressObj->ipAddress; 21 | $udp_Port = $ipAddressObj->udpPort; 22 | // echo "\$ip_Address = ".$ipAddressObj->ipAddress.", \$udp_Port = ".$ipAddressObj->udpPort."
"; 23 | $in = $getStatus."\n"; 24 | $udpStatus = udpRequest($ip_Address, $udp_Port, $in); 25 | // echo "\$udpStatus = ".$udpStatus."
"; 26 | 27 | $udpType = explode(",", $udpStatus); 28 | $tempStr = 29 | "
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | ".$udpType[4]."
39 |
40 | 41 | 42 | 43 |
44 | 45 | 46 | Temperature 47 |
48 |
49 | 50 | 51 | 52 | 53 | 54 |
55 | ".$udpType[0]."° C 56 |

57 | 58 | 59 | Temperature 60 |
61 |
62 | 63 | 64 | 65 | 66 |
67 | ".$udpType[1]."° F 68 |

69 | 70 | 71 | Upper Switch 72 |

73 | "; 74 | if($udpType[2] === " N") 75 | { 76 | $tempStr .= "ON "; 77 | }else{ 78 | $tempStr .= "OFF"; 79 | } 80 | $tempStr .= 81 | " 82 |

83 | 84 | 85 | Lower Switch 86 |

87 | "; 88 | if($udpType[3] === " N") 89 | { 90 | $tempStr .= "ON "; 91 | }else{ 92 | $tempStr .= "OFF"; 93 | } 94 | $tempStr .= 95 | " 96 |

97 | 98 |
"; 99 | 100 | echo "\n\n$tempStr\n
"; 101 | if($setDebug > 0) 102 | echo "\$dataTimer = $dataTimer\n"; 103 | if($dataTimer == "00" || $dataTimer == "01") 104 | { 105 | $time = time("U"); 106 | $switch1 = trim($udpType[2]); 107 | $switch2 = trim($udpType[3]); 108 | $insertQuery = "INSERT INTO device SET `ipaddress`=\"$ip_Address\",`port`=$udp_Port,`time`=$time,`tempc`=$udpType[0],`tempf`=$udpType[1],`switch1`=\"$switch1\",`switch2`=\"$switch2\""; 109 | if($setDebug != 0) 110 | echo $insertQuery."\n"; 111 | $insertResult = mysqli_query($link, $insertQuery); 112 | if($insertResult === FALSE && $setDebug != 0) 113 | { 114 | echo "Data Insert Failed\n"; 115 | printf("Error: %s\n", mysqli_error($link)); 116 | } 117 | 118 | if($insertResult === TRUE && $setDebug != 0) 119 | { 120 | echo "Data Insert Success\n"; 121 | } 122 | mysqli_free_result($insertResult); 123 | } 124 | } 125 | /* free result set */ 126 | mysqli_free_result($result); 127 | ?> 128 | --------------------------------------------------------------------------------