├── .gitattributes ├── .gitignore ├── esp_4051 └── esp_4051.ino ├── esp_595 └── esp_595.ino ├── esp_595_spi └── esp_595_spi.ino ├── esp_595_spi_4051 └── esp_595_spi_4051.ino ├── esp_597 └── esp_597.ino ├── esp_597_spi └── esp_597_spi.ino ├── esp_counter_clock └── esp_counter_clock.ino ├── esp_daylight_alarm_rtc └── esp_daylight_alarm_rtc.ino ├── esp_eeprom_test └── esp_eeprom_test.ino ├── esp_http_node └── esp_http_node.ino ├── esp_http_pwm └── esp_http_pwm.ino ├── esp_mqtt_button_panel └── esp_mqtt_button_panel.ino ├── esp_mqtt_dht └── esp_mqtt_dht.ino ├── esp_mqtt_display └── esp_mqtt_display.ino ├── esp_mqtt_display_01 └── esp_mqtt_display_01.ino ├── esp_mqtt_flow └── esp_mqtt_flow.ino ├── esp_mqtt_node └── esp_mqtt_node.ino ├── esp_mqtt_relay └── esp_mqtt_relay.ino ├── esp_mqtt_rtc └── esp_mqtt_rtc.ino ├── esp_mqtt_sonoff └── esp_mqtt_sonoff.ino ├── espdisplayhome └── espdisplayhome.ino └── libraries ├── Bounce2 ├── .gitignore ├── Bounce1.zip ├── Bounce2.cpp ├── Bounce2.h ├── BouncySwitch_lockout.png ├── BouncySwitch_stable.png ├── INSTALL.txt ├── LICENSE ├── README.md ├── examples │ ├── bounce │ │ └── bounce.ino │ ├── bounce2buttons │ │ └── bounce2buttons.ino │ ├── change │ │ └── change.ino │ ├── circuit-bounce-change-duration-retrigger.png │ ├── duration │ │ └── duration.ino │ └── retrigger │ │ └── retrigger.ino ├── keywords.txt ├── library.json └── library.properties ├── DHT ├── DHT.cpp ├── DHT.h ├── README.txt ├── examples │ └── DHTtester │ │ └── DHTtester.ino └── library.properties ├── IRremoteESP8266 ├── Contributors.md ├── IRremoteESP8266.cpp ├── IRremoteESP8266.h ├── IRremoteInt.h ├── LICENSE.txt ├── README.md ├── examples │ ├── IRGCSendDemo │ │ └── IRGCSendDemo.ino │ ├── IRGCTCPServer │ │ └── IRGCTCPServer.ino │ ├── IRServer │ │ └── IRServer.ino │ ├── IRrecvDemo │ │ └── IRrecvDemo.ino │ ├── IRrecvDump │ │ └── IRrecvDump.ino │ ├── IRrecvDumpV2 │ │ └── IRrecvDumpV2.ino │ ├── IRsendDemo │ │ └── IRsendDemo.ino │ └── JVCPanasonicSendDemo │ │ └── JVCPanasonicSendDemo.ino ├── keywords.txt ├── library.json └── library.properties ├── PCF8574_HD44780_I2C ├── Examples │ ├── CustomChars │ │ └── CustomChars.ino │ ├── Demo │ │ └── Demo.ino │ ├── HelloWorld │ │ └── HelloWorld.ino │ ├── MultipleLcd │ │ └── MultipleLcd.ino │ └── SerialDisplay │ │ └── SerialDisplay.ino ├── Info │ ├── HD44780.pdf │ ├── I2C_LCD_Breakoutboard.jpg │ ├── PCF8574.pdf │ └── README.txt ├── PCF8574_HD44780_I2C.cpp ├── PCF8574_HD44780_I2C.h └── keywords.txt ├── Rtc ├── .gitattributes ├── .gitignore ├── README.md ├── RtcDS1307.cpp ├── RtcDS1307.h ├── RtcDS3231.cpp ├── RtcDS3231.h ├── RtcDateTime.cpp ├── RtcDateTime.h ├── RtcTemperature.h ├── RtcUtility.cpp ├── RtcUtility.h ├── examples │ ├── DS1307_Memory │ │ └── DS1307_Memory.ino │ ├── DS1307_Simple │ │ └── DS1307_Simple.ino │ ├── DS3231_Alarms │ │ ├── DS3231_Alarms.ino │ │ ├── DS3231_Alarms.vcxproj │ │ ├── DS3231_Alarms.vcxproj.filters │ │ └── Visual Micro │ │ │ └── .DS3231_Alarms.vsarduino.h │ ├── DS3231_Simple │ │ └── DS3231_Simple.ino │ └── DS3231_StoreIt │ │ └── DS3231_StoreIt.ino └── keywords.txt ├── WiFiManager ├── LICENSE ├── README.md ├── WiFiManager.cpp ├── WiFiManager.h ├── examples │ ├── AutoConnect │ │ └── AutoConnect.ino │ ├── AutoConnectWithFSParameters │ │ └── AutoConnectWithFSParameters.ino │ ├── AutoConnectWithFSParametersAndCustomIP │ │ └── AutoConnectWithFSParametersAndCustomIP.ino │ ├── AutoConnectWithFeedback │ │ └── AutoConnectWithFeedback.ino │ ├── AutoConnectWithFeedbackLED │ │ └── AutoConnectWithFeedbackLED.ino │ ├── AutoConnectWithReset │ │ └── AutoConnectWithReset.ino │ ├── AutoConnectWithStaticIP │ │ └── AutoConnectWithStaticIP.ino │ ├── AutoConnectWithTimeout │ │ └── AutoConnectWithTimeout.ino │ └── OnDemandConfigPortal │ │ └── OnDemandConfigPortal.ino ├── extras │ └── WiFiManager.template.html ├── keywords.txt ├── library.json ├── library.properties └── travis │ └── common.sh ├── pubsubclient.old ├── .gitignore ├── CHANGES.txt ├── LICENSE.txt ├── README ├── examples │ ├── mqtt_auth │ │ └── mqtt_auth.ino │ ├── mqtt_basic │ │ └── mqtt_basic.ino │ ├── mqtt_publish_in_callback │ │ └── mqtt_publish_in_callback.ino │ ├── mqtt_qos │ │ └── mqtt_qos.ino │ ├── mqtt_stream │ │ └── mqtt_stream.ino │ └── mqtt_subscriber │ │ └── mqtt_subscriber.ino ├── keywords.txt ├── library.properties ├── src │ ├── MQTT.cpp │ ├── MQTT.h │ ├── PubSubClient.cpp │ └── PubSubClient.h └── tests │ ├── .gitignore │ ├── Makefile │ ├── README.md │ ├── src │ ├── connect_spec.cpp │ ├── keepalive_spec.cpp │ ├── lib │ │ ├── Arduino.h │ │ ├── BDDTest.cpp │ │ ├── BDDTest.h │ │ ├── Buffer.cpp │ │ ├── Buffer.h │ │ ├── Client.h │ │ ├── IPAddress.h │ │ ├── ShimClient.cpp │ │ ├── ShimClient.h │ │ ├── Stream.cpp │ │ ├── Stream.h │ │ └── trace.h │ ├── publish_spec.cpp │ ├── receive_spec.cpp │ └── subscribe_spec.cpp │ ├── testcases │ ├── __init__.py │ ├── mqtt_basic.py │ ├── mqtt_publish_in_callback.py │ └── settings.py │ └── testsuite.py └── pubsubclient ├── .gitignore ├── CHANGES.txt ├── LICENSE.txt ├── README ├── README.md ├── examples ├── mqtt_auth │ └── mqtt_auth.ino ├── mqtt_basic │ └── mqtt_basic.ino ├── mqtt_esp8266 │ └── mqtt_esp8266.ino ├── mqtt_publish_in_callback │ └── mqtt_publish_in_callback.ino ├── mqtt_qos │ └── mqtt_qos.ino ├── mqtt_reconnect_nonblocking │ └── mqtt_reconnect_nonblocking.ino ├── mqtt_stream │ └── mqtt_stream.ino └── mqtt_subscriber │ └── mqtt_subscriber.ino ├── keywords.txt ├── library.json ├── library.properties ├── src ├── MQTT.cpp ├── MQTT.h ├── PubSubClient.cpp └── PubSubClient.h └── tests ├── .gitignore ├── Makefile ├── README.md ├── src ├── connect_spec.cpp ├── keepalive_spec.cpp ├── lib │ ├── Arduino.h │ ├── BDDTest.cpp │ ├── BDDTest.h │ ├── Buffer.cpp │ ├── Buffer.h │ ├── Client.h │ ├── IPAddress.cpp │ ├── IPAddress.h │ ├── ShimClient.cpp │ ├── ShimClient.h │ ├── Stream.cpp │ ├── Stream.h │ └── trace.h ├── publish_spec.cpp ├── receive_spec.cpp └── subscribe_spec.cpp ├── testcases ├── __init__.py ├── mqtt_basic.py ├── mqtt_publish_in_callback.py └── settings.py └── testsuite.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | 38 | # Directories potentially created on remote AFP share 39 | .AppleDB 40 | .AppleDesktop 41 | Network Trash Folder 42 | Temporary Items 43 | .apdisk 44 | -------------------------------------------------------------------------------- /esp_4051/esp_4051.ino: -------------------------------------------------------------------------------- 1 | int s0 = 4; 2 | int s1 = 5; 3 | void setup(){ 4 | pinMode(s0, OUTPUT); // s0 5 | pinMode(s1, OUTPUT); // s1 6 | Serial.begin(115200); 7 | } 8 | 9 | //pin 1 is zoom 10 | //pin 2 is x 11 | //pin 0 is y 12 | 13 | void loop () { 14 | 15 | 16 | 17 | for (int count=1; count<=3; count++) { 18 | 19 | digitalWrite(s0, bitRead(count,0)); 20 | 21 | digitalWrite(s1, bitRead(count,1)); 22 | 23 | 24 | Serial.print("pin :"); 25 | Serial.print(count,HEX); 26 | Serial.print(" "); 27 | Serial.println(analogRead(A0)); 28 | delay(300); 29 | 30 | } 31 | 32 | } 33 | 34 | -------------------------------------------------------------------------------- /esp_595/esp_595.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Shift Register Example 3 | Turning on the outputs of a 74HC595 using an array 4 | 5 | Hardware: 6 | * 74HC595 shift register 7 | * LEDs attached to each of the outputs of the shift register 8 | 9 | */ 10 | int MR = 16; 11 | int STCP = 15; 12 | int PL = 2; 13 | int SHCP = 14; 14 | int Q = 12; 15 | int DO = 13; 16 | 17 | //holders for infromation you're going to pass to shifting function 18 | byte data; 19 | byte dataIn; 20 | byte dataArray[10]; 21 | byte errorLED = 0x01; 22 | byte runLED = 0x02; 23 | byte rstLED = 0x04; 24 | byte crsLED = 0x08; 25 | byte fineLED = 0x10; 26 | #include "SPI.h" 27 | 28 | void setup() { 29 | SPI.begin(); 30 | SPI.setBitOrder(MSBFIRST); 31 | pinMode(MR, OUTPUT); 32 | pinMode(STCP, OUTPUT); 33 | pinMode(PL, OUTPUT); 34 | pinMode(SHCP, OUTPUT); 35 | pinMode(Q, INPUT); 36 | pinMode(DO, OUTPUT); 37 | digitalWrite(MR, 1); 38 | digitalWrite(STCP, 0); 39 | digitalWrite(PL, 1); 40 | digitalWrite(SHCP, 0); 41 | digitalWrite(DO, 0); 42 | Serial.begin(115200); 43 | 44 | //Binary notation as comment 45 | dataArray[0] = errorLED | runLED; 46 | dataArray[1] = rstLED | crsLED; 47 | dataArray[2] = fineLED | errorLED; 48 | dataArray[3] = crsLED; 49 | dataArray[4] = rstLED; 50 | } 51 | 52 | 53 | 54 | 55 | void loop() { 56 | 57 | for (int j = 0; j < 5; j++) { 58 | data = dataArray[j]; 59 | dataIn = 0x00; 60 | digitalWrite(STCP, LOW); 61 | /* digitalWrite(PL, 0); 62 | digitalWrite(PL, 1); 63 | dataIn = dataIn | digitalRead(Q); 64 | digitalWrite(DO, data & 0b00000001); 65 | digitalWrite(SHCP, 1); 66 | digitalWrite(SHCP, 0); 67 | dataIn = dataIn | digitalRead(Q)>>1; 68 | digitalWrite(DO, data & 0b00000010); 69 | digitalWrite(SHCP, 1); 70 | digitalWrite(SHCP, 0); 71 | dataIn = dataIn | digitalRead(Q)>>2; 72 | digitalWrite(DO, data & 0b00000100); 73 | digitalWrite(SHCP, 1); 74 | digitalWrite(SHCP, 0); 75 | dataIn = dataIn | digitalRead(Q)>>3; 76 | digitalWrite(DO, data & 0b00001000); 77 | digitalWrite(SHCP, 1); 78 | digitalWrite(SHCP, 0); 79 | dataIn = dataIn | digitalRead(Q)>>4; 80 | digitalWrite(DO, data & 0b00010000); 81 | digitalWrite(SHCP, 1); 82 | digitalWrite(SHCP, 0); 83 | dataIn = dataIn | digitalRead(Q)>>5; 84 | digitalWrite(DO, data & 0b00100000); 85 | digitalWrite(SHCP, 1); 86 | digitalWrite(SHCP, 0); 87 | dataIn = dataIn | digitalRead(Q)>>6; 88 | digitalWrite(DO, data & 0b01000000); 89 | digitalWrite(SHCP, 1); 90 | digitalWrite(SHCP, 0); 91 | dataIn = dataIn | digitalRead(Q)>>7; 92 | digitalWrite(DO, data & 0b10000000);*/ 93 | dataIn = SPI.transfer(data); 94 | digitalWrite(STCP, HIGH); 95 | Serial.print("spi transfer in: "); 96 | Serial.println (dataIn,HEX); 97 | delay(1000); 98 | } 99 | } 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /esp_595_spi/esp_595_spi.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Example 34.1 - SPI bus demo using a Microchip MCP4162 digital potentiometer [http://bit.ly/iwDmnd] 3 | http://tronixstuff.com/tutorials > chapter 34 | CC by-sa-nc | John Boxall 4 | */ 5 | 6 | #include "SPI.h" // necessary library 7 | int ss=15; // using digital pin 10 for SPI slave select 8 | int del=200; // used for various delays 9 | 10 | void setup() 11 | { 12 | pinMode(ss, OUTPUT); // we use this for SS pin 13 | SPI.begin(); // wake up the SPI bus. 14 | SPI.setBitOrder(MSBFIRST); 15 | // our MCP4162 requires data to be sent MSB (most significant byte) first 16 | } 17 | 18 | void loop() 19 | { 20 | for (int a=0; a<256; a++) 21 | { 22 | digitalWrite(ss, LOW); 23 | SPI.transfer(a); // send value (0~255) 24 | digitalWrite(ss, HIGH); 25 | delay(del); 26 | } 27 | for (int a=255; a>=0; --a) 28 | { 29 | digitalWrite(ss, LOW); 30 | SPI.transfer(a); // send value (0~255) 31 | digitalWrite(ss, HIGH); 32 | delay(del); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /esp_597/esp_597.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Set DS to 0 (output) can be hardwired 3 | Set MR to 1 (output) can be hardwired 4 | Set STCP to 0 (output) needs to be toggled 5 | Set PL to 1 (output) needs to be toggled 6 | Set SHCP to 0 (output) needs to be toggled 7 | 8 | to load data 9 | Set STCP to 1 10 | delay 1us 11 | Set STCP to 0 (load flip flop) 12 | delay 1us 13 | Set PL to 0 14 | delay 1us 15 | Set PL to 1 (parallel load) 16 | 17 | now bit 7 is already available for read 18 | toggle clock SHCP (to 1 and then again to 0) 19 | now bit 6 is available for read 20 | toggle clock SHCP (to 1 and then again to 0) 21 | */ 22 | int MR = 16; 23 | int STCP = 15; 24 | int PL = 2; 25 | int SHCP = 14; 26 | int Q = 12; 27 | 28 | // the setup routine runs once when you press reset: 29 | void setup() { 30 | pinMode(MR, OUTPUT); 31 | pinMode(STCP, OUTPUT); 32 | pinMode(PL, OUTPUT); 33 | pinMode(SHCP, OUTPUT); 34 | pinMode(Q, INPUT); 35 | digitalWrite(MR, 1); 36 | digitalWrite(STCP, 0); 37 | digitalWrite(PL, 1); 38 | digitalWrite(SHCP, 0); 39 | Serial.begin(115200); 40 | } 41 | 42 | // the loop routine runs over and over again forever: 43 | void loop() { 44 | digitalWrite(STCP, 1); 45 | digitalWrite(STCP, 0); 46 | digitalWrite(PL, 0); 47 | digitalWrite(PL, 1); 48 | delayMicroseconds(1); 49 | Serial.print("bit pattern: "); 50 | Serial.print(digitalRead(Q)); 51 | digitalWrite(SHCP, 1); 52 | digitalWrite(SHCP, 0); 53 | Serial.print(digitalRead(Q)); 54 | digitalWrite(SHCP, 1); 55 | digitalWrite(SHCP, 0); 56 | Serial.print(digitalRead(Q)); 57 | digitalWrite(SHCP, 1); 58 | digitalWrite(SHCP, 0); 59 | Serial.print(digitalRead(Q)); 60 | digitalWrite(SHCP, 1); 61 | digitalWrite(SHCP, 0); 62 | Serial.print(digitalRead(Q)); 63 | digitalWrite(SHCP, 1); 64 | digitalWrite(SHCP, 0); 65 | Serial.print(digitalRead(Q)); 66 | digitalWrite(SHCP, 1); 67 | digitalWrite(SHCP, 0); 68 | Serial.print(digitalRead(Q)); 69 | digitalWrite(SHCP, 1); 70 | digitalWrite(SHCP, 0); 71 | Serial.println(digitalRead(Q)); 72 | digitalWrite(MR, 0); 73 | digitalWrite(MR, 1); 74 | } 75 | -------------------------------------------------------------------------------- /esp_597_spi/esp_597_spi.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Set DS to 0 (output) can be hardwired 3 | Set MR to 1 (output) can be hardwired 4 | Set STCP to 0 (output) needs to be toggled 5 | Set PL to 1 (output) needs to be toggled 6 | Set SHCP to 0 (output) needs to be toggled 7 | 8 | to load data 9 | Set STCP to 1 10 | delay 1us 11 | Set STCP to 0 (load flip flop) 12 | delay 1us 13 | Set PL to 0 14 | delay 1us 15 | Set PL to 1 (parallel load) 16 | 17 | now bit 7 is already available for read 18 | toggle clock SHCP (to 1 and then again to 0) 19 | now bit 6 is available for read 20 | toggle clock SHCP (to 1 and then again to 0) 21 | */ 22 | int MR = 16; 23 | int STCP = 15; 24 | int PL = 2; 25 | int SHCP = 14; 26 | int Q = 12; 27 | 28 | #include "SPI.h" 29 | // the setup routine runs once when you press reset: 30 | void setup() { 31 | 32 | SPI.begin(); 33 | SPI.setBitOrder(MSBFIRST); 34 | pinMode(MR, OUTPUT); 35 | pinMode(STCP, OUTPUT); 36 | pinMode(PL, OUTPUT); 37 | pinMode(SHCP, OUTPUT); 38 | pinMode(Q, INPUT); 39 | digitalWrite(MR, 1); 40 | digitalWrite(STCP, 0); 41 | digitalWrite(PL, 1); 42 | digitalWrite(SHCP, 0); 43 | Serial.begin(115200); 44 | } 45 | 46 | // the loop routine runs over and over again forever: 47 | void loop() { 48 | digitalWrite(STCP, 1); 49 | delayMicroseconds(1); 50 | digitalWrite(STCP, 0); 51 | delayMicroseconds(1); 52 | digitalWrite(PL, 0); 53 | delayMicroseconds(1); 54 | digitalWrite(PL, 1); 55 | delayMicroseconds(1); 56 | Serial.print("bit pattern: "); 57 | Serial.println(SPI.transfer(0x01), BIN); 58 | } 59 | -------------------------------------------------------------------------------- /esp_eeprom_test/esp_eeprom_test.ino: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | char ssid[32] = "i3detroit"; 5 | char password[32]; 6 | char mqtt_server[32] = "10.13.0.155"; 7 | char mqtt_topic[50] = "abzmanHome/House/Basement/North/Light/Control"; 8 | 9 | void setup() { 10 | // put your setup code here, to run once: 11 | 12 | Serial.begin(115200); 13 | delay(500); 14 | //saveCredentials(); 15 | loadCredentials(); 16 | } 17 | 18 | void loop() { 19 | // put your main code here, to run repeatedly: 20 | 21 | } 22 | 23 | /** Load WLAN credentials from EEPROM */ 24 | void loadCredentials() { 25 | 26 | EEPROM.begin(512); 27 | EEPROM.get(0, ssid); 28 | EEPROM.get(0+sizeof(ssid), password); 29 | EEPROM.get(0+sizeof(ssid)+sizeof(password), mqtt_server); 30 | EEPROM.get(0+sizeof(ssid)+sizeof(password)+sizeof(mqtt_server), mqtt_topic); 31 | char ok[2+1]; 32 | EEPROM.get(0+sizeof(ssid)+sizeof(password)+sizeof(mqtt_server)+sizeof(mqtt_topic), ok); 33 | EEPROM.end(); 34 | if (String(ok) != String("OK")) { 35 | ssid[0] = 0; 36 | password[0] = 0; 37 | } 38 | Serial.println("Recovered credentials:"); 39 | Serial.println(ssid); 40 | Serial.println(password); 41 | Serial.println(mqtt_server); 42 | Serial.println(mqtt_topic); 43 | 44 | } 45 | 46 | /** Store WLAN credentials to EEPROM */ 47 | void saveCredentials() { 48 | 49 | EEPROM.begin(512); 50 | EEPROM.put(0, ssid); 51 | EEPROM.put(0+sizeof(ssid), password); 52 | EEPROM.put(0+sizeof(ssid)+sizeof(password), mqtt_server); 53 | EEPROM.put(0+sizeof(ssid)+sizeof(password)+sizeof(mqtt_server), mqtt_topic); 54 | char ok[2+1] = "OK"; 55 | EEPROM.put(0+sizeof(ssid)+sizeof(password)+sizeof(mqtt_server)+sizeof(mqtt_topic), ok); 56 | EEPROM.commit(); 57 | EEPROM.end(); 58 | 59 | } 60 | -------------------------------------------------------------------------------- /esp_http_pwm/esp_http_pwm.ino: -------------------------------------------------------------------------------- 1 | #pragma GCC diagnostic ignored "-Wwrite-strings" 2 | 3 | #include 4 | #include 5 | #define led 14 6 | String form = // String form to sent to the client-browser 7 | "

" 8 | "

" 9 | "

simple pwm test

" 10 | "

pwm (10-1023, 0 for off)

" 11 | "
"; 12 | 13 | long period; 14 | #define SSID "i3" // insert your SSID 15 | #define PASS "" // insert your password 16 | 17 | // Instantiate server class // See tab Network for #include 18 | ESP8266WebServer server(80); // HTTP server will listen at port 80 19 | 20 | 21 | void setup(void) 22 | { 23 | //ESP.wdtDisable(); // used to debug, disable wachdog timer, 24 | Serial.begin(115200); // full speed to monitor 25 | WiFi.begin(SSID, PASS); // Connect to WiFi network 26 | pinMode(led, OUTPUT); 27 | analogWrite(led, 0); 28 | analogWriteFreq(20000); 29 | while (WiFi.status() != WL_CONNECTED) { // Wait for connection 30 | delay(500); 31 | Serial.print("."); 32 | } 33 | 34 | // Set up the endpoints for HTTP server, Endpoints can be written as inline functions: 35 | server.on("/", []() 36 | { 37 | server.send(200, "text/html", form); 38 | }); 39 | 40 | server.on("/msg", handle_msg); // And as regular external functions: 41 | server.begin(); // Start the server 42 | 43 | Serial.print("SSID : "); // prints SSID in monitor 44 | Serial.println(SSID); // to monitor 45 | 46 | char result[16]; 47 | sprintf(result, "%3d.%3d.%3d.%3d", WiFi.localIP()[0], WiFi.localIP()[1], WiFi.localIP()[2], WiFi.localIP()[3]); 48 | 49 | Serial.println("WebServer ready: "); 50 | Serial.println(WiFi.localIP()); // Serial monitor prints localIP 51 | Serial.println(); 52 | Serial.println(result); 53 | 54 | } 55 | 56 | void loop(void) { 57 | server.handleClient(); // checks for incoming messages 58 | } 59 | 60 | /* 61 | handles the messages coming from the webbrowser, restores a few special characters and 62 | constructs the strings that can be sent to the oled display 63 | */ 64 | void handle_msg() 65 | { 66 | server.send(200, "text/html", form); // Send same page so they can send another msg 67 | 68 | String msg = server.arg("pwm"); 69 | Serial.println(msg.toInt()); 70 | analogWrite(led, msg.toInt()); 71 | } 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /esp_mqtt_display/esp_mqtt_display.ino: -------------------------------------------------------------------------------- 1 | /* esp_mqtt_display - ESP8266 connected to a 4800bps serial led display (16 digit) 2 | 3 | Based on ESP8266Webserver,mqtt_publish_in_callback (thank you) 4 | 5 | Version 1.0 6/20/2015 Evan Allen 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | //char ssid[] = "abz-fi"; // your network SSID (name) 14 | //char password[] = "we do what we must, because we can"; // your network password 15 | const char* ssid = "i3"; 16 | const char* password = ""; 17 | 18 | // Update these with values suitable for your network. 19 | IPAddress server(10, 13, 0, 136); 20 | 21 | PubSubClient client(server); 22 | 23 | String webString = ""; // String to display 24 | String tempString = ""; // String to temporarily store stuff 25 | 26 | 27 | // Callback function 28 | void callback(const MQTT::Publish& pub) { 29 | 30 | if (pub.topic().equals("displayTopic")) 31 | { 32 | tempString = ""; 33 | tempString += pub.payload_string(); 34 | 35 | if (tempString.length() < 16) 36 | { 37 | webString = ""; 38 | for (int i = 0; i < 16 - tempString.length(); i++) 39 | { 40 | webString += " "; 41 | } 42 | webString += tempString; 43 | } else 44 | { 45 | webString = ""; 46 | webString += tempString; 47 | 48 | } 49 | 50 | Serial1.print(webString); 51 | } 52 | 53 | Serial.print(pub.topic()); 54 | Serial.print(" => "); 55 | Serial.println(pub.payload_string()); 56 | } 57 | 58 | void setup(void) 59 | { 60 | // You can open the Arduino IDE Serial Monitor window to see what the code is doing 61 | Serial.begin(115200); // Serial connection from ESP-01 via 3.3v console cable 62 | Serial1.begin(4800); // Serial connection to display 63 | client.set_callback(callback); 64 | // Connect to WiFi network 65 | WiFi.begin(ssid, password); 66 | Serial.print("\n\r \n\rWorking to connect"); 67 | 68 | // Wait for connection 69 | while (WiFi.status() != WL_CONNECTED) { 70 | delay(500); 71 | Serial.print("."); 72 | } 73 | Serial.println(""); 74 | Serial.println("Esp General Purpose Server"); 75 | Serial.print("Connected to "); 76 | Serial.println(ssid); 77 | Serial.print("IP address: "); 78 | Serial.println(WiFi.localIP()); 79 | Serial1.print("IP ADDR "); 80 | Serial1.print(WiFi.localIP()); 81 | Serial.println(); 82 | 83 | if (client.connect("arduinoClient")) { 84 | client.publish("outTopic", "hello world"); 85 | client.subscribe("displayTopic"); 86 | } 87 | 88 | } 89 | 90 | void loop(void) 91 | { 92 | client.loop(); 93 | } 94 | -------------------------------------------------------------------------------- /esp_mqtt_display_01/esp_mqtt_display_01.ino: -------------------------------------------------------------------------------- 1 | /* esp_mqtt_display_01 - ESP8266 connected to a 4800bps serial led display (16 digit) for the esp-01 (no debug output, using the serial line to talk to the display)zzzz 2 | 3 | Based on ESP8266Webserver,mqtt_publish_in_callback (thank you) 4 | 5 | Version 1.1 9/23/2015 Evan Allen 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | //char ssid[] = "abz-fi"; // your network SSID (name) 14 | //char password[] = "we do what we must, because we can"; // your network password 15 | const char* ssid = "i3"; 16 | const char* password = ""; 17 | 18 | // Update these with values suitable for your network. 19 | IPAddress server(10, 13, 0, 136); 20 | 21 | PubSubClient client(server); 22 | 23 | String webString = ""; // String to display 24 | String tempString = ""; // String to temporarily store stuff 25 | int character = 0; 26 | int d = 500; 27 | char valid[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789- "; 28 | bool isValid = 0; 29 | // Callback function 30 | void callback(const MQTT::Publish& pub) { 31 | if (pub.topic().equals("delayTopic")) 32 | { 33 | char buffer[] = ""; 34 | pub.payload_string().toCharArray(buffer,pub.payload_string().length()+1); 35 | d = atoi(buffer); 36 | } 37 | if (pub.topic().equals("displayTopic")) 38 | { 39 | tempString = ""; 40 | tempString += pub.payload_string(); 41 | 42 | 43 | //check if correct characters 44 | for (int i = 0;i 16) 114 | { 115 | 116 | Serial.print(webString.charAt(character)); 117 | character++; 118 | if (webString.length() < character+1) 119 | { 120 | character = 0; 121 | } 122 | } 123 | delay(d); 124 | } 125 | -------------------------------------------------------------------------------- /esp_mqtt_flow/esp_mqtt_flow.ino: -------------------------------------------------------------------------------- 1 | /* esp_mqtt_flow - ESP8266 mqtt node with 2 flow sensors as inputs 2 | 3 | Based on DHTServer(ESP8266Webserver, DHTexample, and BlinkWithoutDelay), mqtt_publish_in_callback (thank you) 4 | 5 | Version 1.0 9/23/2015 Evan Allen 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | 15 | int flowPin1 = 5; 16 | int flowPin2 = 4; 17 | unsigned long flow1count = 0; 18 | unsigned long flow2count = 0; 19 | 20 | 21 | #define countof(a) (sizeof(a) / sizeof(a[0])) 22 | 23 | //char ssid[] = "abz-fi"; // your network SSID (name) 24 | //char password[] = "we do what we must, because we can"; // your network password 25 | const char* ssid = "i3"; 26 | const char* password = ""; 27 | 28 | 29 | // Update these with values suitable for your network. 30 | IPAddress server(10, 13, 0, 136); 31 | 32 | PubSubClient client(server); 33 | 34 | 35 | String webString = ""; // String to display 36 | 37 | // Callback function 38 | void callback(const MQTT::Publish& pub) { 39 | if(pub.payload_string().equals("flow1")) 40 | { 41 | webString = "Flow 2: " + String(flow1count/450.0) + " L"; // Arduino has a hard time with float to string 42 | client.publish("outTopic",webString); 43 | } else if(pub.payload_string().equals("flow2")) 44 | { 45 | webString = "Flow 2: " + String(flow2count/450.0) + " L"; 46 | client.publish("outTopic",webString); // send to someones browser when asked 47 | 48 | } else 49 | 50 | 51 | 52 | 53 | 54 | 55 | Serial.print("Flow 1 in Liters: "); 56 | Serial.print(flow1count/450.0); 57 | Serial.print("\tFlow 2 in Liters: "); 58 | Serial.print(flow2count/450.0); 59 | Serial.print("\tFlow 1 in pulses: "); 60 | Serial.print(flow1count); 61 | Serial.print("\tFlow 2 in pulse: "); 62 | Serial.println(flow2count); 63 | delay(500); 64 | 65 | 66 | 67 | 68 | { 69 | } 70 | 71 | Serial.print(pub.topic()); 72 | Serial.print(" => "); 73 | Serial.println(pub.payload_string()); 74 | } 75 | 76 | void setup() 77 | { 78 | Serial.begin(115200); 79 | 80 | pinMode(flowPin1, INPUT_PULLUP); 81 | attachInterrupt(flowPin1, flow1, CHANGE); 82 | pinMode(flowPin2, INPUT_PULLUP); 83 | attachInterrupt(flowPin2, flow2, CHANGE); 84 | 85 | 86 | 87 | client.set_callback(callback); 88 | // Connect to WiFi network 89 | WiFi.begin(ssid, password); 90 | Serial.print("\n\r \n\rWorking to connect"); 91 | 92 | // Wait for connection 93 | while (WiFi.status() != WL_CONNECTED) { 94 | delay(500); 95 | Serial.print("."); 96 | } 97 | Serial.println(""); 98 | Serial.println("Esp General Purpose Server"); 99 | Serial.print("Connected to "); 100 | Serial.println(ssid); 101 | Serial.print("IP address: "); 102 | Serial.println(WiFi.localIP()); 103 | 104 | 105 | 106 | if (client.connect("arduinoClient")) { 107 | client.publish("outTopic","flow boot up"); 108 | client.subscribe("inTopic"); 109 | } 110 | 111 | 112 | 113 | 114 | } 115 | 116 | void loop() 117 | { 118 | client.loop(); 119 | } 120 | 121 | void flow1() 122 | { 123 | flow1count +=1; 124 | } 125 | 126 | void flow2() 127 | { 128 | flow2count +=1; 129 | } 130 | -------------------------------------------------------------------------------- /esp_mqtt_relay/esp_mqtt_relay.ino: -------------------------------------------------------------------------------- 1 | /* esp_mqtt_relay - ESP8266 mqtt node with a bistable relay 2 | 3 | Based on mqtt_publish_in_callback (thank you) 4 | 5 | Version 1.0 9/23/2015 Evan Allen 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | #define ONPIN 14 15 | #define OFFPIN 12 16 | #define countof(a) (sizeof(a) / sizeof(a[0])) 17 | boolean relayState = 0; 18 | 19 | const char* ssid = "i3"; 20 | const char* password = ""; 21 | 22 | String webString = ""; // String to display 23 | 24 | // Update these with values suitable for your network. 25 | IPAddress server(10, 13, 0, 136); 26 | 27 | PubSubClient client(server); 28 | 29 | 30 | // Callback function 31 | void callback(const MQTT::Publish& pub) { 32 | if (pub.payload_string().equals("relay on")) 33 | { 34 | if (relayState) { 35 | webString = "The Relay is already on"; 36 | } else { 37 | digitalWrite(ONPIN, 1); 38 | delay(5); 39 | digitalWrite(ONPIN, 0); 40 | relayState = 1; 41 | webString = "The Relay has been turned on"; 42 | } 43 | client.publish("outTopic", webString); // send to someones browser when asked 44 | 45 | 46 | } else if (pub.payload_string().equals("relay off")) 47 | { 48 | if (relayState) { 49 | digitalWrite(OFFPIN, 1); 50 | delay(5); 51 | digitalWrite(OFFPIN, 0); 52 | relayState = 0; 53 | webString = "The Relay has been turned off"; 54 | } else { 55 | webString = "Relay is already off"; 56 | } 57 | client.publish("outTopic", webString); // send to someones browser when asked 58 | 59 | 60 | } else if (pub.payload_string().equals("relay state")) 61 | { 62 | if (relayState) { 63 | webString = "Relay is on"; 64 | } else { 65 | webString = "Relay is off"; 66 | } 67 | client.publish("outTopic", webString); // send to someones browser when asked 68 | 69 | 70 | } 71 | Serial.print(pub.topic()); 72 | Serial.print(" => "); 73 | Serial.println(pub.payload_string()); 74 | } 75 | void setup(void) 76 | { 77 | // You can open the Arduino IDE Serial Monitor window to see what the code is doing 78 | Serial.begin(115200); // Serial connection from ESP-01 via 3.3v console cable 79 | pinMode(ONPIN, OUTPUT); 80 | digitalWrite(ONPIN, 0); 81 | pinMode(OFFPIN, OUTPUT); 82 | digitalWrite(OFFPIN, 0); 83 | 84 | client.set_callback(callback); 85 | // Connect to WiFi network 86 | WiFi.begin(ssid, password); 87 | Serial.print("\n\r \n\rWorking to connect"); 88 | 89 | // Wait for connection 90 | while (WiFi.status() != WL_CONNECTED) { 91 | delay(500); 92 | Serial.print("."); 93 | } 94 | Serial.println(""); 95 | Serial.println("Esp General Purpose Server"); 96 | Serial.print("Connected to "); 97 | Serial.println(ssid); 98 | Serial.print("IP address: "); 99 | Serial.println(WiFi.localIP()); 100 | 101 | if (client.connect("arduinoClient")) { 102 | client.publish("outTopic", "relay boot up"); 103 | client.subscribe("inTopic"); 104 | } 105 | 106 | } 107 | 108 | void loop(void) 109 | { 110 | 111 | client.loop(); 112 | 113 | //send things periodically 114 | 115 | } 116 | -------------------------------------------------------------------------------- /libraries/Bounce2/.gitignore: -------------------------------------------------------------------------------- 1 | *.db -------------------------------------------------------------------------------- /libraries/Bounce2/Bounce1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abzman/esp-stuff/93f390c95d2fb8b4b88caee80a7901eb904328de/libraries/Bounce2/Bounce1.zip -------------------------------------------------------------------------------- /libraries/Bounce2/Bounce2.h: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2013 thomasfredericks 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * 25 | Main code by Thomas O Fredericks (tof@t-o-f.info) 26 | Previous contributions by Eric Lowry, Jim Schimpf and Tom Harkaway 27 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 28 | 29 | #ifndef Bounce2_h 30 | #define Bounce2_h 31 | 32 | // Uncomment the following line for "LOCK-OUT" debounce method 33 | //#define BOUNCE_LOCK_OUT 34 | 35 | // Uncomment the following line for "BOUNCE_WITH_PROMPT_DETECTION" debounce method 36 | //#define BOUNCE_WITH_PROMPT_DETECTION 37 | 38 | #include 39 | 40 | #ifndef _BV 41 | #define _BV(n) (1<<(n)) 42 | #endif 43 | 44 | class Bounce 45 | { 46 | public: 47 | // Create an instance of the bounce library 48 | Bounce(); 49 | 50 | // Attach to a pin (and also sets initial state) 51 | void attach(int pin); 52 | 53 | // Attach to a pin (and also sets initial state) and sets pin to mode (INPUT/INPUT_PULLUP/OUTPUT) 54 | void attach(int pin, int mode); 55 | 56 | // Sets the debounce interval 57 | void interval(uint16_t interval_millis); 58 | 59 | // Updates the pin 60 | // Returns 1 if the state changed 61 | // Returns 0 if the state did not change 62 | bool update(); 63 | 64 | // Returns the updated pin state 65 | bool read(); 66 | 67 | // Returns the falling pin state 68 | bool fell(); 69 | 70 | // Returns the rising pin state 71 | bool rose(); 72 | 73 | // Partial compatibility for programs written with Bounce version 1 74 | bool risingEdge() { return rose(); } 75 | bool fallingEdge() { return fell(); } 76 | Bounce(uint8_t pin, unsigned long interval_millis ) : Bounce() { 77 | attach(pin); 78 | interval(interval_millis); 79 | } 80 | 81 | protected: 82 | unsigned long previous_millis; 83 | uint16_t interval_millis; 84 | uint8_t state; 85 | uint8_t pin; 86 | }; 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /libraries/Bounce2/BouncySwitch_lockout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abzman/esp-stuff/93f390c95d2fb8b4b88caee80a7901eb904328de/libraries/Bounce2/BouncySwitch_lockout.png -------------------------------------------------------------------------------- /libraries/Bounce2/BouncySwitch_stable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abzman/esp-stuff/93f390c95d2fb8b4b88caee80a7901eb904328de/libraries/Bounce2/BouncySwitch_stable.png -------------------------------------------------------------------------------- /libraries/Bounce2/INSTALL.txt: -------------------------------------------------------------------------------- 1 | Put the "Bounce2" folder in your Arduino or Wiring "libraries" folder. 2 | -------------------------------------------------------------------------------- /libraries/Bounce2/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 thomasfredericks 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /libraries/Bounce2/README.md: -------------------------------------------------------------------------------- 1 | BOUNCE 2 2 | ===================== 3 | 4 | Debouncing library for Arduino or Wiring 5 | 6 | by Thomas Ouellet Fredericks 7 | 8 | with contributions from: 9 | 10 | Eric Lowry, Jim Schimpf and Tom Harkaway 11 | 12 | 13 | HAVE A QUESTION? 14 | ===================== 15 | Please post your questions here : 16 | http://forum.arduino.cc/index.php?topic=266132.0 17 | 18 | DOWNLOAD 19 | ===================== 20 | 21 | Download the latest version (version 2) here : 22 | 23 | https://github.com/thomasfredericks/Bounce2/archive/master.zip 24 | 25 | 26 | DOCUMENTATION 27 | ===================== 28 | 29 | The latest version (version 2) documentation can be found here : 30 | 31 | https://github.com/thomasfredericks/Bounce2/wiki 32 | 33 | 34 | ABOUT BOUNCE 1 (ORIGINAL VERSION) 35 | ===================== 36 | 37 | The original version of Bounce (Bounce 1) is included but not supported anymore. 38 | -------------------------------------------------------------------------------- /libraries/Bounce2/examples/bounce/bounce.ino: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | DESCRIPTION 4 | ==================== 5 | Simple example of the Bounce library that switches the debug LED when a button is pressed. 6 | */ 7 | // Include the Bounce2 library found here : 8 | // https://github.com/thomasfredericks/Bounce-Arduino-Wiring 9 | #include 10 | 11 | #define BUTTON_PIN 2 12 | #define LED_PIN 13 13 | 14 | // Instantiate a Bounce object 15 | Bounce debouncer = Bounce(); 16 | 17 | void setup() { 18 | 19 | // Setup the button with an internal pull-up : 20 | pinMode(BUTTON_PIN,INPUT_PULLUP); 21 | 22 | // After setting up the button, setup the Bounce instance : 23 | debouncer.attach(BUTTON_PIN); 24 | debouncer.interval(5); // interval in ms 25 | 26 | //Setup the LED : 27 | pinMode(LED_PIN,OUTPUT); 28 | 29 | } 30 | 31 | void loop() { 32 | // Update the Bounce instance : 33 | debouncer.update(); 34 | 35 | // Get the updated value : 36 | int value = debouncer.read(); 37 | 38 | // Turn on or off the LED as determined by the state : 39 | if ( value == LOW ) { 40 | digitalWrite(LED_PIN, HIGH ); 41 | } 42 | else { 43 | digitalWrite(LED_PIN, LOW ); 44 | } 45 | 46 | } 47 | 48 | 49 | -------------------------------------------------------------------------------- /libraries/Bounce2/examples/bounce2buttons/bounce2buttons.ino: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | DESCRIPTION 4 | ==================== 5 | Simple example of the Bounce library that switches the debug LED when 6 | either of 2 buttons are pressed. 7 | */ 8 | 9 | // Include the Bounce2 library found here : 10 | // https://github.com/thomasfredericks/Bounce2 11 | #include 12 | 13 | #define BUTTON_PIN_1 2 14 | #define BUTTON_PIN_2 3 15 | 16 | 17 | #define LED_PIN 13 18 | 19 | // Instantiate a Bounce object 20 | Bounce debouncer1 = Bounce(); 21 | 22 | // Instantiate another Bounce object 23 | Bounce debouncer2 = Bounce(); 24 | 25 | void setup() { 26 | 27 | // Setup the first button with an internal pull-up : 28 | pinMode(BUTTON_PIN_1,INPUT_PULLUP); 29 | // After setting up the button, setup the Bounce instance : 30 | debouncer1.attach(BUTTON_PIN_1); 31 | debouncer1.interval(5); // interval in ms 32 | 33 | // Setup the second button with an internal pull-up : 34 | pinMode(BUTTON_PIN_2,INPUT_PULLUP); 35 | // After setting up the button, setup the Bounce instance : 36 | debouncer2.attach(BUTTON_PIN_2); 37 | debouncer2.interval(5); // interval in ms 38 | 39 | 40 | //Setup the LED : 41 | pinMode(LED_PIN,OUTPUT); 42 | 43 | } 44 | 45 | void loop() { 46 | // Update the Bounce instances : 47 | debouncer1.update(); 48 | debouncer2.update(); 49 | 50 | // Get the updated value : 51 | int value1 = debouncer1.read(); 52 | int value2 = debouncer2.read(); 53 | 54 | // Turn on the LED if either button is pressed : 55 | if ( value1 == LOW || value2 == LOW ) { 56 | digitalWrite(LED_PIN, HIGH ); 57 | } 58 | else { 59 | digitalWrite(LED_PIN, LOW ); 60 | } 61 | 62 | } 63 | 64 | 65 | -------------------------------------------------------------------------------- /libraries/Bounce2/examples/change/change.ino: -------------------------------------------------------------------------------- 1 | 2 | // Detect the falling edge 3 | 4 | // Include the Bounce2 library found here : 5 | // https://github.com/thomasfredericks/Bounce-Arduino-Wiring 6 | #include 7 | 8 | 9 | #define BUTTON_PIN 2 10 | #define LED_PIN 13 11 | 12 | int ledState = LOW; 13 | 14 | 15 | // Instantiate a Bounce object : 16 | Bounce debouncer = Bounce(); 17 | 18 | void setup() { 19 | 20 | // Setup the button with an internal pull-up : 21 | pinMode(BUTTON_PIN,INPUT_PULLUP); 22 | 23 | // After setting up the button, setup the Bounce instance : 24 | debouncer.attach(BUTTON_PIN); 25 | debouncer.interval(500); 26 | 27 | // Setup the LED : 28 | pinMode(LED_PIN,OUTPUT); 29 | digitalWrite(LED_PIN,ledState); 30 | 31 | 32 | } 33 | 34 | void loop() { 35 | 36 | // Update the Bounce instance : 37 | debouncer.update(); 38 | 39 | // Call code if Bounce fell (transition from HIGH to LOW) : 40 | if ( debouncer.fell() ) { 41 | 42 | // Toggle LED state : 43 | ledState = !ledState; 44 | digitalWrite(LED_PIN,ledState); 45 | 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /libraries/Bounce2/examples/circuit-bounce-change-duration-retrigger.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abzman/esp-stuff/93f390c95d2fb8b4b88caee80a7901eb904328de/libraries/Bounce2/examples/circuit-bounce-change-duration-retrigger.png -------------------------------------------------------------------------------- /libraries/Bounce2/examples/duration/duration.ino: -------------------------------------------------------------------------------- 1 | /* 2 | DESCRIPTION 3 | ==================== 4 | Reports through serial (57600 baud) the time since 5 | a button press (transition from HIGH to LOW). 6 | 7 | */ 8 | 9 | // Include the Bounce2 library found here : 10 | // https://github.com/thomasfredericks/Bounce-Arduino-Wiring 11 | #include 12 | 13 | 14 | #define BUTTON_PIN 2 15 | #define LED_PIN 13 16 | 17 | // Instantiate a Bounce object : 18 | Bounce debouncer = Bounce(); 19 | 20 | unsigned long buttonPressTimeStamp; 21 | 22 | void setup() { 23 | 24 | Serial.begin(57600); 25 | 26 | // Setup the button with an internal pull-up : 27 | pinMode(BUTTON_PIN,INPUT_PULLUP); 28 | 29 | // After setting up the button, setup the Bounce instance : 30 | debouncer.attach(BUTTON_PIN); 31 | debouncer.interval(5); 32 | 33 | // Setup the LED : 34 | pinMode(LED_PIN,OUTPUT); 35 | 36 | } 37 | 38 | void loop() { 39 | 40 | // Update the Bounce instance : 41 | debouncer.update(); 42 | 43 | // Call code if Bounce fell (transition from HIGH to LOW) : 44 | if ( debouncer.fell() ) {; 45 | 46 | Serial.println( millis()-buttonPressTimeStamp ); 47 | buttonPressTimeStamp = millis(); 48 | 49 | } 50 | 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /libraries/Bounce2/examples/retrigger/retrigger.ino: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | DESCRIPTION 4 | ==================== 5 | Example of the bounce library that shows how to retrigger an event when a button is held down. 6 | In this case, the debug LED will blink every 500 ms as long as the button is held down. 7 | Open the Serial Monitor (57600 baud) for debug messages. 8 | 9 | */ 10 | 11 | // Include the Bounce2 library found here : 12 | // https://github.com/thomasfredericks/Bounce-Arduino-Wiring 13 | #include 14 | 15 | 16 | #define BUTTON_PIN 2 17 | #define LED_PIN 13 18 | 19 | // Instantiate a Bounce object 20 | Bounce debouncer = Bounce(); 21 | 22 | int buttonState; 23 | unsigned long buttonPressTimeStamp; 24 | 25 | int ledState; 26 | 27 | void setup() { 28 | 29 | Serial.begin(57600); 30 | 31 | // Setup the button 32 | pinMode(BUTTON_PIN,INPUT); 33 | // Activate internal pull-up 34 | digitalWrite(BUTTON_PIN,HIGH); 35 | 36 | // After setting up the button, setup debouncer 37 | debouncer.attach(BUTTON_PIN); 38 | debouncer.interval(5); 39 | 40 | //Setup the LED 41 | pinMode(LED_PIN,OUTPUT); 42 | digitalWrite(LED_PIN,ledState); 43 | 44 | } 45 | 46 | void loop() { 47 | // Update the debouncer and get the changed state 48 | boolean changed = debouncer.update(); 49 | 50 | 51 | 52 | if ( changed ) { 53 | // Get the update value 54 | int value = debouncer.read(); 55 | if ( value == HIGH) { 56 | ledState = LOW; 57 | digitalWrite(LED_PIN, ledState ); 58 | 59 | buttonState = 0; 60 | Serial.println("Button released (state 0)"); 61 | 62 | } else { 63 | ledState = HIGH; 64 | digitalWrite(LED_PIN, ledState ); 65 | 66 | buttonState = 1; 67 | Serial.println("Button pressed (state 1)"); 68 | buttonPressTimeStamp = millis(); 69 | 70 | } 71 | } 72 | 73 | if ( buttonState == 1 ) { 74 | if ( millis() - buttonPressTimeStamp >= 500 ) { 75 | buttonPressTimeStamp = millis(); 76 | if ( ledState == HIGH ) ledState = LOW; 77 | else if ( ledState == LOW ) ledState = HIGH; 78 | digitalWrite(LED_PIN, ledState ); 79 | Serial.println("Retriggering button"); 80 | } 81 | } 82 | 83 | 84 | } 85 | 86 | 87 | -------------------------------------------------------------------------------- /libraries/Bounce2/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Bounce2 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | Bounce KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | update KEYWORD2 16 | interval KEYWORD2 17 | read KEYWORD2 18 | attach KEYWORD2 19 | rose KEYWORD2 20 | fell KEYWORD2 21 | 22 | ####################################### 23 | # Instances (KEYWORD2) 24 | ####################################### 25 | 26 | ####################################### 27 | # Constants (LITERAL1) 28 | ####################################### 29 | 30 | -------------------------------------------------------------------------------- /libraries/Bounce2/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Bounce2", 3 | "keywords": "bounce, signal, input, ouput", 4 | "description": "Debouncing library for Arduino or Wiring", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/thomasfredericks/Bounce2.git" 8 | }, 9 | "version": "2.1", 10 | "exclude": [ 11 | "*.png", 12 | "*.zip" 13 | ], 14 | "frameworks": "arduino", 15 | "platforms": "*" 16 | } 17 | -------------------------------------------------------------------------------- /libraries/Bounce2/library.properties: -------------------------------------------------------------------------------- 1 | name=Bounce2 2 | version=2.21 3 | author=Thomas O Fredericks with contributions fromEric Lowry, Jim Schimpf and Tom Harkaway 4 | maintainer=Thomas O Fredericks 5 | sentence=Debouncing library for Arduino and Wiring. 6 | paragraph=Deboucing switches and toggles is important. 7 | category=Signal Input/Output 8 | url=https://github.com/thomasfredericks/Bounce2 9 | architectures=* -------------------------------------------------------------------------------- /libraries/DHT/DHT.h: -------------------------------------------------------------------------------- 1 | #ifndef DHT_H 2 | #define DHT_H 3 | #if ARDUINO >= 100 4 | #include "Arduino.h" 5 | #else 6 | #include "WProgram.h" 7 | #endif 8 | 9 | /* DHT library 10 | 11 | MIT license 12 | written by Adafruit Industries 13 | */ 14 | 15 | // how many timing transitions we need to keep track of. 2 * number bits + extra 16 | #define MAXTIMINGS 85 17 | 18 | #define DHT11 11 19 | #define DHT22 22 20 | #define DHT21 21 21 | #define AM2301 21 22 | 23 | class DHT { 24 | private: 25 | uint8_t data[6]; 26 | uint8_t _pin, _type, _count; 27 | unsigned long _lastreadtime; 28 | boolean firstreading; 29 | 30 | public: 31 | DHT(uint8_t pin, uint8_t type, uint8_t count=6); 32 | void begin(void); 33 | float readTemperature(bool S=false); 34 | float convertCtoF(float); 35 | float convertFtoC(float); 36 | float computeHeatIndex(float tempFahrenheit, float percentHumidity); 37 | float readHumidity(void); 38 | boolean read(void); 39 | 40 | }; 41 | #endif 42 | -------------------------------------------------------------------------------- /libraries/DHT/README.txt: -------------------------------------------------------------------------------- 1 | This is an Arduino library for the DHT series of low cost temperature/humidity sensors. 2 | 3 | To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder DHT. Check that the DHT folder contains DHT.cpp and DHT.h. Place the DHT library folder your /libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. -------------------------------------------------------------------------------- /libraries/DHT/examples/DHTtester/DHTtester.ino: -------------------------------------------------------------------------------- 1 | // Example testing sketch for various DHT humidity/temperature sensors 2 | // Written by ladyada, public domain 3 | 4 | #include "DHT.h" 5 | 6 | #define DHTPIN 2 // what pin we're connected to 7 | 8 | // Uncomment whatever type you're using! 9 | //#define DHTTYPE DHT11 // DHT 11 10 | #define DHTTYPE DHT22 // DHT 22 (AM2302) 11 | //#define DHTTYPE DHT21 // DHT 21 (AM2301) 12 | 13 | // Connect pin 1 (on the left) of the sensor to +5V 14 | // NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1 15 | // to 3.3V instead of 5V! 16 | // Connect pin 2 of the sensor to whatever your DHTPIN is 17 | // Connect pin 4 (on the right) of the sensor to GROUND 18 | // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor 19 | 20 | // Initialize DHT sensor for normal 16mhz Arduino 21 | DHT dht(DHTPIN, DHTTYPE); 22 | // NOTE: For working with a faster chip, like an Arduino Due or Teensy, you 23 | // might need to increase the threshold for cycle counts considered a 1 or 0. 24 | // You can do this by passing a 3rd parameter for this threshold. It's a bit 25 | // of fiddling to find the right value, but in general the faster the CPU the 26 | // higher the value. The default for a 16mhz AVR is a value of 6. For an 27 | // Arduino Due that runs at 84mhz a value of 30 works. 28 | // Example to initialize DHT sensor for Arduino Due: 29 | //DHT dht(DHTPIN, DHTTYPE, 30); 30 | 31 | void setup() { 32 | Serial.begin(9600); 33 | Serial.println("DHTxx test!"); 34 | 35 | dht.begin(); 36 | } 37 | 38 | void loop() { 39 | // Wait a few seconds between measurements. 40 | delay(2000); 41 | 42 | // Reading temperature or humidity takes about 250 milliseconds! 43 | // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) 44 | float h = dht.readHumidity(); 45 | // Read temperature as Celsius 46 | float t = dht.readTemperature(); 47 | // Read temperature as Fahrenheit 48 | float f = dht.readTemperature(true); 49 | 50 | // Check if any reads failed and exit early (to try again). 51 | if (isnan(h) || isnan(t) || isnan(f)) { 52 | Serial.println("Failed to read from DHT sensor!"); 53 | return; 54 | } 55 | 56 | // Compute heat index 57 | // Must send in temp in Fahrenheit! 58 | float hi = dht.computeHeatIndex(f, h); 59 | 60 | Serial.print("Humidity: "); 61 | Serial.print(h); 62 | Serial.print(" %\t"); 63 | Serial.print("Temperature: "); 64 | Serial.print(t); 65 | Serial.print(" *C "); 66 | Serial.print(f); 67 | Serial.print(" *F\t"); 68 | Serial.print("Heat index: "); 69 | Serial.print(hi); 70 | Serial.println(" *F"); 71 | } 72 | -------------------------------------------------------------------------------- /libraries/DHT/library.properties: -------------------------------------------------------------------------------- 1 | name=DHT sensor library 2 | version=1.0.0 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=Arduino library for DHT11, DHT22, etc Temp & Humidity Sensors 6 | paragraph=Arduino library for DHT11, DHT22, etc Temp & Humidity Sensors 7 | category=Sensors 8 | url=https://github.com/adafruit/DHT-sensor-library 9 | architectures=* 10 | -------------------------------------------------------------------------------- /libraries/IRremoteESP8266/Contributors.md: -------------------------------------------------------------------------------- 1 | ## Contributors of this project 2 | - [Mark Szabo](https://github.com/markszabo/) : IR sending on ESP8266 3 | - [Sébastien Warin](https://github.com/sebastienwarin/) (http://sebastien.warin.fr) : IR receiving on ESP8266 4 | 5 | ## Contributors of the original project (https://github.com/shirriff/Arduino-IRremote/) 6 | These are the active contributors of this project that you may contact if there is anything you need help with or if you have suggestions. 7 | 8 | - [z3t0](https://github.com/z3t0) : Active Contributor and currently also the main contributor. 9 | * Email: zetoslab@gmail.com 10 | * Skype: polarised16 11 | - [shirriff](https://github.com/shirriff) : Owner of repository and creator of library. 12 | - [Informatic](https://github.com/Informatic) : Active contributor 13 | - [fmeschia](https://github.com/fmeschia) : Active contributor 14 | - [PaulStoffregen](https://github.com/paulstroffregen) : Active contributor 15 | - [crash7](https://github.com/crash7) : Active contributor 16 | - [Neco777](https://github.com/neco777) : Active contributor 17 | 18 | Note: This list is being updated constantly so please let [z3t0](https://github.com/z3t0) know if you have been missed. 19 | 20 | 21 | -------------------------------------------------------------------------------- /libraries/IRremoteESP8266/README.md: -------------------------------------------------------------------------------- 1 | # IRremote ESP8266 Library 2 | 3 | This library enables you to **send and receive** infra-red signals on an ESP8266 using Arduino framework (https://github.com/esp8266/Arduino) 4 | 5 | This library is based on Ken Shirriff's work (https://github.com/shirriff/Arduino-IRremote/) 6 | 7 | [Mark Szabo](https://github.com/markszabo/IRremoteESP8266) has updated the IRsend class to work on ESP8266 and [Sebastien Warin](https://github.com/sebastienwarin/IRremoteESP8266) the receiving & decoding part (IRrecv class). 8 | 9 | Seb's notes : I also changed the pulse parameters for Samsung, update the Panasonic and Samsung decoders and remove the SANYO decoders. The IR decoder was successfully tested with Panasonic and Samsung remote controls. 10 | 11 | ## Installation 12 | 1. Click "Download ZIP" 13 | 2. Extract the downloaded zip file 14 | 3. Rename the extracted folder to "IRremoteESP8266" 15 | 4. Move this folder to your libraries directory (under windows: C:\Users\YOURNAME\Documents\Arduino\libraries\) 16 | 5. Restart your Arduino ide 17 | 6. Check out the examples 18 | 19 | ## Contributing 20 | If you want to contribute to this project: 21 | - Report bugs and errors 22 | - Ask for enhancements 23 | - Create issues and pull requests 24 | - Tell other people about this library 25 | 26 | ## Contributors 27 | Check [here](Contributors.md) 28 | -------------------------------------------------------------------------------- /libraries/IRremoteESP8266/examples/IRGCSendDemo/IRGCSendDemo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * IRremoteESP8266: IRsendGCDemo - demonstrates sending Global Cache-formatted IR codes with IRsend 3 | * An IR LED must be connected to ESP8266 pin 0. 4 | * Version 0.1 30 March, 2016 5 | * Based on Ken Shirriff's IrsendDemo Version 0.1 July, 2009, Copyright 2009 Ken Shirriff, http://arcfn.com 6 | */ 7 | 8 | #include 9 | 10 | // Codes are in Global Cache format less the emitter ID and request ID. These codes can be found in GC's Control Tower database. 11 | 12 | unsigned int Samsung_power_toggle[71] = {38000,1,1,170,170,20,63,20,63,20,63,20,20,20,20,20,20,20,20,20,20,20,63,20,63,20,63,20,20,20,20,20,20,20,20,20,20,20,20,20,63,20,20,20,20,20,20,20,20,20,20,20,20,20,63,20,20,20,63,20,63,20,63,20,63,20,63,20,63,20,1798}; 13 | 14 | IRsend irsend(4); //an IR emitter led is connected to GPIO pin 4 15 | 16 | void setup() 17 | { 18 | irsend.begin(); 19 | Serial.begin(115200); 20 | } 21 | 22 | void loop() { 23 | Serial.println("Toggling power"); 24 | irsend.sendGC(Samsung_power_toggle, 71); 25 | delay(10000); 26 | } -------------------------------------------------------------------------------- /libraries/IRremoteESP8266/examples/IRGCTCPServer/IRGCTCPServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * IRremoteESP8266: IRGCTCPServer - send Global Cache-formatted codes via TCP. 3 | * An IR emitter must be connected to GPIO pin 4. 4 | * Version 0.1 1 April, 2016 5 | * Hisham Khalifa, http://www.hishamkhalifa.com 6 | * 7 | * Example command - Samsung TV power toggle: 38000,1,1,170,170,20,63,20,63,20,63,20,20,20,20,20,20,20,20,20,20,20,63,20,63,20,63,20,20,20,20,20,20,20,20,20,20,20,20,20,63,20,20,20,20,20,20,20,20,20,20,20,20,20,63,20,20,20,63,20,63,20,63,20,63,20,63,20,63,20,1798\r\n 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | const char* ssid = "..."; 18 | const char* password = "..."; 19 | 20 | WiFiServer server(4998); // Uses port 4998. 21 | WiFiClient client; 22 | 23 | unsigned int *codeArray; 24 | IRsend irsend(4); //an IR emitter led is connected to GPIO pin 4 25 | 26 | void parseString(String str) { 27 | int nextIndex; 28 | int codeLength = 1; 29 | int currentIndex = 0; 30 | nextIndex = str.indexOf(','); 31 | 32 | // change to do/until and remove superfluous repetition below... 33 | while (nextIndex != -1) { 34 | if (codeLength > 1) { 35 | codeArray = (unsigned int*) realloc(codeArray, codeLength * sizeof(unsigned int)); 36 | } else { 37 | codeArray = (unsigned int*) malloc(codeLength * sizeof(unsigned int)); 38 | } 39 | 40 | codeArray[codeLength-1] = (unsigned int) (str.substring(currentIndex, nextIndex).toInt()); 41 | 42 | codeLength++; 43 | currentIndex = nextIndex + 1; 44 | nextIndex = str.indexOf(',', currentIndex); 45 | } 46 | codeArray = (unsigned int*) realloc(codeArray, codeLength * sizeof(unsigned int)); 47 | codeArray[codeLength-1] = (unsigned int) (str.substring(currentIndex, nextIndex).toInt()); 48 | 49 | irsend.sendGC(codeArray,codeLength); 50 | } 51 | 52 | void setup() { 53 | // initialize serial: 54 | Serial.begin(115200); 55 | Serial.println(" "); 56 | Serial.println("IR TCP Server"); 57 | 58 | while (WiFi.status() != WL_CONNECTED) { 59 | delay(900); 60 | Serial.print("."); 61 | } 62 | 63 | server.begin(); 64 | IPAddress myAddress = WiFi.localIP(); 65 | Serial.println(myAddress); 66 | irsend.begin(); 67 | } 68 | 69 | void loop() { 70 | while(!client) { 71 | client = server.available(); 72 | } 73 | 74 | while(!client.connected()){ 75 | delay(900); 76 | client = server.available(); 77 | } 78 | 79 | if(client.available()){ 80 | String irCode = client.readStringUntil('\r'); // Exclusive of \r 81 | client.readStringUntil('\n'); // Skip new line as well 82 | client.flush(); 83 | parseString(irCode); 84 | } 85 | } -------------------------------------------------------------------------------- /libraries/IRremoteESP8266/examples/IRServer/IRServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * IRremoteESP8266: IRServer - demonstrates sending IR codes controlled from a webserver 3 | * An IR LED must be connected to ESP8266 pin 0. 4 | * Version 0.1 June, 2015 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | const char* ssid = "....."; 14 | const char* password = "....."; 15 | MDNSResponder mdns; 16 | 17 | ESP8266WebServer server(80); 18 | 19 | IRsend irsend(0); 20 | 21 | void handleRoot() { 22 | server.send(200, "text/html", " ESP8266 Demo

Hello from ESP8266, you can send NEC encoded IR signals from here!

Send 0xFFE01F

Send 0xFAB123

Send 0xFFE896

"); 23 | } 24 | 25 | void handleIr(){ 26 | for (uint8_t i=0; i 9 | 10 | int RECV_PIN = 2; //an IR detector/demodulatord is connected to GPIO pin 2 11 | 12 | IRrecv irrecv(RECV_PIN); 13 | 14 | decode_results results; 15 | 16 | void setup() 17 | { 18 | Serial.begin(9600); 19 | irrecv.enableIRIn(); // Start the receiver 20 | } 21 | 22 | void loop() { 23 | if (irrecv.decode(&results)) { 24 | Serial.println(results.value, HEX); 25 | irrecv.resume(); // Receive the next value 26 | } 27 | delay(100); 28 | } 29 | -------------------------------------------------------------------------------- /libraries/IRremoteESP8266/examples/IRrecvDump/IRrecvDump.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * IRremoteESP8266: IRrecvDump - dump details of IR codes with IRrecv 3 | * An IR detector/demodulator must be connected to the input RECV_PIN. 4 | * Version 0.1 Sept, 2015 5 | * Based on Ken Shirriff's IrsendDemo Version 0.1 July, 2009, Copyright 2009 Ken Shirriff, http://arcfn.com 6 | * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post) 7 | * LG added by Darryl Smith (based on the JVC protocol) 8 | */ 9 | 10 | #include 11 | 12 | int RECV_PIN = 2; //an IR detector/demodulatord is connected to GPIO pin 2 13 | 14 | IRrecv irrecv(RECV_PIN); 15 | 16 | decode_results results; 17 | 18 | void setup() 19 | { 20 | Serial.begin(9600); 21 | irrecv.enableIRIn(); // Start the receiver 22 | } 23 | 24 | 25 | void dump(decode_results *results) { 26 | // Dumps out the decode_results structure. 27 | // Call this after IRrecv::decode() 28 | int count = results->rawlen; 29 | if (results->decode_type == UNKNOWN) { 30 | Serial.print("Unknown encoding: "); 31 | } 32 | else if (results->decode_type == NEC) { 33 | Serial.print("Decoded NEC: "); 34 | 35 | } 36 | else if (results->decode_type == SONY) { 37 | Serial.print("Decoded SONY: "); 38 | } 39 | else if (results->decode_type == RC5) { 40 | Serial.print("Decoded RC5: "); 41 | } 42 | else if (results->decode_type == RC6) { 43 | Serial.print("Decoded RC6: "); 44 | } 45 | else if (results->decode_type == PANASONIC) { 46 | Serial.print("Decoded PANASONIC - Address: "); 47 | Serial.print(results->panasonicAddress, HEX); 48 | Serial.print(" Value: "); 49 | } 50 | else if (results->decode_type == LG) { 51 | Serial.print("Decoded LG: "); 52 | } 53 | else if (results->decode_type == JVC) { 54 | Serial.print("Decoded JVC: "); 55 | } 56 | else if (results->decode_type == AIWA_RC_T501) { 57 | Serial.print("Decoded AIWA RC T501: "); 58 | } 59 | else if (results->decode_type == WHYNTER) { 60 | Serial.print("Decoded Whynter: "); 61 | } 62 | Serial.print(results->value, HEX); 63 | Serial.print(" ("); 64 | Serial.print(results->bits, DEC); 65 | Serial.println(" bits)"); 66 | Serial.print("Raw ("); 67 | Serial.print(count, DEC); 68 | Serial.print("): "); 69 | 70 | for (int i = 1; i < count; i++) { 71 | if (i & 1) { 72 | Serial.print(results->rawbuf[i]*USECPERTICK, DEC); 73 | } 74 | else { 75 | Serial.write('-'); 76 | Serial.print((unsigned long) results->rawbuf[i]*USECPERTICK, DEC); 77 | } 78 | Serial.print(" "); 79 | } 80 | Serial.println(); 81 | } 82 | 83 | void loop() { 84 | if (irrecv.decode(&results)) { 85 | Serial.println(results.value, HEX); 86 | dump(&results); 87 | irrecv.resume(); // Receive the next value 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /libraries/IRremoteESP8266/examples/IRsendDemo/IRsendDemo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * IRremoteESP8266: IRsendDemo - demonstrates sending IR codes with IRsend 3 | * An IR LED must be connected to ESP8266 pin 0. 4 | * Version 0.1 June, 2015 5 | * Based on Ken Shirriff's IrsendDemo Version 0.1 July, 2009, Copyright 2009 Ken Shirriff, http://arcfn.com 6 | */ 7 | 8 | #include 9 | 10 | IRsend irsend(0); //an IR led is connected to GPIO pin 0 11 | 12 | void setup() 13 | { 14 | irsend.begin(); 15 | Serial.begin(9600); 16 | } 17 | 18 | void loop() { 19 | Serial.println("NEC"); 20 | irsend.sendNEC(0x00FFE01F, 36); 21 | delay(2000); 22 | Serial.println("Sony"); 23 | irsend.sendSony(0xa90, 12); 24 | delay(2000); 25 | } 26 | -------------------------------------------------------------------------------- /libraries/IRremoteESP8266/examples/JVCPanasonicSendDemo/JVCPanasonicSendDemo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * IRremoteESP8266: IRsendDemo - demonstrates sending IR codes with IRsend 3 | * An IR LED must be connected to ESP8266 pin 0. 4 | * Version 0.1 June, 2015 5 | * Based on Ken Shirriff's IrsendDemo Version 0.1 July, 2009, Copyright 2009 Ken Shirriff, http://arcfn.com 6 | * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post) 7 | */ 8 | #include 9 | 10 | #define PanasonicAddress 0x4004 // Panasonic address (Pre data) 11 | #define PanasonicPower 0x100BCBD // Panasonic Power button 12 | 13 | #define JVCPower 0xC5E8 14 | 15 | IRsend irsend(0); //an IR led is connected to GPIO pin 0 16 | 17 | void setup() 18 | { 19 | irsend.begin(); 20 | } 21 | 22 | void loop() { 23 | irsend.sendPanasonic(PanasonicAddress,PanasonicPower); // This should turn your TV on and off 24 | 25 | irsend.sendJVC(JVCPower, 16,0); // hex value, 16 bits, no repeat 26 | delayMicroseconds(50); // see http://www.sbprojects.com/knowledge/ir/jvc.php for information 27 | irsend.sendJVC(JVCPower, 16,1); // hex value, 16 bits, repeat 28 | delayMicroseconds(50); 29 | } 30 | -------------------------------------------------------------------------------- /libraries/IRremoteESP8266/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For IRremote 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | decode_results KEYWORD1 10 | IRrecv KEYWORD1 11 | IRsend KEYWORD1 12 | 13 | ####################################### 14 | # Methods and Functions (KEYWORD2) 15 | ####################################### 16 | 17 | decode KEYWORD2 18 | enableIRIn KEYWORD2 19 | disableIRIn KEYWORD2 20 | resume KEYWORD2 21 | begin KEYWORD2 22 | enableIROut KEYWORD2 23 | sendNEC KEYWORD2 24 | sendSony KEYWORD2 25 | sendSanyo KEYWORD2 26 | sendMitsubishi KEYWORD2 27 | sendRaw KEYWORD2 28 | sendRC5 KEYWORD2 29 | sendRC6 KEYWORD2 30 | sendDISH KEYWORD2 31 | sendSharp KEYWORD2 32 | sendSharpRaw KEYWORD2 33 | sendPanasonic KEYWORD2 34 | sendJVC KEYWORD2 35 | sendWhynter KEYWORD2 36 | sendSAMSUNG KEYWORD2 37 | sendCOOLIX KEYWORD2 38 | 39 | ####################################### 40 | # Constants (LITERAL1) 41 | ####################################### 42 | 43 | NEC LITERAL1 44 | SONY LITERAL1 45 | SANYO LITERAL1 46 | MITSUBISHI LITERAL1 47 | RC5 LITERAL1 48 | RC6 LITERAL1 49 | DISH LITERAL1 50 | SHARP LITERAL1 51 | PANASONIC LITERAL1 52 | JVC LITERAL1 53 | LG LITERAL1 54 | SAMSUNG LITERAL1 55 | WHYNTER LITERAL1 56 | AIWA_RC_T501 LITERAL1 57 | COOLIX LITERAL1 58 | UNKNOWN LITERAL1 59 | REPEAT LITERAL1 -------------------------------------------------------------------------------- /libraries/IRremoteESP8266/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "IRremoteESP8266", 3 | "keywords": "infrared, ir, remote", 4 | "description": "Send and receive infrared signals with multiple protocols", 5 | "repository": 6 | { 7 | "type": "git", 8 | "url": "https://github.com/sebastienwarin/IRremoteESP8266.git" 9 | }, 10 | "frameworks": "arduino", 11 | "platforms": "esp8266" 12 | } 13 | -------------------------------------------------------------------------------- /libraries/IRremoteESP8266/library.properties: -------------------------------------------------------------------------------- 1 | name=IRremoteESP8266 2 | version=1.0.0 3 | author=Sebastien Warin, Mark Szabo, Ken Shirriff 4 | maintainer=Sebastien Warin 5 | sentence=Send and receive infrared signals with multiple protocols. 6 | paragraph=This library enables you to send and receive infra-red signals on an ESP8266. 7 | category=Device Control 8 | url=https://github.com/sebastienwarin/IRremoteESP8266 9 | architectures=esp8266 10 | -------------------------------------------------------------------------------- /libraries/PCF8574_HD44780_I2C/Examples/CustomChars/CustomChars.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | uint8_t bell[8] = {0x4,0xe,0xe,0xe,0x1f,0x0,0x4}; 5 | uint8_t note[8] = {0x2,0x3,0x2,0xe,0x1e,0xc,0x0}; 6 | uint8_t clock[8] = {0x0,0xe,0x15,0x17,0x11,0xe,0x0}; 7 | uint8_t heart[8] = {0x0,0xa,0x1f,0x1f,0xe,0x4,0x0}; 8 | uint8_t duck[8] = {0x0,0xc,0x1d,0xf,0xf,0x6,0x0}; 9 | uint8_t check[8] = {0x0,0x1,0x3,0x16,0x1c,0x8,0x0}; 10 | uint8_t cross[8] = {0x0,0x1b,0xe,0x4,0xe,0x1b,0x0}; 11 | uint8_t retarrow[8] = { 0x1,0x1,0x5,0x9,0x1f,0x8,0x4}; 12 | 13 | // Address 0x27, 16 chars, 2 line display 14 | PCF8574_HD44780_I2C lcd(0x27,16,2); 15 | 16 | 17 | void setup() 18 | { 19 | lcd.init(); // LCD Initialization 20 | lcd.backlight(); // Backlight ON 21 | lcd.clear(); // Clear the display 22 | 23 | lcd.createChar(0, bell); // Create the characters 24 | lcd.createChar(1, note); 25 | lcd.createChar(2, clock); 26 | lcd.createChar(3, heart); 27 | lcd.createChar(4, duck); 28 | lcd.createChar(5, check); 29 | lcd.createChar(6, cross); 30 | lcd.createChar(7, retarrow); 31 | lcd.home(); 32 | 33 | lcd.setCursor(0,0); 34 | for(uint8_t cr = 0; cr < 8; cr++){ 35 | lcd.write(cr); // Show the characters on the display 36 | } 37 | } 38 | 39 | void loop() 40 | { 41 | } -------------------------------------------------------------------------------- /libraries/PCF8574_HD44780_I2C/Examples/HelloWorld/HelloWorld.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | // Address 0x27, 16 chars, 2 line display 6 | PCF8574_HD44780_I2C lcd(0x27,16,2); 7 | 8 | 9 | void setup() 10 | { 11 | lcd.init(); // LCD Initialization 12 | lcd.backlight(); // Backlight ON 13 | lcd.clear(); // Clear the display 14 | 15 | lcd.setCursor(0,0); // Set the cursor to col 0, row 0 16 | lcd.print("Hello"); // Print the first word 17 | lcd.setCursor(0,1); // Set the cursor to col 0, row 1 18 | lcd.print("World!"); // Print the second word 19 | } 20 | 21 | void loop() 22 | { 23 | } 24 | -------------------------------------------------------------------------------- /libraries/PCF8574_HD44780_I2C/Examples/MultipleLcd/MultipleLcd.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // First LCD - Address 0x27, 16 chars, 2 line display 5 | PCF8574_HD44780_I2C lcd1(0x27,16,2); 6 | // Second LCD - Address 0x20, 16 chars, 2 line display 7 | PCF8574_HD44780_I2C lcd2(0x20,16,2); 8 | 9 | 10 | void setup() 11 | { 12 | lcd1.init(); // initialize the first lcd 13 | lcd2.init(); // initialize the second lcd 14 | 15 | // Print a message on the first LCD. 16 | lcd1.backlight(); 17 | lcd1.print("Hello, #1 world!"); 18 | 19 | // Print a message on the second LCD. 20 | lcd2.backlight(); 21 | lcd2.print("Hello, #2 world!"); 22 | 23 | } 24 | 25 | void loop() 26 | { 27 | } 28 | -------------------------------------------------------------------------------- /libraries/PCF8574_HD44780_I2C/Examples/SerialDisplay/SerialDisplay.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Displays text sent over the serial port (e.g. from the Serial Monitor) on 3 | * an attached LCD. 4 | */ 5 | #include 6 | #include 7 | 8 | 9 | // Address 0x27, 16 chars, 2 line display 10 | PCF8574_HD44780_I2C lcd(0x27,16,2); 11 | 12 | void setup() 13 | { 14 | lcd.init(); // LCD Initialization 15 | lcd.backlight(); // Backlight ON 16 | lcd.clear(); // Clear the display 17 | Serial.begin(115200); // You need to set this baudrate on serial monitor 18 | } 19 | 20 | void loop() 21 | { 22 | // when characters arrive over the serial port... 23 | if (Serial.available()) { 24 | // wait a bit for the entire message to arrive 25 | delay(100); 26 | // clear the screen 27 | lcd.clear(); 28 | // read all the available characters 29 | while (Serial.available() > 0) { 30 | // display each character to the LCD 31 | lcd.write(Serial.read()); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /libraries/PCF8574_HD44780_I2C/Info/HD44780.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abzman/esp-stuff/93f390c95d2fb8b4b88caee80a7901eb904328de/libraries/PCF8574_HD44780_I2C/Info/HD44780.pdf -------------------------------------------------------------------------------- /libraries/PCF8574_HD44780_I2C/Info/I2C_LCD_Breakoutboard.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abzman/esp-stuff/93f390c95d2fb8b4b88caee80a7901eb904328de/libraries/PCF8574_HD44780_I2C/Info/I2C_LCD_Breakoutboard.jpg -------------------------------------------------------------------------------- /libraries/PCF8574_HD44780_I2C/Info/PCF8574.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abzman/esp-stuff/93f390c95d2fb8b4b88caee80a7901eb904328de/libraries/PCF8574_HD44780_I2C/Info/PCF8574.pdf -------------------------------------------------------------------------------- /libraries/PCF8574_HD44780_I2C/Info/README.txt: -------------------------------------------------------------------------------- 1 | /********************************* 2 | PCF8574_HD44780_I2C 3 | Library for PCF8574 Breakout Board 4 | by Testato on ArduinoForum 5 | 6 | based on code from: 7 | - Mario H. 8 | **********************************/ 9 | 10 | You can see in the picture I2C_LCD_Breakoutboard.jpg the board compatible with this library 11 | - Without solder the A0-A1-A2 the address is 0x27 12 | - If you do not have or do not want the backlight, remove the Jumper, otherwise replace the jumper with a limiting resistor of the correct value for your display. 13 | 14 | - For news and comment: 15 | http://forum.arduino.cc/index.php?topic=242423.0 16 | 17 | 18 | - Original Library Ver 2.0 (not working on this breakoutboard) 19 | http://hmario.home.xs4all.nl/arduino/LiquidCrystal_I2C/ 20 | 21 | 22 | Update: 23 | -------------------------- 24 | Ver 2.1 (first release compatible with this breakoutboard): 25 | - Changed name to PCF8574_HD44780_I2C Library 26 | - Added Expander I/O Port define 27 | - Replaced many Hex value with a more friendly _BV() macro 28 | - Adapted all commands and flags define to this breakout board 29 | - Changed Backlight logic for NPN transistor used on this breakout board 30 | - Adapted send() function 31 | - Removed unnecessary Delay from Init() function 32 | - Comments added to many #Define 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /libraries/PCF8574_HD44780_I2C/keywords.txt: -------------------------------------------------------------------------------- 1 | ########################################### 2 | # Syntax Coloring Map 3 | # PCF8574_HD44780_I2C Library 4 | ########################################### 5 | 6 | ########################################### 7 | # Datatypes (KEYWORD1) 8 | ########################################### 9 | 10 | LiquidCrystal_I2C KEYWORD1 11 | 12 | ########################################### 13 | # Methods and Functions (KEYWORD2) 14 | ########################################### 15 | init KEYWORD2 16 | begin KEYWORD2 17 | clear KEYWORD2 18 | home KEYWORD2 19 | noDisplay KEYWORD2 20 | display KEYWORD2 21 | noBlink KEYWORD2 22 | blink KEYWORD2 23 | noCursor KEYWORD2 24 | cursor KEYWORD2 25 | scrollDisplayLeft KEYWORD2 26 | scrollDisplayRight KEYWORD2 27 | leftToRight KEYWORD2 28 | rightToLeft KEYWORD2 29 | shiftIncrement KEYWORD2 30 | shiftDecrement KEYWORD2 31 | noBacklight KEYWORD2 32 | backlight KEYWORD2 33 | autoscroll KEYWORD2 34 | noAutoscroll KEYWORD2 35 | createChar KEYWORD2 36 | setCursor KEYWORD2 37 | print KEYWORD2 38 | blink_on KEYWORD2 39 | blink_off KEYWORD2 40 | cursor_on KEYWORD2 41 | cursor_off KEYWORD2 42 | setBacklight KEYWORD2 43 | load_custom_character KEYWORD2 44 | printstr KEYWORD2 45 | ########################################### 46 | # Constants (LITERAL1) 47 | ########################################### 48 | -------------------------------------------------------------------------------- /libraries/Rtc/.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /libraries/Rtc/.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | 38 | # Directories potentially created on remote AFP share 39 | .AppleDB 40 | .AppleDesktop 41 | Network Trash Folder 42 | Temporary Items 43 | .apdisk 44 | -------------------------------------------------------------------------------- /libraries/Rtc/README.md: -------------------------------------------------------------------------------- 1 | # Rtc 2 | 3 | Arduino Real Time Clock library. 4 | An RTC library with deep device support. 5 | 6 | Now supports esp8266. 7 | 8 | ## Installing This Library 9 | 10 | Clone (Git) this project into Documents/Arduino/libraries/Rtc. 11 | It should now show up in the import list. 12 | 13 | ## Supported Devices 14 | ###DS1307 15 | Full support including squarewave output pin and memory access 16 | 17 | ###DS3231 18 | Full support including squarewave output pin and alarms. 19 | 20 | ## Samples 21 | ###DS1307 Simple 22 | This demonstrates how to set and get the date and time from the device. 23 | 24 | ###DS1307 Memory 25 | This demonstrates how to write and read data from the extended memory of the device. This memory is retained even after the device has lost power. 26 | 27 | ###DS3231 Simple 28 | This demonstrates how to set and get the date and time from the device. 29 | 30 | ###DS3231 StoreIt 31 | This demonstrates how to turn off the Rtc clock so that the onboard battery will last longer. 32 | 33 | ###DS3231 Alarms 34 | This demonstrates how to set the alarms and check when the alarms are triggered. This includes using the squarewave output to trigger an interrupt. 35 | -------------------------------------------------------------------------------- /libraries/Rtc/RtcDS1307.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef __RTCDS1307_H__ 4 | #define __RTCDS1307_H__ 5 | 6 | #include 7 | #include 8 | 9 | enum DS1307SquareWaveOut 10 | { 11 | DS1307SquareWaveOut_1Hz = 0b00010000, 12 | DS1307SquareWaveOut_4kHz = 0b00010001, 13 | DS1307SquareWaveOut_8kHz = 0b00010010, 14 | DS1307SquareWaveOut_32kHz = 0b00010011, 15 | DS1307SquareWaveOut_High = 0b10000000, 16 | DS1307SquareWaveOut_Low = 0b00000000, 17 | }; 18 | 19 | class RtcDS1307 20 | { 21 | public: 22 | static void Begin(); 23 | 24 | static bool IsDateTimeValid() 25 | { 26 | return GetIsRunning(); 27 | } 28 | 29 | static bool GetIsRunning(); 30 | static void SetIsRunning(bool isRunning); 31 | 32 | static void SetDateTime(const RtcDateTime& dt); 33 | static RtcDateTime GetDateTime(); 34 | 35 | static void SetMemory(uint8_t memoryAddress, uint8_t value); 36 | static uint8_t GetMemory(uint8_t memoryAddress); 37 | 38 | static uint8_t SetMemory(uint8_t memoryAddress, const uint8_t* pValue, uint8_t countBytes); 39 | static uint8_t GetMemory(uint8_t memoryAddress, uint8_t* pValue, uint8_t countBytes); 40 | 41 | static void SetSquareWavePin(DS1307SquareWaveOut pinMode); 42 | 43 | private: 44 | static uint8_t getReg(uint8_t regAddress); 45 | static void setReg(uint8_t regAddress, uint8_t regValue); 46 | }; 47 | 48 | #endif // __RTCDS1307_H__ -------------------------------------------------------------------------------- /libraries/Rtc/RtcDateTime.cpp: -------------------------------------------------------------------------------- 1 | 2 | #if defined(ESP8266) 3 | #include 4 | #else 5 | #include 6 | #endif 7 | 8 | #include "RtcDateTime.h" 9 | #include 10 | 11 | 12 | static const uint8_t c_daysInMonth[] PROGMEM = { 31,28,31,30,31,30,31,31,30,31,30,31 }; 13 | 14 | RtcDateTime::RtcDateTime(uint32_t secondsFrom2000) 15 | { 16 | _second = secondsFrom2000 % 60; 17 | uint32_t timeFrom2000 = secondsFrom2000 / 60; 18 | _minute = timeFrom2000 % 60; 19 | timeFrom2000 /= 60; 20 | _hour = timeFrom2000 % 24; 21 | uint16_t days = timeFrom2000 / 24; 22 | uint8_t leapDays; 23 | 24 | for (_yearFrom2000 = 0; ; ++_yearFrom2000) 25 | { 26 | leapDays = (_yearFrom2000 % 4 == 0) ? 1 : 0; 27 | if (days < 365U + leapDays) 28 | break; 29 | days -= 365 + leapDays; 30 | } 31 | for (_month = 1; ; ++_month) 32 | { 33 | uint8_t daysPerMonth = pgm_read_byte(c_daysInMonth + _month - 1); 34 | if (leapDays && _month == 2) 35 | daysPerMonth++; 36 | if (days < daysPerMonth) 37 | break; 38 | days -= daysPerMonth; 39 | } 40 | _dayOfMonth = days + 1; 41 | } 42 | 43 | uint8_t StringToUint8(const char* pString) 44 | { 45 | uint8_t value = 0; 46 | 47 | // skip leading 0 and spaces 48 | while ('0' == *pString || *pString == ' ') 49 | { 50 | pString++; 51 | } 52 | 53 | // calculate number until we hit non-numeral char 54 | while ('0' <= *pString && *pString <= '9') 55 | { 56 | value *= 10; 57 | value += *pString - '0'; 58 | pString++; 59 | } 60 | return value; 61 | } 62 | 63 | RtcDateTime::RtcDateTime(const char* date, const char* time) 64 | { 65 | // sample input: date = "Dec 26 2009", time = "12:34:56" 66 | _yearFrom2000 = StringToUint8(date + 9); 67 | // Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 68 | switch (date[0]) 69 | { 70 | case 'J': 71 | if ( date[1] == 'a' ) 72 | _month = 1; 73 | else if ( date[2] == 'n' ) 74 | _month = 6; 75 | else 76 | _month = 7; 77 | break; 78 | case 'F': 79 | _month = 2; 80 | break; 81 | case 'A': 82 | _month = date[1] == 'p' ? 4 : 8; 83 | break; 84 | case 'M': 85 | _month = date[2] == 'r' ? 3 : 5; 86 | break; 87 | case 'S': 88 | _month = 9; 89 | break; 90 | case 'O': 91 | _month = 10; 92 | break; 93 | case 'N': 94 | _month = 11; 95 | break; 96 | case 'D': 97 | _month = 12; 98 | break; 99 | } 100 | _dayOfMonth = StringToUint8(date + 4); 101 | _hour = StringToUint8(time); 102 | _minute = StringToUint8(time + 3); 103 | _second = StringToUint8(time + 6); 104 | } 105 | 106 | uint16_t DaysSinceFirstOfYear2000(uint16_t year, uint8_t month, uint8_t dayOfMonth) 107 | { 108 | uint16_t days = dayOfMonth; 109 | for (uint8_t indexMonth = 1; indexMonth < month; ++indexMonth) 110 | { 111 | days += pgm_read_byte(c_daysInMonth + indexMonth - 1); 112 | } 113 | if (month > 2 && year % 4 == 0) 114 | { 115 | days++; 116 | } 117 | return days + 365 * year + (year + 3) / 4 - 1; 118 | } 119 | 120 | uint32_t SecondsIn(uint16_t days, uint8_t hours, uint8_t minutes, uint8_t seconds) 121 | { 122 | return ((days * 24L + hours) * 60 + minutes) * 60 + seconds; 123 | } 124 | 125 | uint8_t RtcDateTime::DayOfWeek() const 126 | { 127 | uint16_t days = DaysSinceFirstOfYear2000(_yearFrom2000, _month, _dayOfMonth); 128 | return (days + 6) % 7; // Jan 1, 2000 is a Saturday, i.e. returns 6 129 | } 130 | 131 | uint32_t RtcDateTime::TotalSeconds() const 132 | { 133 | uint16_t days = DaysSinceFirstOfYear2000(_yearFrom2000, _month, _dayOfMonth); 134 | return SecondsIn(days, _hour, _minute, _second); 135 | } -------------------------------------------------------------------------------- /libraries/Rtc/RtcDateTime.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef __RTCDATETIME_H__ 4 | #define __RTCDATETIME_H__ 5 | 6 | class RtcDateTime 7 | { 8 | public: 9 | RtcDateTime(uint32_t secondsFrom2000 = 0); 10 | RtcDateTime(uint16_t year, 11 | uint8_t month, 12 | uint8_t dayOfMonth, 13 | uint8_t hour, 14 | uint8_t minute, 15 | uint8_t second) : 16 | _yearFrom2000((year >= 2000) ? year - 2000 : year), 17 | _month(month), 18 | _dayOfMonth(dayOfMonth), 19 | _hour(hour), 20 | _minute(minute), 21 | _second(second) 22 | { 23 | } 24 | 25 | // RtcDateTime compileDateTime(__DATE__, __TIME__); 26 | RtcDateTime(const char* date, const char* time); 27 | 28 | uint16_t Year() const 29 | { 30 | return 2000 + _yearFrom2000; 31 | } 32 | uint8_t Month() const 33 | { 34 | return _month; 35 | } 36 | uint8_t Day() const 37 | { 38 | return _dayOfMonth; 39 | } 40 | uint8_t Hour() const 41 | { 42 | return _hour; 43 | } 44 | uint8_t Minute() const 45 | { 46 | return _minute; 47 | } 48 | uint8_t Second() const 49 | { 50 | return _second; 51 | } 52 | uint8_t DayOfWeek() const; 53 | 54 | // 32-bit times as seconds since 1/1/2000 55 | uint32_t TotalSeconds() const; 56 | 57 | // add seconds 58 | void operator += (uint32_t seconds) 59 | { 60 | RtcDateTime after = RtcDateTime( TotalSeconds() + seconds ); 61 | *this = after; 62 | } 63 | 64 | // allows for comparisons to just work (==, <, >, <=, >=, !=) 65 | operator uint32_t() const 66 | { 67 | return TotalSeconds(); 68 | } 69 | 70 | protected: 71 | uint8_t _yearFrom2000; 72 | uint8_t _month; 73 | uint8_t _dayOfMonth; 74 | uint8_t _hour; 75 | uint8_t _minute; 76 | uint8_t _second; 77 | }; 78 | 79 | #endif // __RTCDATETIME_H__ -------------------------------------------------------------------------------- /libraries/Rtc/RtcTemperature.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef __RTCTEMPERATURE_H__ 4 | #define __RTCTEMPERATURE_H__ 5 | 6 | 7 | class RtcTemperature 8 | { 9 | public: 10 | RtcTemperature(int8_t degrees, uint8_t fraction) : 11 | integerDegrees(degrees), 12 | decimalFraction(fraction) 13 | { 14 | } 15 | 16 | float AsFloat() 17 | { 18 | float degrees = (float)integerDegrees; 19 | degrees += ((degrees < 0) ? -1 : 1) * (float)decimalFraction; 20 | return degrees; 21 | } 22 | 23 | int8_t AsWholeDegrees() 24 | { 25 | return integerDegrees; 26 | } 27 | 28 | uint8_t GetFractional() 29 | { 30 | return decimalFraction; 31 | } 32 | 33 | protected: 34 | int8_t integerDegrees; 35 | uint8_t decimalFraction; 36 | }; 37 | 38 | #endif // __RTCTEMPERATURE_H__ -------------------------------------------------------------------------------- /libraries/Rtc/RtcUtility.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #if defined(ESP8266) 5 | #include 6 | #else 7 | #include 8 | #endif 9 | #include "RtcUtility.h" 10 | 11 | uint8_t BcdToUint8(uint8_t val) 12 | { 13 | return val - 6 * (val >> 4); 14 | } 15 | 16 | uint8_t Uint8ToBcd(uint8_t val) 17 | { 18 | return val + 6 * (val / 10); 19 | } 20 | 21 | uint8_t BcdToBin24Hour(uint8_t bcdHour) 22 | { 23 | uint8_t hour; 24 | if (bcdHour & 0x20) 25 | { 26 | // 12 hour mode, convert to 24 27 | bool isPm = ((bcdHour & 0x10) != 0); 28 | 29 | hour = BcdToUint8(bcdHour & 0x1f); 30 | if (isPm) 31 | { 32 | hour += 12; 33 | } 34 | } 35 | else 36 | { 37 | hour = BcdToUint8(bcdHour); 38 | } 39 | return hour; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /libraries/Rtc/RtcUtility.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __RTCUTILITY_H__ 3 | #define __RTCUTILITY_H__ 4 | 5 | extern uint8_t BcdToUint8(uint8_t val); 6 | extern uint8_t Uint8ToBcd(uint8_t val); 7 | extern uint8_t BcdToBin24Hour(uint8_t bcdHour); 8 | 9 | #endif // __RTCUTILITY_H__ 10 | -------------------------------------------------------------------------------- /libraries/Rtc/examples/DS1307_Memory/DS1307_Memory.ino: -------------------------------------------------------------------------------- 1 | 2 | // CONNECTIONS: 3 | // DS3231 SDA --> SDA 4 | // DS3231 SCL --> SCL 5 | 6 | #define countof(a) (sizeof(a) / sizeof(a[0])) 7 | 8 | #if defined(ESP8266) 9 | #include 10 | #else 11 | #include 12 | #endif 13 | #include // must be incuded here so that Arduino library object file references work 14 | #include 15 | 16 | RtcDS1307 Rtc; 17 | 18 | const char data[] = "what time is it"; 19 | 20 | void setup () 21 | { 22 | Serial.begin(57600); 23 | 24 | Serial.print("compiled: "); 25 | Serial.print(__DATE__); 26 | Serial.println(__TIME__); 27 | 28 | //--------RTC SETUP ------------ 29 | Rtc.Begin(); 30 | #if defined(ESP8266) 31 | Wire.begin(0, 2); 32 | #endif 33 | 34 | RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__); 35 | printDateTime(compiled); 36 | Serial.println(); 37 | 38 | if (!Rtc.IsDateTimeValid()) 39 | { 40 | Serial.println("RTC lost confidence in the DateTime!"); 41 | Rtc.SetDateTime(compiled); 42 | } 43 | 44 | RtcDateTime now = Rtc.GetDateTime(); 45 | if (now < compiled) 46 | { 47 | Serial.println("RTC is older than compile time! (Updating DateTime)"); 48 | Rtc.SetDateTime(compiled); 49 | } 50 | 51 | // never assume the Rtc was last configured by you, so 52 | // just clear them to your needed state 53 | Rtc.SetSquareWavePin(DS1307SquareWaveOut_Low); 54 | 55 | /* comment out on a second run to see that the info is stored long term */ 56 | // Store something in memory on the RTC 57 | Rtc.SetMemory(0, 13); 58 | uint8_t written = Rtc.SetMemory(13, (const uint8_t*)data, sizeof(data) - 1); // remove the null terminator strings add 59 | Rtc.SetMemory(1, written); 60 | /* end of comment out section */ 61 | } 62 | 63 | void loop () 64 | { 65 | if (!Rtc.IsDateTimeValid()) 66 | { 67 | // Common Cuases: 68 | // 1) the battery on the device is low or even missing and the power line was disconnected 69 | Serial.println("RTC lost confidence in the DateTime!"); 70 | } 71 | 72 | RtcDateTime now = Rtc.GetDateTime(); 73 | 74 | printDateTime(now); 75 | Serial.println(); 76 | 77 | delay(5000); 78 | 79 | // read data 80 | 81 | // get the offset we stored our data from address zero 82 | uint8_t address = Rtc.GetMemory(0); 83 | if (address != 13) 84 | { 85 | Serial.println("address didn't match"); 86 | } 87 | else 88 | { 89 | // get the size of the data from address 1 90 | uint8_t count = Rtc.GetMemory(1); 91 | uint8_t buff[20]; 92 | 93 | // get our data from the address with the given size 94 | uint8_t gotten = Rtc.GetMemory(address, buff, count); 95 | 96 | if (gotten != count || 97 | count != sizeof(data) - 1) // remove the extra null terminator strings add 98 | { 99 | Serial.print("something didn't match, count = "); 100 | Serial.print(count, DEC); 101 | Serial.print(", gotten = "); 102 | Serial.print(gotten, DEC); 103 | Serial.println(); 104 | } 105 | Serial.print("data read ("); 106 | Serial.print(gotten); 107 | Serial.print(") = \""); 108 | while (gotten > 0) 109 | { 110 | Serial.print((char)buff[count - gotten]); 111 | gotten--; 112 | } 113 | Serial.println("\""); 114 | } 115 | 116 | 117 | delay(5000); 118 | } 119 | 120 | 121 | 122 | void printDateTime(const RtcDateTime& dt) 123 | { 124 | char datestring[20]; 125 | 126 | snprintf_P(datestring, 127 | countof(datestring), 128 | PSTR("%02u/%02u/%04u %02u:%02u:%02u"), 129 | dt.Month(), 130 | dt.Day(), 131 | dt.Year(), 132 | dt.Hour(), 133 | dt.Minute(), 134 | dt.Second() ); 135 | Serial.print(datestring); 136 | } 137 | 138 | -------------------------------------------------------------------------------- /libraries/Rtc/examples/DS1307_Simple/DS1307_Simple.ino: -------------------------------------------------------------------------------- 1 | 2 | // CONNECTIONS: 3 | // DS3231 SDA --> SDA 4 | // DS3231 SCL --> SCL 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include // must be incuded here so that Arduino library object file references work 11 | #include 12 | 13 | RtcDS1307 Rtc; 14 | 15 | void setup () 16 | { 17 | Serial.begin(115200); 18 | 19 | Serial.print("compiled: "); 20 | Serial.print(__DATE__); 21 | Serial.println(__TIME__); 22 | 23 | //--------RTC SETUP ------------ 24 | Rtc.Begin(); 25 | Wire.begin(0, 2); 26 | 27 | RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__); 28 | printDateTime(compiled); 29 | Serial.println(); 30 | 31 | if (!Rtc.IsDateTimeValid()) 32 | { 33 | // Common Cuases: 34 | // 1) first time you ran and the device wasn't running yet 35 | // 2) the battery on the device is low or even missing 36 | 37 | Serial.println("RTC lost confidence in the DateTime!"); 38 | 39 | // following line sets the RTC to the date & time this sketch was compiled 40 | // it will also reset the valid flag internally unless the Rtc device is 41 | // having an issue 42 | 43 | Rtc.SetDateTime(compiled); 44 | } 45 | 46 | RtcDateTime now = Rtc.GetDateTime(); 47 | if (now < compiled) 48 | { 49 | Serial.println("RTC is older than compile time! (Updating DateTime)"); 50 | Rtc.SetDateTime(compiled); 51 | } 52 | else if (now > compiled) 53 | { 54 | Serial.println("RTC is newer than compile time. (this is expected)"); 55 | } 56 | else if (now == compiled) 57 | { 58 | Serial.println("RTC is the same as compile time! (not expected but all is fine)"); 59 | } 60 | 61 | // never assume the Rtc was last configured by you, so 62 | // just clear them to your needed state 63 | Rtc.SetSquareWavePin(DS1307SquareWaveOut_Low); 64 | } 65 | 66 | void loop () 67 | { 68 | if (!Rtc.IsDateTimeValid()) 69 | { 70 | // Common Cuases: 71 | // 1) the battery on the device is low or even missing and the power line was disconnected 72 | Serial.println("RTC lost confidence in the DateTime!"); 73 | } 74 | 75 | RtcDateTime now = Rtc.GetDateTime(); 76 | 77 | printDateTime(now); 78 | Serial.println(); 79 | 80 | delay(10000); // ten seconds 81 | } 82 | 83 | #define countof(a) (sizeof(a) / sizeof(a[0])) 84 | 85 | void printDateTime(const RtcDateTime& dt) 86 | { 87 | String datestring = ""; 88 | datestring += dt.Month(); 89 | datestring += "/"; 90 | datestring += dt.Day(); 91 | datestring += "/"; 92 | datestring += dt.Year(); 93 | datestring += " "; 94 | datestring += dt.Hour(); 95 | datestring += ":"; 96 | datestring += dt.Minute(); 97 | datestring += ":"; 98 | datestring += dt.Second(); 99 | datestring += "\n"; 100 | Serial.print(datestring); 101 | } 102 | 103 | -------------------------------------------------------------------------------- /libraries/Rtc/examples/DS3231_Alarms/DS3231_Alarms.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {969D9575-C911-4B46-BC8C-88C6A9086115} 15 | DS3231_Alarms 16 | 17 | 18 | 19 | Application 20 | true 21 | v120 22 | MultiByte 23 | 24 | 25 | Application 26 | false 27 | v120 28 | true 29 | MultiByte 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | Level3 45 | Disabled 46 | true 47 | 48 | 49 | true 50 | 51 | 52 | 53 | 54 | Level3 55 | MaxSpeed 56 | true 57 | true 58 | true 59 | 60 | 61 | true 62 | true 63 | true 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /libraries/Rtc/examples/DS3231_Alarms/DS3231_Alarms.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | -------------------------------------------------------------------------------- /libraries/Rtc/examples/DS3231_Alarms/Visual Micro/.DS3231_Alarms.vsarduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | Editor: http://www.visualmicro.com 3 | visual micro and the arduino ide ignore this code during compilation. this code is automatically maintained by visualmicro, manual changes to this file will be overwritten 4 | the contents of the Visual Micro sketch sub folder can be deleted prior to publishing a project 5 | all non-arduino files created by visual micro and all visual studio project or solution files can be freely deleted and are not required to compile a sketch (do not delete your own code!). 6 | note: debugger breakpoints are stored in '.sln' or '.asln' files, knowledge of last uploaded breakpoints is stored in the upload.vmps.xml file. Both files are required to continue a previous debug session without needing to compile and upload again 7 | 8 | Hardware: Arduino Mega w/ ATmega2560 (Mega 2560), Platform=avr, Package=arduino 9 | */ 10 | 11 | #ifndef _VSARDUINO_H_ 12 | #define _VSARDUINO_H_ 13 | #define __AVR_ATmega2560__ 14 | #define ARDUINO 161 15 | #define ARDUINO_MAIN 16 | #define __AVR__ 17 | #define __avr__ 18 | #define F_CPU 16000000L 19 | #define __cplusplus 20 | #define GCC_VERSION 40801 21 | #define ARDUINO_ARCH_AVR 22 | #define ARDUINO_AVR_MEGA2560 23 | #define __inline__ 24 | #define __asm__(x) 25 | #define __extension__ 26 | //#define __ATTR_PURE__ 27 | //#define __ATTR_CONST__ 28 | #define __inline__ 29 | //#define __asm__ 30 | #define __volatile__ 31 | #define GCC_VERSION 40801 32 | #define volatile(va_arg) 33 | 34 | typedef void *__builtin_va_list; 35 | #define __builtin_va_start 36 | #define __builtin_va_end 37 | //#define __DOXYGEN__ 38 | #define __attribute__(x) 39 | #define NOINLINE __attribute__((noinline)) 40 | #define prog_void 41 | #define PGM_VOID_P int 42 | #define NEW_H 43 | /* 44 | #ifndef __ATTR_CONST__ 45 | #define __ATTR_CONST__ __attribute__((__const__)) 46 | #endif 47 | 48 | #ifndef __ATTR_MALLOC__ 49 | #define __ATTR_MALLOC__ __attribute__((__malloc__)) 50 | #endif 51 | 52 | #ifndef __ATTR_NORETURN__ 53 | #define __ATTR_NORETURN__ __attribute__((__noreturn__)) 54 | #endif 55 | 56 | #ifndef __ATTR_PURE__ 57 | #define __ATTR_PURE__ __attribute__((__pure__)) 58 | #endif 59 | */ 60 | typedef unsigned char byte; 61 | extern "C" void __cxa_pure_virtual() {;} 62 | 63 | 64 | 65 | #include 66 | #include 67 | #undef F 68 | #define F(string_literal) ((const PROGMEM char *)(string_literal)) 69 | #undef cli 70 | #define cli() 71 | #define pgm_read_byte(address_short) 72 | #define pgm_read_word(address_short) 73 | #define pgm_read_word2(address_short) 74 | #define digitalPinToPort(P) 75 | #define digitalPinToBitMask(P) 76 | #define digitalPinToTimer(P) 77 | #define analogInPinToBit(P) 78 | #define portOutputRegister(P) 79 | #define portInputRegister(P) 80 | #define portModeRegister(P) 81 | #include 82 | #endif 83 | -------------------------------------------------------------------------------- /libraries/Rtc/examples/DS3231_Simple/DS3231_Simple.ino: -------------------------------------------------------------------------------- 1 | 2 | // CONNECTIONS: 3 | // DS3231 SDA --> SDA 4 | // DS3231 SCL --> SCL 5 | 6 | #if defined(ESP8266) 7 | #include 8 | #else 9 | #include 10 | #endif 11 | #include // must be incuded here so that Arduino library object file references work 12 | #include 13 | 14 | RtcDS3231 Rtc; 15 | 16 | void setup () 17 | { 18 | Serial.begin(57600); 19 | 20 | Serial.print("compiled: "); 21 | Serial.print(__DATE__); 22 | Serial.println(__TIME__); 23 | 24 | //--------RTC SETUP ------------ 25 | Rtc.Begin(); 26 | #if defined(ESP8266) 27 | Wire.begin(0, 2); 28 | #endif 29 | 30 | RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__); 31 | printDateTime(compiled); 32 | Serial.println(); 33 | 34 | if (!Rtc.IsDateTimeValid()) 35 | { 36 | // Common Cuases: 37 | // 1) first time you ran and the device wasn't running yet 38 | // 2) the battery on the device is low or even missing 39 | 40 | Serial.println("RTC lost confidence in the DateTime!"); 41 | 42 | // following line sets the RTC to the date & time this sketch was compiled 43 | // it will also reset the valid flag internally unless the Rtc device is 44 | // having an issue 45 | 46 | Rtc.SetDateTime(compiled); 47 | } 48 | 49 | RtcDateTime now = Rtc.GetDateTime(); 50 | if (now < compiled) 51 | { 52 | Serial.println("RTC is older than compile time! (Updating DateTime)"); 53 | Rtc.SetDateTime(compiled); 54 | } 55 | else if (now > compiled) 56 | { 57 | Serial.println("RTC is newer than compile time. (this is expected)"); 58 | } 59 | else if (now == compiled) 60 | { 61 | Serial.println("RTC is the same as compile time! (not expected but all is fine)"); 62 | } 63 | 64 | // never assume the Rtc was last configured by you, so 65 | // just clear them to your needed state 66 | Rtc.Enable32kHzPin(false); 67 | Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeNone); 68 | } 69 | 70 | void loop () 71 | { 72 | if (!Rtc.IsDateTimeValid()) 73 | { 74 | // Common Cuases: 75 | // 1) the battery on the device is low or even missing and the power line was disconnected 76 | Serial.println("RTC lost confidence in the DateTime!"); 77 | } 78 | 79 | RtcDateTime now = Rtc.GetDateTime(); 80 | 81 | printDateTime(now); 82 | Serial.println(); 83 | 84 | delay(10000); // ten seconds 85 | } 86 | 87 | #define countof(a) (sizeof(a) / sizeof(a[0])) 88 | 89 | void printDateTime(const RtcDateTime& dt) 90 | { 91 | char datestring[20]; 92 | 93 | snprintf_P(datestring, 94 | countof(datestring), 95 | PSTR("%02u/%02u/%04u %02u:%02u:%02u"), 96 | dt.Month(), 97 | dt.Day(), 98 | dt.Year(), 99 | dt.Hour(), 100 | dt.Minute(), 101 | dt.Second() ); 102 | Serial.print(datestring); 103 | } 104 | 105 | -------------------------------------------------------------------------------- /libraries/Rtc/examples/DS3231_StoreIt/DS3231_StoreIt.ino: -------------------------------------------------------------------------------- 1 | 2 | // CONNECTIONS: 3 | // DS3231 SDA --> SDA 4 | // DS3231 SCL --> SCL 5 | 6 | #if defined(ESP8266) 7 | #include 8 | #else 9 | #include 10 | #endif 11 | #include // must be incuded here so that Arduino library object file references work 12 | #include 13 | 14 | RtcDS3231 Rtc; 15 | 16 | void setup () 17 | { 18 | Serial.begin(57600); 19 | 20 | Serial.print("compiled: "); 21 | Serial.print(__DATE__); 22 | Serial.println(__TIME__); 23 | 24 | //--------RTC SETUP ------------ 25 | Rtc.Begin(); 26 | #if defined(ESP8266) 27 | Wire.begin(0, 2); 28 | #endif 29 | RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__); 30 | printDateTime(compiled); 31 | Serial.println(); 32 | 33 | if (!Rtc.IsDateTimeValid()) 34 | { 35 | Serial.println("RTC lost confidence in the DateTime!"); 36 | Rtc.SetDateTime(compiled); 37 | } 38 | 39 | RtcDateTime now = Rtc.GetDateTime(); 40 | if (now < compiled) 41 | { 42 | Serial.println("RTC is older than compile time! (Updating DateTime)"); 43 | Rtc.SetDateTime(compiled); 44 | } 45 | 46 | // never assume the Rtc was last configured by you, so 47 | // just clear them to your needed state 48 | Rtc.Enable32kHzPin(false); 49 | Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeNone); 50 | } 51 | 52 | void loop () 53 | { 54 | RtcDateTime now = Rtc.GetDateTime(); 55 | 56 | printDateTime(now); 57 | Serial.println(); 58 | 59 | for(;;) 60 | { 61 | Rtc.SetIsRunning(false); 62 | Serial.println(">>> Rtc ready for storage <<<"); 63 | 64 | delay(10000); // ten seconds 65 | } 66 | } 67 | 68 | #define countof(a) (sizeof(a) / sizeof(a[0])) 69 | 70 | void printDateTime(const RtcDateTime& dt) 71 | { 72 | char datestring[20]; 73 | 74 | snprintf_P(datestring, 75 | countof(datestring), 76 | PSTR("%02u/%02u/%04u %02u:%02u:%02u"), 77 | dt.Month(), 78 | dt.Day(), 79 | dt.Year(), 80 | dt.Hour(), 81 | dt.Minute(), 82 | dt.Second() ); 83 | Serial.print(datestring); 84 | } 85 | 86 | -------------------------------------------------------------------------------- /libraries/Rtc/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map Task 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | DS3231AlarmOne KEYWORD1 10 | DS3231AlarmTwo KEYWORD1 11 | RtcDS3231 KEYWORD1 12 | RtcTemperature KEYWORD1 13 | RtcDateTime KEYWORD1 14 | 15 | ####################################### 16 | # Methods and Functions (KEYWORD2) 17 | ####################################### 18 | 19 | Begin KEYWORD2 20 | IsDateTimeValid KEYWORD2 21 | GetIsRunning KEYWORD2 22 | SetIsRunning KEYWORD2 23 | SetDateTime KEYWORD2 24 | GetDateTime KEYWORD2 25 | GetTemperature KEYWORD2 26 | Enable32kHzPin KEYWORD2 27 | SetSquareWavePin KEYWORD2 28 | SetSquareWavePinClockFrequency KEYWORD2 29 | SetAlarmOne KEYWORD2 30 | SetAlarmTwo KEYWORD2 31 | GetAlarmOne KEYWORD2 32 | GetAlarmTwo KEYWORD2 33 | LatchAlarmsTriggeredFlags KEYWORD2 34 | ForceTemperatureCompensationUpdate KEYWORD2 35 | GetAgingOffset KEYWORD2 36 | SetAgingOffset KEYWORD2 37 | AsFloat KEYWORD2 38 | AsWholeDegrees KEYWORD2 39 | GetFractional KEYWORD2 40 | Year KEYWORD2 41 | Month KEYWORD2 42 | Day KEYWORD2 43 | Hour KEYWORD2 44 | Minute KEYWORD2 45 | Second KEYWORD2 46 | DayOfWeek KEYWORD2 47 | TotalSeconds KEYWORD2 48 | DayOf KEYWORD2 49 | ControlFlags KEYWORD2 50 | 51 | ####################################### 52 | # Constants (LITERAL1) 53 | ####################################### 54 | 55 | DS3231SquareWaveClock_1Hz LITERAL1 56 | DS3231SquareWaveClock_1kHz LITERAL1 57 | DS3231SquareWaveClock_4kHz LITERAL1 58 | DS3231SquareWaveClock_8kHz LITERAL1 59 | DS3231SquareWavePin_ModeNone LITERAL1 60 | DS3231SquareWavePin_ModeBatteryBackup LITERAL1 61 | DS3231SquareWavePin_ModeClock LITERAL1 62 | DS3231SquareWavePin_ModeAlarmOne LITERAL1 63 | DS3231SquareWavePin_ModeAlarmTwo LITERAL1 64 | DS3231SquareWavePin_ModeAlarmBoth LITERAL1 65 | DS3231AlarmOneControl_HoursMinutesSecondsDayOfMonthMatch LITERAL1 66 | DS3231AlarmOneControl_OncePerSecond LITERAL1 67 | DS3231AlarmOneControl_SecondsMatch LITERAL1 68 | DS3231AlarmOneControl_MinutesSecondsMatch LITERAL1 69 | DS3231AlarmOneControl_HoursMinutesSecondsMatch LITERAL1 70 | DS3231AlarmOneControl_HoursMinutesSecondsDayOfWeekMatch LITERAL1 71 | DS3231AlarmTwoControl_HoursMinutesDayOfMonthMatch LITERAL1 72 | DS3231AlarmTwoControl_OncePerMinute LITERAL1 73 | DS3231AlarmTwoControl_MinutesMatch LITERAL1 74 | DS3231AlarmTwoControl_HoursMinutesMatch LITERAL1 75 | DS3231AlarmTwoControl_HoursMinutesDayOfWeekMatch LITERAL1 76 | DS3231AlarmFlag_Alarm1 LITERAL1 77 | DS3231AlarmFlag_Alarm2 LITERAL1 78 | DS3231AlarmFlag_AlarmBoth LITERAL1 79 | DS1307SquareWaveOut_1Hz LITERAL1 80 | DS1307SquareWaveOut_4kHz LITERAL1 81 | DS1307SquareWaveOut_8kHz LITERAL1 82 | DS1307SquareWaveOut_32kHz LITERAL1 83 | DS1307SquareWaveOut_High LITERAL1 84 | DS1307SquareWaveOut_Low LITERAL1 85 | -------------------------------------------------------------------------------- /libraries/WiFiManager/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 tzapu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /libraries/WiFiManager/examples/AutoConnect/AutoConnect.ino: -------------------------------------------------------------------------------- 1 | #include //https://github.com/esp8266/Arduino 2 | 3 | //needed for library 4 | #include 5 | #include 6 | #include //https://github.com/tzapu/WiFiManager 7 | 8 | 9 | void setup() { 10 | // put your setup code here, to run once: 11 | Serial.begin(115200); 12 | 13 | //WiFiManager 14 | //Local intialization. Once its business is done, there is no need to keep it around 15 | WiFiManager wifiManager; 16 | //reset saved settings 17 | //wifiManager.resetSettings(); 18 | 19 | //set custom ip for portal 20 | //wifiManager.setAPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); 21 | 22 | //fetches ssid and pass from eeprom and tries to connect 23 | //if it does not connect it starts an access point with the specified name 24 | //here "AutoConnectAP" 25 | //and goes into a blocking loop awaiting configuration 26 | wifiManager.autoConnect("AutoConnectAP"); 27 | //or use this for auto generated name ESP + ChipID 28 | //wifiManager.autoConnect(); 29 | 30 | 31 | //if you get here you have connected to the WiFi 32 | Serial.println("connected...yeey :)"); 33 | } 34 | 35 | void loop() { 36 | // put your main code here, to run repeatedly: 37 | 38 | } 39 | -------------------------------------------------------------------------------- /libraries/WiFiManager/examples/AutoConnectWithFeedback/AutoConnectWithFeedback.ino: -------------------------------------------------------------------------------- 1 | #include //https://github.com/esp8266/Arduino 2 | 3 | //needed for library 4 | #include 5 | #include 6 | #include "WiFiManager.h" //https://github.com/tzapu/WiFiManager 7 | 8 | void configModeCallback (WiFiManager *myWiFiManager) { 9 | Serial.println("Entered config mode"); 10 | Serial.println(WiFi.softAPIP()); 11 | //if you used auto generated SSID, print it 12 | Serial.println(myWiFiManager->getConfigPortalSSID()); 13 | } 14 | 15 | void setup() { 16 | // put your setup code here, to run once: 17 | Serial.begin(115200); 18 | 19 | //WiFiManager 20 | //Local intialization. Once its business is done, there is no need to keep it around 21 | WiFiManager wifiManager; 22 | //reset settings - for testing 23 | //wifiManager.resetSettings(); 24 | 25 | //set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode 26 | wifiManager.setAPCallback(configModeCallback); 27 | 28 | //fetches ssid and pass and tries to connect 29 | //if it does not connect it starts an access point with the specified name 30 | //here "AutoConnectAP" 31 | //and goes into a blocking loop awaiting configuration 32 | if(!wifiManager.autoConnect()) { 33 | Serial.println("failed to connect and hit timeout"); 34 | //reset and try again, or maybe put it to deep sleep 35 | ESP.reset(); 36 | delay(1000); 37 | } 38 | 39 | //if you get here you have connected to the WiFi 40 | Serial.println("connected...yeey :)"); 41 | 42 | } 43 | 44 | void loop() { 45 | // put your main code here, to run repeatedly: 46 | 47 | } 48 | -------------------------------------------------------------------------------- /libraries/WiFiManager/examples/AutoConnectWithFeedbackLED/AutoConnectWithFeedbackLED.ino: -------------------------------------------------------------------------------- 1 | #include //https://github.com/esp8266/Arduino 2 | 3 | //needed for library 4 | #include 5 | #include 6 | #include //https://github.com/tzapu/WiFiManager 7 | 8 | //for LED status 9 | #include 10 | Ticker ticker; 11 | 12 | void tick() 13 | { 14 | //toggle state 15 | int state = digitalRead(BUILTIN_LED); // get the current state of GPIO1 pin 16 | digitalWrite(BUILTIN_LED, !state); // set pin to the opposite state 17 | } 18 | 19 | //gets called when WiFiManager enters configuration mode 20 | void configModeCallback (WiFiManager *myWiFiManager) { 21 | Serial.println("Entered config mode"); 22 | Serial.println(WiFi.softAPIP()); 23 | //if you used auto generated SSID, print it 24 | Serial.println(myWiFiManager->getConfigPortalSSID()); 25 | //entered config mode, make led toggle faster 26 | ticker.attach(0.2, tick); 27 | } 28 | 29 | void setup() { 30 | // put your setup code here, to run once: 31 | Serial.begin(115200); 32 | 33 | //set led pin as output 34 | pinMode(BUILTIN_LED, OUTPUT); 35 | // start ticker with 0.5 because we start in AP mode and try to connect 36 | ticker.attach(0.6, tick); 37 | 38 | //WiFiManager 39 | //Local intialization. Once its business is done, there is no need to keep it around 40 | WiFiManager wifiManager; 41 | //reset settings - for testing 42 | //wifiManager.resetSettings(); 43 | 44 | //set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode 45 | wifiManager.setAPCallback(configModeCallback); 46 | 47 | //fetches ssid and pass and tries to connect 48 | //if it does not connect it starts an access point with the specified name 49 | //here "AutoConnectAP" 50 | //and goes into a blocking loop awaiting configuration 51 | if (!wifiManager.autoConnect()) { 52 | Serial.println("failed to connect and hit timeout"); 53 | //reset and try again, or maybe put it to deep sleep 54 | ESP.reset(); 55 | delay(1000); 56 | } 57 | 58 | //if you get here you have connected to the WiFi 59 | Serial.println("connected...yeey :)"); 60 | ticker.detach(); 61 | //keep LED on 62 | digitalWrite(BUILTIN_LED, LOW); 63 | } 64 | 65 | void loop() { 66 | // put your main code here, to run repeatedly: 67 | 68 | } 69 | -------------------------------------------------------------------------------- /libraries/WiFiManager/examples/AutoConnectWithReset/AutoConnectWithReset.ino: -------------------------------------------------------------------------------- 1 | #include //this needs to be first, or it all crashes and burns... 2 | 3 | #include //https://github.com/esp8266/Arduino 4 | 5 | //needed for library 6 | #include 7 | #include 8 | #include //https://github.com/tzapu/WiFiManager 9 | 10 | void setup() { 11 | // put your setup code here, to run once: 12 | Serial.begin(115200); 13 | Serial.println(); 14 | 15 | //WiFiManager 16 | //Local intialization. Once its business is done, there is no need to keep it around 17 | WiFiManager wifiManager; 18 | 19 | //exit after config instead of connecting 20 | wifiManager.setBreakAfterConfig(true); 21 | 22 | //reset settings - for testing 23 | //wifiManager.resetSettings(); 24 | 25 | 26 | //tries to connect to last known settings 27 | //if it does not connect it starts an access point with the specified name 28 | //here "AutoConnectAP" with password "password" 29 | //and goes into a blocking loop awaiting configuration 30 | if (!wifiManager.autoConnect("AutoConnectAP", "password")) { 31 | Serial.println("failed to connect, we should reset as see if it connects"); 32 | delay(3000); 33 | ESP.reset(); 34 | delay(5000); 35 | } 36 | 37 | //if you get here you have connected to the WiFi 38 | Serial.println("connected...yeey :)"); 39 | 40 | 41 | Serial.println("local ip"); 42 | Serial.println(WiFi.localIP()); 43 | } 44 | 45 | void loop() { 46 | // put your main code here, to run repeatedly: 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /libraries/WiFiManager/examples/AutoConnectWithStaticIP/AutoConnectWithStaticIP.ino: -------------------------------------------------------------------------------- 1 | #include //this needs to be first, or it all crashes and burns... 2 | 3 | #include //https://github.com/esp8266/Arduino 4 | 5 | //needed for library 6 | #include 7 | #include 8 | #include //https://github.com/tzapu/WiFiManager 9 | 10 | 11 | /************************************************************************************** 12 | * this example shows how to set a static IP configuration for the ESP 13 | * although the IP shows in the config portal, the changes will revert 14 | * to the IP set in the source file. 15 | * if you want the ability to configure and persist the new IP configuration 16 | * look at the FS examples, which save the config to file 17 | *************************************************************************************/ 18 | 19 | 20 | 21 | //default custom static IP 22 | //char static_ip[16] = "10.0.1.59"; 23 | //char static_gw[16] = "10.0.1.1"; 24 | //char static_sn[16] = "255.255.255.0"; 25 | 26 | void setup() { 27 | // put your setup code here, to run once: 28 | Serial.begin(115200); 29 | Serial.println(); 30 | 31 | //WiFiManager 32 | //Local intialization. Once its business is done, there is no need to keep it around 33 | WiFiManager wifiManager; 34 | 35 | //reset settings - for testing 36 | //wifiManager.resetSettings(); 37 | 38 | //set static ip 39 | //the commented bit only works for ESP8266 core 2.1.0 or newer 40 | /*IPAddress _ip,_gw,_sn; 41 | _ip.fromString(static_ip); 42 | _gw.fromString(static_gw); 43 | _sn.fromString(static_sn); 44 | */ 45 | IPAddress _ip = IPAddress(10, 0, 1, 78); 46 | IPAddress _gw = IPAddress(10, 0, 1, 1); 47 | IPAddress _sn = IPAddress(255, 255, 255, 0); 48 | 49 | wifiManager.setSTAStaticIPConfig(_ip, _gw, _sn); 50 | 51 | 52 | //tries to connect to last known settings 53 | //if it does not connect it starts an access point with the specified name 54 | //here "AutoConnectAP" with password "password" 55 | //and goes into a blocking loop awaiting configuration 56 | if (!wifiManager.autoConnect("AutoConnectAP", "password")) { 57 | Serial.println("failed to connect, we should reset as see if it connects"); 58 | delay(3000); 59 | ESP.reset(); 60 | delay(5000); 61 | } 62 | 63 | //if you get here you have connected to the WiFi 64 | Serial.println("connected...yeey :)"); 65 | 66 | 67 | Serial.println("local ip"); 68 | Serial.println(WiFi.localIP()); 69 | } 70 | 71 | void loop() { 72 | // put your main code here, to run repeatedly: 73 | 74 | 75 | } 76 | -------------------------------------------------------------------------------- /libraries/WiFiManager/examples/AutoConnectWithTimeout/AutoConnectWithTimeout.ino: -------------------------------------------------------------------------------- 1 | #include //https://github.com/esp8266/Arduino 2 | 3 | //needed for library 4 | #include 5 | #include 6 | #include //https://github.com/tzapu/WiFiManager 7 | 8 | 9 | 10 | void setup() { 11 | // put your setup code here, to run once: 12 | Serial.begin(115200); 13 | 14 | //WiFiManager 15 | //Local intialization. Once its business is done, there is no need to keep it around 16 | WiFiManager wifiManager; 17 | //reset settings - for testing 18 | //wifiManager.resetSettings(); 19 | 20 | //sets timeout until configuration portal gets turned off 21 | //useful to make it all retry or go to sleep 22 | //in seconds 23 | wifiManager.setTimeout(180); 24 | 25 | //fetches ssid and pass and tries to connect 26 | //if it does not connect it starts an access point with the specified name 27 | //here "AutoConnectAP" 28 | //and goes into a blocking loop awaiting configuration 29 | if(!wifiManager.autoConnect("AutoConnectAP")) { 30 | Serial.println("failed to connect and hit timeout"); 31 | delay(3000); 32 | //reset and try again, or maybe put it to deep sleep 33 | ESP.reset(); 34 | delay(5000); 35 | } 36 | 37 | //if you get here you have connected to the WiFi 38 | Serial.println("connected...yeey :)"); 39 | 40 | } 41 | 42 | void loop() { 43 | // put your main code here, to run repeatedly: 44 | 45 | } 46 | -------------------------------------------------------------------------------- /libraries/WiFiManager/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino: -------------------------------------------------------------------------------- 1 | #include //https://github.com/esp8266/Arduino 2 | 3 | //needed for library 4 | #include 5 | #include 6 | #include //https://github.com/tzapu/WiFiManager 7 | 8 | // select wich pin will trigger the configuraton portal when set to LOW 9 | // ESP-01 users please note: the only pins available (0 and 2), are shared 10 | // with the bootloader, so always set them HIGH at power-up 11 | #define TRIGGER_PIN 0 12 | 13 | 14 | void setup() { 15 | // put your setup code here, to run once: 16 | Serial.begin(115200); 17 | Serial.println("\n Starting"); 18 | 19 | pinMode(TRIGGER_PIN, INPUT); 20 | } 21 | 22 | 23 | void loop() { 24 | // is configuration portal requested? 25 | if ( digitalRead(TRIGGER_PIN) == LOW ) { 26 | //WiFiManager 27 | //Local intialization. Once its business is done, there is no need to keep it around 28 | WiFiManager wifiManager; 29 | 30 | //reset settings - for testing 31 | //wifiManager.resetSettings(); 32 | 33 | //sets timeout until configuration portal gets turned off 34 | //useful to make it all retry or go to sleep 35 | //in seconds 36 | //wifiManager.setTimeout(120); 37 | 38 | //it starts an access point with the specified name 39 | //here "AutoConnectAP" 40 | //and goes into a blocking loop awaiting configuration 41 | 42 | //WITHOUT THIS THE AP DOES NOT SEEM TO WORK PROPERLY WITH SDK 1.5 , update to at least 1.5.1 43 | //WiFi.mode(WIFI_STA); 44 | 45 | if (!wifiManager.startConfigPortal("OnDemandAP")) { 46 | Serial.println("failed to connect and hit timeout"); 47 | delay(3000); 48 | //reset and try again, or maybe put it to deep sleep 49 | ESP.reset(); 50 | delay(5000); 51 | } 52 | 53 | //if you get here you have connected to the WiFi 54 | Serial.println("connected...yeey :)"); 55 | } 56 | 57 | 58 | // put your main code here, to run repeatedly: 59 | 60 | } 61 | -------------------------------------------------------------------------------- /libraries/WiFiManager/extras/WiFiManager.template.html: -------------------------------------------------------------------------------- 1 | {v} 2 | 3 | 4 | 5 |
6 | 14 | 15 | 19 | 20 |
{v} {r}%
21 |
PMisa 100%
22 | 23 |
PMisa 8%
24 | 25 | 26 | 27 |
28 | 29 | 30 |


31 |
32 |
33 |

34 |
35 |
36 | 37 |
38 | -------------------------------------------------------------------------------- /libraries/WiFiManager/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For WifiManager 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | WiFiManager KEYWORD1 10 | WiFiManagerParameter KEYWORD1 11 | 12 | 13 | ####################################### 14 | # Methods and Functions (KEYWORD2) 15 | ####################################### 16 | autoConnect KEYWORD2 17 | getSSID KEYWORD2 18 | getPassword KEYWORD2 19 | getConfigPortalSSID KEYWORD2 20 | resetSettings KEYWORD2 21 | setConfigPortalTimeout KEYWORD2 22 | setConnectTimeout KEYWORD2 23 | setDebugOutput KEYWORD2 24 | setMinimumSignalQuality KEYWORD2 25 | setAPStaticIPConfig KEYWORD2 26 | setSTAStaticIPConfig KEYWORD2 27 | setAPCallback KEYWORD2 28 | setSaveConfigCallback KEYWORD2 29 | addParameter KEYWORD2 30 | getID KEYWORD2 31 | getValue KEYWORD2 32 | getPlaceholder KEYWORD2 33 | getValueLength KEYWORD2 34 | 35 | ####################################### 36 | # Constants (LITERAL1) 37 | ####################################### 38 | 39 | # LITERAL1 40 | -------------------------------------------------------------------------------- /libraries/WiFiManager/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "WifiManager", 3 | "keywords": "wifi, wi-fi", 4 | "description": "ESP8266 WiFi Connection manager with fallback web configuration portal", 5 | "repository": 6 | { 7 | "type": "git", 8 | "url": "https://github.com/tzapu/WiFiManager.git" 9 | }, 10 | "frameworks": "arduino", 11 | "platforms": "espressif", 12 | "version": "0.12" 13 | } 14 | -------------------------------------------------------------------------------- /libraries/WiFiManager/library.properties: -------------------------------------------------------------------------------- 1 | name=WiFiManager 2 | version=0.12 3 | author=tzapu 4 | maintainer=tzapu 5 | sentence=ESP8266 WiFi Connection manager with fallback web configuration portal 6 | paragraph=Library for configuring ESP8266 modules WiFi credentials at runtime. 7 | category=Communication 8 | url=https://github.com/tzapu/WiFiManager.git 9 | architectures=esp8266 10 | -------------------------------------------------------------------------------- /libraries/WiFiManager/travis/common.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function build_examples() 4 | { 5 | # track the exit code for this platform 6 | local exit_code=0 7 | # loop through results and add them to the array 8 | examples=($(find $PWD/examples/ -name "*.pde" -o -name "*.ino")) 9 | 10 | # get the last example in the array 11 | local last="${examples[@]:(-1)}" 12 | 13 | # loop through example sketches 14 | for example in "${examples[@]}"; do 15 | 16 | # store the full path to the example's sketch directory 17 | local example_dir=$(dirname $example) 18 | 19 | # store the filename for the example without the path 20 | local example_file=$(basename $example) 21 | 22 | echo "$example_file: " 23 | local sketch="$example_dir/$example_file" 24 | echo "$sketch" 25 | #arduino -v --verbose-build --verify $sketch 26 | 27 | # verify the example, and save stdout & stderr to a variable 28 | # we have to avoid reading the exit code of local: 29 | # "when declaring a local variable in a function, the local acts as a command in its own right" 30 | local build_stdout 31 | build_stdout=$(arduino --verify $sketch 2>&1) 32 | 33 | # echo output if the build failed 34 | if [ $? -ne 0 ]; then 35 | # heavy X 36 | echo -e "\xe2\x9c\x96" 37 | echo -e "----------------------------- DEBUG OUTPUT -----------------------------\n" 38 | echo "$build_stdout" 39 | echo -e "\n------------------------------------------------------------------------\n" 40 | 41 | # mark as fail 42 | exit_code=1 43 | 44 | else 45 | # heavy checkmark 46 | echo -e "\xe2\x9c\x93" 47 | fi 48 | done 49 | 50 | return $exit_code 51 | } 52 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *# 3 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/CHANGES.txt: -------------------------------------------------------------------------------- 1 | 1.9 2 | * Do not split MQTT packets over multiple calls to _client->write() 3 | * API change: All constructors now require an instance of Client 4 | to be passed in. 5 | * Fixed example to match 1.8 api changes - dpslwk 6 | * Added username/password support - WilHall 7 | * Added publish_P - publishes messages from PROGMEM - jobytaffey 8 | 9 | 1.8 10 | * KeepAlive interval is configurable in PubSubClient.h 11 | * Maximum packet size is configurable in PubSubClient.h 12 | * API change: Return boolean rather than int from various functions 13 | * API change: Length parameter in message callback changed 14 | from int to unsigned int 15 | * Various internal tidy-ups around types 16 | 1.7 17 | * Improved keepalive handling 18 | * Updated to the Arduino-1.0 API 19 | 1.6 20 | * Added the ability to publish a retained message 21 | 22 | 1.5 23 | * Added default constructor 24 | * Fixed compile error when used with arduino-0021 or later 25 | 26 | 1.4 27 | * Fixed connection lost handling 28 | 29 | 1.3 30 | * Fixed packet reading bug in PubSubClient.readPacket 31 | 32 | 1.2 33 | * Fixed compile error when used with arduino-0016 or later 34 | 35 | 36 | 1.1 37 | * Reduced size of library 38 | * Added support for Will messages 39 | * Clarified licensing - see LICENSE.txt 40 | 41 | 42 | 1.0 43 | * Only Quality of Service (QOS) 0 messaging is supported 44 | * The maximum message size, including header, is 128 bytes 45 | * The keepalive interval is set to 30 seconds 46 | * No support for Will messages 47 | 48 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2008-2012 Nicholas O'Leary 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/README: -------------------------------------------------------------------------------- 1 | A client library for the ESP8266 (using the Arduino environment) that provides support for MQTT. 2 | 3 | Modified from Nicholas O'Leary's original for the Arduino + Ethernet shield: 4 | http://knolleary.net/arduino-client-for-mqtt/ 5 | 6 | See here for the ESP8266-Arduino work: 7 | https://github.com/esp8266/Arduino 8 | 9 | New features 10 | ------------ 11 | 12 | A whole set of MQTT classes has been added, one for each message type. 13 | This moved a good amount of code out of the PubSubClient class, leaving it to 14 | handle the high-level flow of the protocol. The MQTT classes handle getting 15 | data into and out of the messages. 16 | 17 | The PubSubClient class operates mostly as it did before. However, the 18 | connect(), publish(), subscribe(), and unsubscribe() methods can now take an 19 | appropriate MQTT object. This allows extra options to be set e.g QoS on 20 | publish, or multiple topics with one (un)subscribe message. 21 | 22 | You can use the MQTT classes and their chainable setter methods like this: 23 | 24 | client.connect(MQTT::Connect("clientId") 25 | .set_clean_session() 26 | .set_will("status", "down") 27 | .set_auth("username", "password) 28 | .set_keepalive(30) 29 | ); 30 | 31 | client.publish(MQTT::Publish("topic", "payload") 32 | .set_retain() 33 | .set_qos(1, client.next_packet_id()) 34 | .set_dup() 35 | ); 36 | 37 | client.subscribe(MQTT::Subscribe(client.next_packet_id()) 38 | .add_topic("topic1") 39 | .add_topic("topic2", 1) // optional qos value 40 | ); 41 | 42 | client.unsubscribe(MQTT::Unsubscribe(client.next_packet_id()) 43 | .add_topic("topic") 44 | ); 45 | 46 | See also the mqtt_auth or mqtt_qos example sketches for how this is used. 47 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/examples/mqtt_auth/mqtt_auth.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Basic MQTT example with Authentication 3 | 4 | - connects to an MQTT server, providing username 5 | and password 6 | - publishes "hello world" to the topic "outTopic" 7 | - subscribes to the topic "inTopic" 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | const char *ssid = "xxxxxxxx"; // cannot be longer than 32 characters! 14 | const char *pass = "yyyyyyyy"; // 15 | 16 | // Update these with values suitable for your network. 17 | IPAddress server(172, 16, 0, 2); 18 | 19 | void callback(const MQTT::Publish& pub) { 20 | // handle message arrived 21 | } 22 | 23 | PubSubClient client(server); 24 | 25 | void setup() 26 | { 27 | // Setup console 28 | Serial.begin(115200); 29 | delay(10); 30 | Serial.println(); 31 | Serial.println(); 32 | 33 | client.set_callback(callback); 34 | 35 | WiFi.begin(ssid, pass); 36 | 37 | int retries = 0; 38 | while ((WiFi.status() != WL_CONNECTED) && (retries < 10)) { 39 | retries++; 40 | delay(500); 41 | Serial.print("."); 42 | } 43 | if (WiFi.status() == WL_CONNECTED) { 44 | Serial.println(""); 45 | Serial.println("WiFi connected"); 46 | } 47 | 48 | if (client.connect(MQTT::Connect("arduinoClient") 49 | .set_auth("testeruser", "testpass"))) { 50 | client.publish("outTopic","hello world"); 51 | client.subscribe("inTopic"); 52 | } 53 | } 54 | 55 | void loop() 56 | { 57 | client.loop(); 58 | } 59 | 60 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/examples/mqtt_basic/mqtt_basic.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Basic MQTT example 3 | 4 | - connects to an MQTT server 5 | - publishes "hello world" to the topic "outTopic" 6 | - subscribes to the topic "inTopic" 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | const char *ssid = "xxxxxxxx"; // cannot be longer than 32 characters! 13 | const char *pass = "yyyyyyyy"; // 14 | 15 | // Update these with values suitable for your network. 16 | IPAddress server(172, 16, 0, 2); 17 | 18 | void callback(const MQTT::Publish& pub) { 19 | // handle message arrived 20 | } 21 | 22 | PubSubClient client(server); 23 | 24 | void setup() 25 | { 26 | // Setup console 27 | Serial.begin(115200); 28 | delay(10); 29 | Serial.println(); 30 | Serial.println(); 31 | 32 | client.set_callback(callback); 33 | 34 | WiFi.begin(ssid, pass); 35 | 36 | int retries = 0; 37 | while ((WiFi.status() != WL_CONNECTED) && (retries < 10)) { 38 | retries++; 39 | delay(500); 40 | Serial.print("."); 41 | } 42 | if (WiFi.status() == WL_CONNECTED) { 43 | Serial.println(""); 44 | Serial.println("WiFi connected"); 45 | } 46 | 47 | if (client.connect("arduinoClient")) { 48 | client.publish("outTopic","hello world"); 49 | client.subscribe("inTopic"); 50 | } 51 | } 52 | 53 | void loop() 54 | { 55 | client.loop(); 56 | } 57 | 58 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/examples/mqtt_publish_in_callback/mqtt_publish_in_callback.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Publishing in the callback 3 | 4 | - connects to an MQTT server 5 | - subscribes to the topic "inTopic" 6 | - when a message is received, republishes it to "outTopic" 7 | 8 | This example shows how to publish messages within the 9 | callback function. The callback function header needs to 10 | be declared before the PubSubClient constructor and the 11 | actual callback defined afterwards. 12 | This ensures the client reference in the callback function 13 | is valid. 14 | 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | const char *ssid = "xxxxxxxx"; // cannot be longer than 32 characters! 21 | const char *pass = "yyyyyyyy"; // 22 | 23 | // Update these with values suitable for your network. 24 | IPAddress server(172, 16, 0, 2); 25 | 26 | PubSubClient client(server); 27 | 28 | // Callback function 29 | void callback(const MQTT::Publish& pub) { 30 | // In order to republish this payload, a copy must be made 31 | // as the orignal payload buffer will be overwritten whilst 32 | // constructing the PUBLISH packet. 33 | 34 | // Copy the payload to a new message 35 | MQTT::Publish newpub("outTopic", pub.payload(), pub.payload_len()); 36 | client.publish(newpub); 37 | } 38 | 39 | void setup() 40 | { 41 | // Setup console 42 | Serial.begin(115200); 43 | delay(10); 44 | Serial.println(); 45 | Serial.println(); 46 | 47 | client.set_callback(callback); 48 | 49 | WiFi.begin(ssid, pass); 50 | 51 | int retries = 0; 52 | while ((WiFi.status() != WL_CONNECTED) && (retries < 10)) { 53 | retries++; 54 | delay(500); 55 | Serial.print("."); 56 | } 57 | if (WiFi.status() == WL_CONNECTED) { 58 | Serial.println(""); 59 | Serial.println("WiFi connected"); 60 | } 61 | 62 | if (client.connect("arduinoClient")) { 63 | client.publish("outTopic","hello world"); 64 | client.subscribe("inTopic"); 65 | } 66 | } 67 | 68 | void loop() 69 | { 70 | client.loop(); 71 | } 72 | 73 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/examples/mqtt_qos/mqtt_qos.ino: -------------------------------------------------------------------------------- 1 | /* 2 | MQTT with QoS example 3 | 4 | - connects to an MQTT server 5 | - publishes "hello world" to the topic "outTopic" with a variety of QoS values 6 | 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | const char *ssid = "xxxxxxxx"; // cannot be longer than 32 characters! 13 | const char *pass = "yyyyyyyy"; // 14 | 15 | // Update these with values suitable for your network. 16 | IPAddress server(172, 16, 0, 2); 17 | 18 | void callback(const MQTT::Publish& pub) { 19 | // handle message arrived 20 | } 21 | 22 | PubSubClient client(server); 23 | 24 | void setup() 25 | { 26 | // Setup console 27 | Serial.begin(115200); 28 | delay(10); 29 | Serial.println(); 30 | Serial.println(); 31 | 32 | client.set_callback(callback); 33 | 34 | WiFi.begin(ssid, pass); 35 | 36 | int retries = 0; 37 | while ((WiFi.status() != WL_CONNECTED) && (retries < 10)) { 38 | retries++; 39 | delay(500); 40 | Serial.print("."); 41 | } 42 | if (WiFi.status() == WL_CONNECTED) { 43 | Serial.println(""); 44 | Serial.println("WiFi connected"); 45 | } 46 | 47 | if (client.connect("arduinoClient")) { 48 | client.publish("outTopic", "hello world qos=0"); // Simple publish with qos=0 49 | 50 | client.publish(MQTT::Publish("outTopic", "hello world qos=1") 51 | .set_qos(1, client.next_packet_id())); 52 | 53 | client.publish(MQTT::Publish("outTopic", "hello world qos=2") 54 | .set_qos(2, client.next_packet_id())); 55 | } 56 | } 57 | 58 | void loop() 59 | { 60 | client.loop(); 61 | } 62 | 63 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/examples/mqtt_stream/mqtt_stream.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Example of using a Stream object to store the message payload 3 | 4 | Uses SRAM library: https://github.com/ennui2342/arduino-sram 5 | but could use any Stream based class such as SD 6 | 7 | - connects to an MQTT server 8 | - publishes "hello world" to the topic "outTopic" 9 | - subscribes to the topic "inTopic" 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | const char *ssid = "xxxxxxxx"; // cannot be longer than 32 characters! 17 | const char *pass = "yyyyyyyy"; // 18 | 19 | // Update these with values suitable for your network. 20 | IPAddress server(172, 16, 0, 2); 21 | 22 | SRAM sram(4, SRAM_1024); 23 | 24 | void callback(const MQTT::Publish& pub) { 25 | sram.seek(1); 26 | 27 | // do something with the message 28 | for (uint8_t i = 0; i < pub.payload_len(); i++) { 29 | sram.write(pub.payload()[i]); 30 | Serial.write(pub.payload()[i]); 31 | } 32 | 33 | Serial.println(); 34 | } 35 | 36 | PubSubClient client(server); 37 | 38 | void setup() 39 | { 40 | // Setup console 41 | Serial.begin(115200); 42 | delay(10); 43 | Serial.println(); 44 | Serial.println(); 45 | 46 | client.set_callback(callback); 47 | 48 | WiFi.begin(ssid, pass); 49 | 50 | int retries = 0; 51 | while ((WiFi.status() != WL_CONNECTED) && (retries < 10)) { 52 | retries++; 53 | delay(500); 54 | Serial.print("."); 55 | } 56 | if (WiFi.status() == WL_CONNECTED) { 57 | Serial.println(""); 58 | Serial.println("WiFi connected"); 59 | } 60 | 61 | if (client.connect("arduinoClient")) { 62 | client.publish("outTopic","hello world"); 63 | client.subscribe("inTopic"); 64 | } 65 | 66 | sram.begin(); 67 | sram.seek(1); 68 | 69 | Serial.begin(9600); 70 | } 71 | 72 | void loop() 73 | { 74 | client.loop(); 75 | } 76 | 77 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/examples/mqtt_subscriber/mqtt_subscriber.ino: -------------------------------------------------------------------------------- 1 | /* 2 | MQTT subscriber example 3 | 4 | - connects to an MQTT server 5 | - subscribes to the topic "inTopic" 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | const char *ssid = "xxxxxxxx"; // cannot be longer than 32 characters! 12 | const char *pass = "yyyyyyyy"; // 13 | 14 | // Update these with values suitable for your network. 15 | IPAddress server(172, 16, 0, 2); 16 | 17 | void callback(const MQTT::Publish& pub) { 18 | Serial.print(pub.topic()); 19 | Serial.print(" => "); 20 | Serial.println(pub.payload_string()); 21 | } 22 | 23 | PubSubClient client(server); 24 | 25 | void setup() 26 | { 27 | // Setup console 28 | Serial.begin(115200); 29 | delay(10); 30 | Serial.println(); 31 | Serial.println(); 32 | 33 | client.set_callback(callback); 34 | 35 | WiFi.begin(ssid, pass); 36 | 37 | int retries = 0; 38 | while ((WiFi.status() != WL_CONNECTED) && (retries < 10)) { 39 | retries++; 40 | delay(500); 41 | Serial.print("."); 42 | } 43 | if (WiFi.status() == WL_CONNECTED) { 44 | Serial.println(""); 45 | Serial.println("WiFi connected"); 46 | } 47 | 48 | if (client.connect("arduinoClient")) { 49 | client.subscribe("inTopic"); 50 | } 51 | } 52 | 53 | void loop() 54 | { 55 | client.loop(); 56 | } 57 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Ultrasound 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | PubSubClient KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | connect KEYWORD2 16 | disconnect KEYWORD2 17 | publish KEYWORD2 18 | subscribe KEYWORD2 19 | loop KEYWORD2 20 | connected KEYWORD2 21 | 22 | ####################################### 23 | # Constants (LITERAL1) 24 | ####################################### 25 | 26 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/library.properties: -------------------------------------------------------------------------------- 1 | name=PubSubClient 2 | version=1.9.1 3 | author=Nick O'Leary, Ian Tester 4 | maintainer=Ian Tester 5 | sentence=A library for communicating with MQTT brokers 6 | paragraph=Supports MQTT 3.1.1 7 | category=Communication 8 | url=http://knolleary.net/arduino-client-for-mqtt/ 9 | architectures=esp8266 -------------------------------------------------------------------------------- /libraries/pubsubclient.old/src/PubSubClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | PubSubClient.h - A simple client for MQTT. 3 | Nicholas O'Leary 4 | http://knolleary.net 5 | */ 6 | 7 | #ifndef PubSubClient_h 8 | #define PubSubClient_h 9 | 10 | #include 11 | #include 12 | 13 | #include "MQTT.h" 14 | 15 | class PubSubClient { 16 | public: 17 | typedef void(*callback_t)(const MQTT::Publish&); 18 | 19 | private: 20 | IPAddress server_ip; 21 | String server_hostname; 22 | uint16_t server_port; 23 | callback_t _callback; 24 | 25 | WiFiClient _client; 26 | uint16_t nextMsgId, keepalive; 27 | uint8_t _max_retries; 28 | unsigned long lastOutActivity; 29 | unsigned long lastInActivity; 30 | bool pingOutstanding; 31 | 32 | // Internal function used by wait_for() and loop() 33 | bool _process_message(MQTT::Message* msg, uint8_t wait_type = 0, uint16_t wait_pid = 0); 34 | 35 | // Wait for a certain type of packet to come back, optionally check its packet id 36 | bool wait_for(uint8_t wait_type, uint16_t wait_pid = 0); 37 | 38 | bool send_reliably(MQTT::Message* msg); 39 | 40 | public: 41 | // Empty constructor - use set_server() later, before connect() 42 | PubSubClient(); 43 | 44 | // Constructors with the server ip address or host name 45 | PubSubClient(IPAddress &ip, uint16_t port = 1883); 46 | PubSubClient(String hostname, uint16_t port = 1883); 47 | 48 | // Set the server ip address or host name 49 | PubSubClient& set_server(IPAddress &ip, uint16_t port = 1883); 50 | PubSubClient& set_server(String hostname, uint16_t port = 1883); 51 | 52 | // Get or set the callback function 53 | callback_t callback(void) const { return _callback; } 54 | PubSubClient& set_callback(callback_t cb) { _callback = cb; return *this; } 55 | PubSubClient& unset_callback(void) { _callback = NULL; return * this; } 56 | 57 | // Set the maximum number of retries when waiting for response packets 58 | PubSubClient& set_max_retries(uint8_t mr) { _max_retries = mr; return *this; } 59 | 60 | // Connect to the server with a client id 61 | bool connect(String id); 62 | 63 | // Connect to the server with a client id and "will" parameters 64 | bool connect(String id, String willTopic, uint8_t willQos, bool willRetain, String willMessage); 65 | 66 | // Disconnect from the server 67 | void disconnect(void); 68 | 69 | // Publish a string payload 70 | bool publish(String topic, String payload); 71 | 72 | // Publish an arbitrary data payload 73 | bool publish(String topic, const uint8_t *payload, unsigned int plength, bool retained = false); 74 | 75 | // Publish an arbitrary data payload stored in "program memory" 76 | bool publish_P(String topic, PGM_P payload, unsigned int, bool retained = false); 77 | 78 | // Subscribe to a topic 79 | bool subscribe(String topic, uint8_t qos = 0); 80 | 81 | // Unsubscribe from a topic 82 | bool unsubscribe(String topic); 83 | 84 | // Wait for packets to come in, processing them 85 | // Also periodically pings the server 86 | bool loop(); 87 | 88 | // Are we connected? 89 | bool connected(); 90 | 91 | // Return the next packet id 92 | // Needed for constructing our own publish (with QoS>0) or (un)subscribe messages 93 | uint16_t next_packet_id(void) { 94 | nextMsgId++; 95 | if (nextMsgId == 0) nextMsgId = 1; 96 | return nextMsgId; 97 | } 98 | 99 | // New methods that take pre-constructed MQTT message objects 100 | bool connect(MQTT::Connect &conn); 101 | bool publish(MQTT::Publish &pub); 102 | bool subscribe(MQTT::Subscribe &sub); 103 | bool unsubscribe(MQTT::Unsubscribe &unsub); 104 | }; 105 | 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/tests/.gitignore: -------------------------------------------------------------------------------- 1 | .build 2 | tmpbin 3 | logs 4 | *.pyc 5 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/tests/Makefile: -------------------------------------------------------------------------------- 1 | SRC_PATH=./src 2 | OUT_PATH=./bin 3 | TEST_SRC=$(wildcard ${SRC_PATH}/*_spec.cpp) 4 | TEST_BIN= $(TEST_SRC:${SRC_PATH}/%.cpp=${OUT_PATH}/%) 5 | VPATH=${SRC_PATH} 6 | SHIM_FILES=${SRC_PATH}/lib/*.cpp 7 | PSC_FILE=../PubSubClient/PubSubClient.cpp 8 | CC=g++ 9 | CFLAGS=-I${SRC_PATH}/lib -I../PubSubClient 10 | 11 | all: $(TEST_BIN) 12 | 13 | ${OUT_PATH}/%: ${SRC_PATH}/%.cpp ${PSC_FILE} ${SHIM_FILES} 14 | mkdir -p ${OUT_PATH} 15 | ${CC} ${CFLAGS} $^ -o $@ 16 | 17 | clean: 18 | @rm -rf ${OUT_PATH} 19 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/tests/README.md: -------------------------------------------------------------------------------- 1 | # Arduino Client for MQTT Test Suite 2 | 3 | This is a regression test suite for the `PubSubClient` library. 4 | 5 | There are two parts: 6 | 7 | - Tests that can be compiled and run on any machine 8 | - Tests that build the example sketches using the Arduino IDE 9 | 10 | 11 | It is a work-in-progress and is subject to complete refactoring as the whim takes 12 | me. 13 | 14 | 15 | ## Local tests 16 | 17 | These are a set of executables that can be run to test specific areas of functionality. 18 | They do not require a real Arduino to be attached, nor the use of the Arduino IDE. 19 | 20 | The tests include a set of mock files to stub out the parts of the Arduino environment the library 21 | depends on. 22 | 23 | ### Dependencies 24 | 25 | - g++ 26 | 27 | ### Running 28 | 29 | Build the tests using the provided `Makefile`: 30 | 31 | $ make 32 | 33 | This will create a set of executables in `./bin/`. Run each of these executables to test the corresponding functionality. 34 | 35 | *Note:* the `connect_spec` and `keepalive_spec` tests involve testing keepalive timers so naturally take a few minutes to run through. 36 | 37 | ## Arduino tests 38 | 39 | *Note:* INO Tool doesn't currently play nicely with Arduino 1.5. This has broken this test suite. 40 | 41 | Without a suitable arduino plugged in, the test suite will only check the 42 | example sketches compile cleanly against the library. 43 | 44 | With an arduino plugged in, each sketch that has a corresponding python 45 | test case is built, uploaded and then the tests run. 46 | 47 | ### Dependencies 48 | 49 | - Python 2.7+ 50 | - [INO Tool](http://inotool.org/) - this provides command-line build/upload of Arduino sketches 51 | 52 | ### Running 53 | 54 | The test suite _does not_ run an MQTT server - it is assumed to be running already. 55 | 56 | $ python testsuite.py 57 | 58 | A summary of activity is printed to the console. More comprehensive logs are written 59 | to the `logs` directory. 60 | 61 | ### What it does 62 | 63 | For each sketch in the library's `examples` directory, e.g. `mqtt_basic.ino`, the suite looks for a matching test case 64 | `testcases/mqtt_basic.py`. 65 | 66 | The test case must follow these conventions: 67 | - sub-class `unittest.TestCase` 68 | - provide the class methods `setUpClass` and `tearDownClass` (TODO: make this optional) 69 | - all test method names begin with `test_` 70 | 71 | The suite will call the `setUpClass` method _before_ uploading the sketch. This 72 | allows any test setup to be performed before the sketch runs - such as connecting 73 | a client and subscribing to topics. 74 | 75 | 76 | ### Settings 77 | 78 | The file `testcases/settings.py` is used to config the test environment. 79 | 80 | - `server_ip` - the IP address of the broker the client should connect to (the broker port is assumed to be 1883). 81 | - `arduino_ip` - the IP address the arduino should use (when not testing DHCP). 82 | 83 | Before each sketch is compiled, these values are automatically substituted in. To 84 | do this, the suite looks for lines that _start_ with the following: 85 | 86 | byte server[] = { 87 | byte ip[] = { 88 | 89 | and replaces them with the appropriate values. 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/tests/src/lib/Arduino.h: -------------------------------------------------------------------------------- 1 | #ifndef Arduino_h 2 | #define Arduino_h 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | extern "C"{ 11 | typedef uint8_t byte ; 12 | typedef uint8_t boolean ; 13 | 14 | /* sketch */ 15 | extern void setup( void ) ; 16 | extern void loop( void ) ; 17 | uint32_t millis( void ); 18 | } 19 | 20 | #define PROGMEM 21 | #define pgm_read_byte_near(x) *(x) 22 | 23 | #endif // Arduino_h 24 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/tests/src/lib/BDDTest.cpp: -------------------------------------------------------------------------------- 1 | #include "BDDTest.h" 2 | #include "trace.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int testCount = 0; 9 | int testPasses = 0; 10 | const char* testDescription; 11 | 12 | std::list failureList; 13 | 14 | int bddtest_test(const char* file, int line, const char* assertion, int result) { 15 | if (!result) { 16 | LOG("F"); 17 | std::ostringstream os; 18 | os << " ! "<::iterator it = failureList.begin(); it != failureList.end(); it++) { 36 | LOG("\n"); 37 | LOG(*it); 38 | } 39 | LOG("\n" << std::dec << testPasses << "/" << testCount << " tests passed\n"); 40 | if (testPasses == testCount) { 41 | return 0; 42 | } 43 | return 1; 44 | } 45 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/tests/src/lib/BDDTest.h: -------------------------------------------------------------------------------- 1 | #ifndef bddtest_h 2 | #define bddtest_h 3 | 4 | int bddtest_test(const char*, int, const char*, int); 5 | void bddtest_start(const char*); 6 | void bddtest_end(); 7 | int bddtest_summary(); 8 | 9 | #define TEST(x) { if (!bddtest_test(__FILE__, __LINE__, #x, (x))) return false; } 10 | 11 | #define IT(x) { bddtest_start(x); } 12 | #define END_IT { bddtest_end();return true;} 13 | 14 | #define FINISH { return bddtest_summary(); } 15 | 16 | #define IS_TRUE(x) TEST(x) 17 | #define IS_FALSE(x) TEST(!(x)) 18 | #define IS_EQUAL(x,y) TEST(x==y) 19 | #define IS_NOT_EQUAL(x,y) TEST(x!=y) 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/tests/src/lib/Buffer.cpp: -------------------------------------------------------------------------------- 1 | #include "Buffer.h" 2 | #include "Arduino.h" 3 | 4 | Buffer::Buffer() { 5 | } 6 | 7 | Buffer::Buffer(uint8_t* buf, size_t size) { 8 | this->add(buf,size); 9 | } 10 | bool Buffer::available() { 11 | return this->pos < this->length; 12 | } 13 | 14 | uint8_t Buffer::next() { 15 | if (this->available()) { 16 | return this->buffer[this->pos++]; 17 | } 18 | return 0; 19 | } 20 | 21 | void Buffer::reset() { 22 | this->pos = 0; 23 | } 24 | 25 | void Buffer::add(uint8_t* buf, size_t size) { 26 | uint16_t i = 0; 27 | for (;ibuffer[this->length++] = buf[i]; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/tests/src/lib/Buffer.h: -------------------------------------------------------------------------------- 1 | #ifndef buffer_h 2 | #define buffer_h 3 | 4 | #include "Arduino.h" 5 | 6 | class Buffer { 7 | private: 8 | uint8_t buffer[1024]; 9 | uint16_t pos; 10 | uint16_t length; 11 | 12 | public: 13 | Buffer(); 14 | Buffer(uint8_t* buf, size_t size); 15 | 16 | virtual bool available(); 17 | virtual uint8_t next(); 18 | virtual void reset(); 19 | 20 | virtual void add(uint8_t* buf, size_t size); 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/tests/src/lib/Client.h: -------------------------------------------------------------------------------- 1 | #ifndef client_h 2 | #define client_h 3 | #include "IPAddress.h" 4 | 5 | class Client { 6 | public: 7 | virtual int connect(IPAddress ip, uint16_t port) =0; 8 | virtual int connect(const char *host, uint16_t port) =0; 9 | virtual size_t write(uint8_t) =0; 10 | virtual size_t write(const uint8_t *buf, size_t size) =0; 11 | virtual int available() = 0; 12 | virtual int read() = 0; 13 | virtual int read(uint8_t *buf, size_t size) = 0; 14 | virtual int peek() = 0; 15 | virtual void flush() = 0; 16 | virtual void stop() = 0; 17 | virtual uint8_t connected() = 0; 18 | virtual operator bool() = 0; 19 | }; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/tests/src/lib/IPAddress.h: -------------------------------------------------------------------------------- 1 | #ifndef IPAddress_h 2 | #define IPAddress_h 3 | 4 | extern "C" { 5 | 6 | #define IPAddress uint8_t* 7 | 8 | } 9 | 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/tests/src/lib/ShimClient.h: -------------------------------------------------------------------------------- 1 | #ifndef shimclient_h 2 | #define shimclient_h 3 | 4 | #include "Arduino.h" 5 | #include "Client.h" 6 | #include "IPAddress.h" 7 | #include "Buffer.h" 8 | 9 | 10 | class ShimClient : public Client { 11 | private: 12 | Buffer* responseBuffer; 13 | Buffer* expectBuffer; 14 | bool _allowConnect; 15 | bool _connected; 16 | bool expectAnything; 17 | bool _error; 18 | uint16_t _received; 19 | IPAddress _expectedIP; 20 | uint16_t _expectedPort; 21 | const char* _expectedHost; 22 | 23 | public: 24 | ShimClient(); 25 | virtual int connect(IPAddress ip, uint16_t port); 26 | virtual int connect(const char *host, uint16_t port); 27 | virtual size_t write(uint8_t); 28 | virtual size_t write(const uint8_t *buf, size_t size); 29 | virtual int available(); 30 | virtual int read(); 31 | virtual int read(uint8_t *buf, size_t size); 32 | virtual int peek(); 33 | virtual void flush(); 34 | virtual void stop(); 35 | virtual uint8_t connected(); 36 | virtual operator bool(); 37 | 38 | virtual ShimClient* respond(uint8_t *buf, size_t size); 39 | virtual ShimClient* expect(uint8_t *buf, size_t size); 40 | 41 | virtual void expectConnect(IPAddress ip, uint16_t port); 42 | virtual void expectConnect(const char *host, uint16_t port); 43 | 44 | virtual uint16_t received(); 45 | virtual bool error(); 46 | 47 | virtual void setAllowConnect(bool b); 48 | virtual void setConnected(bool b); 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/tests/src/lib/Stream.cpp: -------------------------------------------------------------------------------- 1 | #include "Stream.h" 2 | #include "trace.h" 3 | #include 4 | #include 5 | 6 | Stream::Stream() { 7 | this->expectBuffer = new Buffer(); 8 | this->_error = false; 9 | this->_written = 0; 10 | } 11 | 12 | size_t Stream::write(uint8_t b) { 13 | this->_written++; 14 | TRACE(std::hex << (unsigned int)b); 15 | if (this->expectBuffer->available()) { 16 | uint8_t expected = this->expectBuffer->next(); 17 | if (expected != b) { 18 | this->_error = true; 19 | TRACE("!=" << (unsigned int)expected); 20 | } 21 | } else { 22 | this->_error = true; 23 | } 24 | TRACE("\n"<< std::dec); 25 | return 1; 26 | } 27 | 28 | 29 | bool Stream::error() { 30 | return this->_error; 31 | } 32 | 33 | void Stream::expect(uint8_t *buf, size_t size) { 34 | this->expectBuffer->add(buf,size); 35 | } 36 | 37 | uint16_t Stream::length() { 38 | return this->_written; 39 | } 40 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/tests/src/lib/Stream.h: -------------------------------------------------------------------------------- 1 | #ifndef Stream_h 2 | #define Stream_h 3 | 4 | #include "Arduino.h" 5 | #include "Buffer.h" 6 | 7 | class Stream { 8 | private: 9 | Buffer* expectBuffer; 10 | bool _error; 11 | uint16_t _written; 12 | 13 | public: 14 | Stream(); 15 | virtual size_t write(uint8_t); 16 | 17 | virtual bool error(); 18 | virtual void expect(uint8_t *buf, size_t size); 19 | virtual uint16_t length(); 20 | }; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/tests/src/lib/trace.h: -------------------------------------------------------------------------------- 1 | #ifndef trace_h 2 | #define trace_h 3 | #include 4 | 5 | #include 6 | 7 | #define LOG(x) {std::cout << x << std::flush; } 8 | #define TRACE(x) {if (getenv("TRACE")) { std::cout << x << std::flush; }} 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/tests/src/publish_spec.cpp: -------------------------------------------------------------------------------- 1 | #include "PubSubClient.h" 2 | #include "ShimClient.h" 3 | #include "Buffer.h" 4 | #include "BDDTest.h" 5 | #include "trace.h" 6 | 7 | 8 | byte server[] = { 172, 16, 0, 2 }; 9 | 10 | void callback(char* topic, byte* payload, unsigned int length) { 11 | // handle message arrived 12 | } 13 | 14 | int test_publish() { 15 | IT("publishes a null-terminated string"); 16 | ShimClient shimClient; 17 | shimClient.setAllowConnect(true); 18 | 19 | byte connack[] = { 0x20, 0x02, 0x00, 0x00 }; 20 | shimClient.respond(connack,4); 21 | 22 | PubSubClient client(server, 1883, callback, shimClient); 23 | int rc = client.connect((char*)"client_test1"); 24 | IS_TRUE(rc); 25 | 26 | byte publish[] = {0x30,0xe,0x0,0x5,0x74,0x6f,0x70,0x69,0x63,0x70,0x61,0x79,0x6c,0x6f,0x61,0x64}; 27 | shimClient.expect(publish,16); 28 | 29 | rc = client.publish((char*)"topic",(char*)"payload"); 30 | IS_TRUE(rc); 31 | 32 | IS_FALSE(shimClient.error()); 33 | 34 | END_IT 35 | } 36 | 37 | 38 | int test_publish_bytes() { 39 | IT("publishes a byte array"); 40 | ShimClient shimClient; 41 | shimClient.setAllowConnect(true); 42 | 43 | byte payload[] = { 0x01,0x02,0x03,0x0,0x05 }; 44 | int length = 5; 45 | 46 | byte connack[] = { 0x20, 0x02, 0x00, 0x00 }; 47 | shimClient.respond(connack,4); 48 | 49 | PubSubClient client(server, 1883, callback, shimClient); 50 | int rc = client.connect((char*)"client_test1"); 51 | IS_TRUE(rc); 52 | 53 | byte publish[] = {0x30,0xc,0x0,0x5,0x74,0x6f,0x70,0x69,0x63,0x1,0x2,0x3,0x0,0x5}; 54 | shimClient.expect(publish,14); 55 | 56 | rc = client.publish((char*)"topic",payload,length); 57 | IS_TRUE(rc); 58 | 59 | IS_FALSE(shimClient.error()); 60 | 61 | END_IT 62 | } 63 | 64 | 65 | int test_publish_retained() { 66 | IT("publishes retained"); 67 | ShimClient shimClient; 68 | shimClient.setAllowConnect(true); 69 | 70 | byte payload[] = { 0x01,0x02,0x03,0x0,0x05 }; 71 | int length = 5; 72 | 73 | byte connack[] = { 0x20, 0x02, 0x00, 0x00 }; 74 | shimClient.respond(connack,4); 75 | 76 | PubSubClient client(server, 1883, callback, shimClient); 77 | int rc = client.connect((char*)"client_test1"); 78 | IS_TRUE(rc); 79 | 80 | byte publish[] = {0x31,0xc,0x0,0x5,0x74,0x6f,0x70,0x69,0x63,0x1,0x2,0x3,0x0,0x5}; 81 | shimClient.expect(publish,14); 82 | 83 | rc = client.publish((char*)"topic",payload,length,true); 84 | IS_TRUE(rc); 85 | 86 | IS_FALSE(shimClient.error()); 87 | 88 | END_IT 89 | } 90 | 91 | int test_publish_not_connected() { 92 | IT("publish fails when not connected"); 93 | ShimClient shimClient; 94 | 95 | PubSubClient client(server, 1883, callback, shimClient); 96 | 97 | int rc = client.publish((char*)"topic",(char*)"payload"); 98 | IS_FALSE(rc); 99 | 100 | IS_FALSE(shimClient.error()); 101 | 102 | END_IT 103 | } 104 | 105 | 106 | int test_publish_P() { 107 | IT("publishes using PROGMEM"); 108 | ShimClient shimClient; 109 | shimClient.setAllowConnect(true); 110 | 111 | byte payload[] = { 0x01,0x02,0x03,0x0,0x05 }; 112 | int length = 5; 113 | 114 | byte connack[] = { 0x20, 0x02, 0x00, 0x00 }; 115 | shimClient.respond(connack,4); 116 | 117 | PubSubClient client(server, 1883, callback, shimClient); 118 | int rc = client.connect((char*)"client_test1"); 119 | IS_TRUE(rc); 120 | 121 | byte publish[] = {0x31,0xc,0x0,0x5,0x74,0x6f,0x70,0x69,0x63,0x1,0x2,0x3,0x0,0x5}; 122 | shimClient.expect(publish,14); 123 | 124 | rc = client.publish_P((char*)"topic",payload,length,true); 125 | IS_TRUE(rc); 126 | 127 | IS_FALSE(shimClient.error()); 128 | 129 | END_IT 130 | } 131 | 132 | 133 | int main() 134 | { 135 | test_publish(); 136 | test_publish_bytes(); 137 | test_publish_retained(); 138 | test_publish_not_connected(); 139 | test_publish_P(); 140 | 141 | FINISH 142 | } 143 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/tests/testcases/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abzman/esp-stuff/93f390c95d2fb8b4b88caee80a7901eb904328de/libraries/pubsubclient.old/tests/testcases/__init__.py -------------------------------------------------------------------------------- /libraries/pubsubclient.old/tests/testcases/mqtt_basic.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import settings 3 | 4 | import time 5 | import mosquitto 6 | 7 | import serial 8 | 9 | def on_message(mosq, obj, msg): 10 | obj.message_queue.append(msg) 11 | 12 | class mqtt_basic(unittest.TestCase): 13 | 14 | message_queue = [] 15 | 16 | @classmethod 17 | def setUpClass(self): 18 | self.client = mosquitto.Mosquitto("pubsubclient_ut", clean_session=True,obj=self) 19 | self.client.connect(settings.server_ip) 20 | self.client.on_message = on_message 21 | self.client.subscribe("outTopic",0) 22 | 23 | @classmethod 24 | def tearDownClass(self): 25 | self.client.disconnect() 26 | 27 | def test_one(self): 28 | i=30 29 | while len(self.message_queue) == 0 and i > 0: 30 | self.client.loop() 31 | time.sleep(0.5) 32 | i -= 1 33 | self.assertTrue(i>0, "message receive timed-out") 34 | self.assertEqual(len(self.message_queue), 1, "unexpected number of messages received") 35 | msg = self.message_queue[0] 36 | self.assertEqual(msg.mid,0,"message id not 0") 37 | self.assertEqual(msg.topic,"outTopic","message topic incorrect") 38 | self.assertEqual(msg.payload,"hello world") 39 | self.assertEqual(msg.qos,0,"message qos not 0") 40 | self.assertEqual(msg.retain,False,"message retain flag incorrect") 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/tests/testcases/mqtt_publish_in_callback.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import settings 3 | 4 | import time 5 | import mosquitto 6 | 7 | import serial 8 | 9 | def on_message(mosq, obj, msg): 10 | obj.message_queue.append(msg) 11 | 12 | class mqtt_publish_in_callback(unittest.TestCase): 13 | 14 | message_queue = [] 15 | 16 | @classmethod 17 | def setUpClass(self): 18 | self.client = mosquitto.Mosquitto("pubsubclient_ut", clean_session=True,obj=self) 19 | self.client.connect(settings.server_ip) 20 | self.client.on_message = on_message 21 | self.client.subscribe("outTopic",0) 22 | 23 | @classmethod 24 | def tearDownClass(self): 25 | self.client.disconnect() 26 | 27 | def test_connect(self): 28 | i=30 29 | while len(self.message_queue) == 0 and i > 0: 30 | self.client.loop() 31 | time.sleep(0.5) 32 | i -= 1 33 | self.assertTrue(i>0, "message receive timed-out") 34 | self.assertEqual(len(self.message_queue), 1, "unexpected number of messages received") 35 | msg = self.message_queue.pop(0) 36 | self.assertEqual(msg.mid,0,"message id not 0") 37 | self.assertEqual(msg.topic,"outTopic","message topic incorrect") 38 | self.assertEqual(msg.payload,"hello world") 39 | self.assertEqual(msg.qos,0,"message qos not 0") 40 | self.assertEqual(msg.retain,False,"message retain flag incorrect") 41 | 42 | 43 | def test_publish(self): 44 | self.assertEqual(len(self.message_queue), 0, "message queue not empty") 45 | payload = "abcdefghij" 46 | self.client.publish("inTopic",payload) 47 | 48 | i=30 49 | while len(self.message_queue) == 0 and i > 0: 50 | self.client.loop() 51 | time.sleep(0.5) 52 | i -= 1 53 | 54 | self.assertTrue(i>0, "message receive timed-out") 55 | self.assertEqual(len(self.message_queue), 1, "unexpected number of messages received") 56 | msg = self.message_queue.pop(0) 57 | self.assertEqual(msg.mid,0,"message id not 0") 58 | self.assertEqual(msg.topic,"outTopic","message topic incorrect") 59 | self.assertEqual(msg.payload,payload) 60 | self.assertEqual(msg.qos,0,"message qos not 0") 61 | self.assertEqual(msg.retain,False,"message retain flag incorrect") 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /libraries/pubsubclient.old/tests/testcases/settings.py: -------------------------------------------------------------------------------- 1 | server_ip = "172.16.0.2" 2 | arduino_ip = "172.16.0.100" 3 | -------------------------------------------------------------------------------- /libraries/pubsubclient/.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *# 3 | -------------------------------------------------------------------------------- /libraries/pubsubclient/CHANGES.txt: -------------------------------------------------------------------------------- 1 | 2.4 2 | * Add MQTT_SOCKET_TIMEOUT to prevent it blocking indefinitely 3 | whilst waiting for inbound data 4 | * Fixed return code when publishing >256 bytes 5 | 6 | 2.3 7 | * Add publish(topic,payload,retained) function 8 | 9 | 2.2 10 | * Change code layout to match Arduino Library reqs 11 | 12 | 2.1 13 | * Add MAX_TRANSFER_SIZE def to chunk messages if needed 14 | * Reject topic/payloads that exceed MQTT_MAX_PACKET_SIZE 15 | 16 | 2.0 17 | * Add (and default to) MQTT 3.1.1 support 18 | * Fix PROGMEM handling for Intel Galileo/ESP8266 19 | * Add overloaded constructors for convenience 20 | * Add chainable setters for server/callback/client/stream 21 | * Add state function to return connack return code 22 | 23 | 1.9 24 | * Do not split MQTT packets over multiple calls to _client->write() 25 | * API change: All constructors now require an instance of Client 26 | to be passed in. 27 | * Fixed example to match 1.8 api changes - dpslwk 28 | * Added username/password support - WilHall 29 | * Added publish_P - publishes messages from PROGMEM - jobytaffey 30 | 31 | 1.8 32 | * KeepAlive interval is configurable in PubSubClient.h 33 | * Maximum packet size is configurable in PubSubClient.h 34 | * API change: Return boolean rather than int from various functions 35 | * API change: Length parameter in message callback changed 36 | from int to unsigned int 37 | * Various internal tidy-ups around types 38 | 1.7 39 | * Improved keepalive handling 40 | * Updated to the Arduino-1.0 API 41 | 1.6 42 | * Added the ability to publish a retained message 43 | 44 | 1.5 45 | * Added default constructor 46 | * Fixed compile error when used with arduino-0021 or later 47 | 48 | 1.4 49 | * Fixed connection lost handling 50 | 51 | 1.3 52 | * Fixed packet reading bug in PubSubClient.readPacket 53 | 54 | 1.2 55 | * Fixed compile error when used with arduino-0016 or later 56 | 57 | 58 | 1.1 59 | * Reduced size of library 60 | * Added support for Will messages 61 | * Clarified licensing - see LICENSE.txt 62 | 63 | 64 | 1.0 65 | * Only Quality of Service (QOS) 0 messaging is supported 66 | * The maximum message size, including header, is 128 bytes 67 | * The keepalive interval is set to 30 seconds 68 | * No support for Will messages 69 | -------------------------------------------------------------------------------- /libraries/pubsubclient/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2008-2015 Nicholas O'Leary 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /libraries/pubsubclient/README: -------------------------------------------------------------------------------- 1 | A client library for the ESP8266 (using the Arduino environment) that provides support for MQTT. 2 | 3 | Modified from Nicholas O'Leary's original for the Arduino + Ethernet shield: 4 | http://knolleary.net/arduino-client-for-mqtt/ 5 | 6 | See here for the ESP8266-Arduino work: 7 | https://github.com/esp8266/Arduino 8 | 9 | New features 10 | ------------ 11 | 12 | A whole set of MQTT classes has been added, one for each message type. 13 | This moved a good amount of code out of the PubSubClient class, leaving it to 14 | handle the high-level flow of the protocol. The MQTT classes handle getting 15 | data into and out of the messages. 16 | 17 | The PubSubClient class operates mostly as it did before. However, the 18 | connect(), publish(), subscribe(), and unsubscribe() methods can now take an 19 | appropriate MQTT object. This allows extra options to be set e.g QoS on 20 | publish, or multiple topics with one (un)subscribe message. 21 | 22 | You can use the MQTT classes and their chainable setter methods like this: 23 | 24 | client.connect(MQTT::Connect("clientId") 25 | .set_clean_session() 26 | .set_will("status", "down") 27 | .set_auth("username", "password) 28 | .set_keepalive(30) 29 | ); 30 | 31 | client.publish(MQTT::Publish("topic", "payload") 32 | .set_retain() 33 | .set_qos(1, client.next_packet_id()) 34 | .set_dup() 35 | ); 36 | 37 | client.subscribe(MQTT::Subscribe(client.next_packet_id()) 38 | .add_topic("topic1") 39 | .add_topic("topic2", 1) // optional qos value 40 | ); 41 | 42 | client.unsubscribe(MQTT::Unsubscribe(client.next_packet_id()) 43 | .add_topic("topic") 44 | ); 45 | 46 | See also the mqtt_auth or mqtt_qos example sketches for how this is used. 47 | -------------------------------------------------------------------------------- /libraries/pubsubclient/README.md: -------------------------------------------------------------------------------- 1 | # Arduino Client for MQTT 2 | 3 | This library provides a client for doing simple publish/subscribe messaging with 4 | a server that supports MQTT. 5 | 6 | ## Examples 7 | 8 | The library comes with a number of example sketches. See File > Examples > PubSubClient 9 | within the Arduino application. 10 | 11 | Full API documentation is available here: http://pubsubclient.knolleary.net 12 | 13 | ## Limitations 14 | 15 | - It can only publish QoS 0 messages. It can subscribe at QoS 0 or QoS 1. 16 | - The maximum message size, including header, is **128 bytes** by default. This 17 | is configurable via `MQTT_MAX_PACKET_SIZE` in `PubSubClient.h`. 18 | - The keepalive interval is set to 15 seconds by default. This is configurable 19 | via `MQTT_KEEPALIVE` in `PubSubClient.h`. 20 | - The client uses MQTT 3.1.1 by default. It can be changed to use MQTT 3.1 by 21 | changing value of `MQTT_VERSION` in `PubSubClient.h`. 22 | 23 | 24 | ## Compatible Hardware 25 | 26 | The library uses the Arduino Ethernet Client api for interacting with the 27 | underlying network hardware. This means it Just Works with a growing number of 28 | boards and shields, including: 29 | 30 | - Arduino Ethernet 31 | - Arduino Ethernet Shield 32 | - Arduino YUN – use the included `YunClient` in place of `EthernetClient`, and 33 | be sure to do a `Bridge.begin()` first 34 | - Arduino WiFi Shield - if you want to send packets > 90 bytes with this shield, 35 | enable the `MQTT_MAX_TRANSFER_SIZE` define in `PubSubClient.h`. 36 | - Sparkfun WiFly Shield – [library](https://github.com/dpslwk/WiFly) 37 | - TI CC3000 WiFi - [library](https://github.com/sparkfun/SFE_CC3000_Library) 38 | - Intel Galileo/Edison 39 | - ESP8266 40 | 41 | The library cannot currently be used with hardware based on the ENC28J60 chip – 42 | such as the Nanode or the Nuelectronics Ethernet Shield. For those, there is an 43 | [alternative library](https://github.com/njh/NanodeMQTT) available. 44 | 45 | ## License 46 | 47 | This code is released under the MIT License. 48 | -------------------------------------------------------------------------------- /libraries/pubsubclient/examples/mqtt_auth/mqtt_auth.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Basic MQTT example with Authentication 3 | 4 | - connects to an MQTT server, providing username 5 | and password 6 | - publishes "hello world" to the topic "outTopic" 7 | - subscribes to the topic "inTopic" 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | // Update these with values suitable for your network. 15 | byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED }; 16 | IPAddress ip(172, 16, 0, 100); 17 | IPAddress server(172, 16, 0, 2); 18 | 19 | void callback(char* topic, byte* payload, unsigned int length) { 20 | // handle message arrived 21 | } 22 | 23 | EthernetClient ethClient; 24 | PubSubClient client(server, 1883, callback, ethClient); 25 | 26 | void setup() 27 | { 28 | Ethernet.begin(mac, ip); 29 | // Note - the default maximum packet size is 128 bytes. If the 30 | // combined length of clientId, username and password exceed this, 31 | // you will need to increase the value of MQTT_MAX_PACKET_SIZE in 32 | // PubSubClient.h 33 | 34 | if (client.connect("arduinoClient", "testuser", "testpass")) { 35 | client.publish("outTopic","hello world"); 36 | client.subscribe("inTopic"); 37 | } 38 | } 39 | 40 | void loop() 41 | { 42 | client.loop(); 43 | } 44 | -------------------------------------------------------------------------------- /libraries/pubsubclient/examples/mqtt_basic/mqtt_basic.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Basic MQTT example 3 | 4 | This sketch demonstrates the basic capabilities of the library. 5 | It connects to an MQTT server then: 6 | - publishes "hello world" to the topic "outTopic" 7 | - subscribes to the topic "inTopic", printing out any messages 8 | it receives. NB - it assumes the received payloads are strings not binary 9 | 10 | It will reconnect to the server if the connection is lost using a blocking 11 | reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to 12 | achieve the same result without blocking the main loop. 13 | 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | // Update these with values suitable for your network. 21 | byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED }; 22 | IPAddress ip(172, 16, 0, 100); 23 | IPAddress server(172, 16, 0, 2); 24 | 25 | void callback(char* topic, byte* payload, unsigned int length) { 26 | Serial.print("Message arrived ["); 27 | Serial.print(topic); 28 | Serial.print("] "); 29 | for (int i=0;i Preferences -> Additional Boards Manager URLs": 20 | http://arduino.esp8266.com/stable/package_esp8266com_index.json 21 | - Open the "Tools -> Board -> Board Manager" and click install for the ESP8266" 22 | - Select your ESP8266 in "Tools -> Board" 23 | 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | // Update these with values suitable for your network. 30 | 31 | const char* ssid = "........"; 32 | const char* password = "........"; 33 | const char* mqtt_server = "broker.mqtt-dashboard.com"; 34 | 35 | WiFiClient espClient; 36 | PubSubClient client(espClient); 37 | long lastMsg = 0; 38 | char msg[50]; 39 | int value = 0; 40 | 41 | void setup() { 42 | pinMode(BUILTIN_LED, OUTPUT); // Initialize the BUILTIN_LED pin as an output 43 | Serial.begin(115200); 44 | setup_wifi(); 45 | client.setServer(mqtt_server, 1883); 46 | client.setCallback(callback); 47 | } 48 | 49 | void setup_wifi() { 50 | 51 | delay(10); 52 | // We start by connecting to a WiFi network 53 | Serial.println(); 54 | Serial.print("Connecting to "); 55 | Serial.println(ssid); 56 | 57 | WiFi.begin(ssid, password); 58 | 59 | while (WiFi.status() != WL_CONNECTED) { 60 | delay(500); 61 | Serial.print("."); 62 | } 63 | 64 | Serial.println(""); 65 | Serial.println("WiFi connected"); 66 | Serial.println("IP address: "); 67 | Serial.println(WiFi.localIP()); 68 | } 69 | 70 | void callback(char* topic, byte* payload, unsigned int length) { 71 | Serial.print("Message arrived ["); 72 | Serial.print(topic); 73 | Serial.print("] "); 74 | for (int i = 0; i < length; i++) { 75 | Serial.print((char)payload[i]); 76 | } 77 | Serial.println(); 78 | 79 | // Switch on the LED if an 1 was received as first character 80 | if ((char)payload[0] == '1') { 81 | digitalWrite(BUILTIN_LED, LOW); // Turn the LED on (Note that LOW is the voltage level 82 | // but actually the LED is on; this is because 83 | // it is acive low on the ESP-01) 84 | } else { 85 | digitalWrite(BUILTIN_LED, HIGH); // Turn the LED off by making the voltage HIGH 86 | } 87 | 88 | } 89 | 90 | void reconnect() { 91 | // Loop until we're reconnected 92 | while (!client.connected()) { 93 | Serial.print("Attempting MQTT connection..."); 94 | // Attempt to connect 95 | if (client.connect("ESP8266Client")) { 96 | Serial.println("connected"); 97 | // Once connected, publish an announcement... 98 | client.publish("outTopic", "hello world"); 99 | // ... and resubscribe 100 | client.subscribe("inTopic"); 101 | } else { 102 | Serial.print("failed, rc="); 103 | Serial.print(client.state()); 104 | Serial.println(" try again in 5 seconds"); 105 | // Wait 5 seconds before retrying 106 | delay(5000); 107 | } 108 | } 109 | } 110 | void loop() { 111 | 112 | if (!client.connected()) { 113 | reconnect(); 114 | } 115 | client.loop(); 116 | 117 | long now = millis(); 118 | if (now - lastMsg > 2000) { 119 | lastMsg = now; 120 | ++value; 121 | snprintf (msg, 75, "hello world #%ld", value); 122 | Serial.print("Publish message: "); 123 | Serial.println(msg); 124 | client.publish("outTopic", msg); 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /libraries/pubsubclient/examples/mqtt_publish_in_callback/mqtt_publish_in_callback.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Publishing in the callback 3 | 4 | - connects to an MQTT server 5 | - subscribes to the topic "inTopic" 6 | - when a message is received, republishes it to "outTopic" 7 | 8 | This example shows how to publish messages within the 9 | callback function. The callback function header needs to 10 | be declared before the PubSubClient constructor and the 11 | actual callback defined afterwards. 12 | This ensures the client reference in the callback function 13 | is valid. 14 | 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | // Update these with values suitable for your network. 22 | byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED }; 23 | IPAddress ip(172, 16, 0, 100); 24 | IPAddress server(172, 16, 0, 2); 25 | 26 | // Callback function header 27 | void callback(char* topic, byte* payload, unsigned int length); 28 | 29 | EthernetClient ethClient; 30 | PubSubClient client(server, 1883, callback, ethClient); 31 | 32 | // Callback function 33 | void callback(char* topic, byte* payload, unsigned int length) { 34 | // In order to republish this payload, a copy must be made 35 | // as the orignal payload buffer will be overwritten whilst 36 | // constructing the PUBLISH packet. 37 | 38 | // Allocate the correct amount of memory for the payload copy 39 | byte* p = (byte*)malloc(length); 40 | // Copy the payload to the new buffer 41 | memcpy(p,payload,length); 42 | client.publish("outTopic", p, length); 43 | // Free the memory 44 | free(p); 45 | } 46 | 47 | void setup() 48 | { 49 | 50 | Ethernet.begin(mac, ip); 51 | if (client.connect("arduinoClient")) { 52 | client.publish("outTopic","hello world"); 53 | client.subscribe("inTopic"); 54 | } 55 | } 56 | 57 | void loop() 58 | { 59 | client.loop(); 60 | } 61 | -------------------------------------------------------------------------------- /libraries/pubsubclient/examples/mqtt_qos/mqtt_qos.ino: -------------------------------------------------------------------------------- 1 | /* 2 | MQTT with QoS example 3 | 4 | - connects to an MQTT server 5 | - publishes "hello world" to the topic "outTopic" with a variety of QoS values 6 | 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | const char *ssid = "xxxxxxxx"; // cannot be longer than 32 characters! 13 | const char *pass = "yyyyyyyy"; // 14 | 15 | // Update these with values suitable for your network. 16 | IPAddress server(172, 16, 0, 2); 17 | 18 | void callback(const MQTT::Publish& pub) { 19 | // handle message arrived 20 | } 21 | 22 | PubSubClient client(server); 23 | 24 | void setup() 25 | { 26 | // Setup console 27 | Serial.begin(115200); 28 | delay(10); 29 | Serial.println(); 30 | Serial.println(); 31 | 32 | client.set_callback(callback); 33 | 34 | WiFi.begin(ssid, pass); 35 | 36 | int retries = 0; 37 | while ((WiFi.status() != WL_CONNECTED) && (retries < 10)) { 38 | retries++; 39 | delay(500); 40 | Serial.print("."); 41 | } 42 | if (WiFi.status() == WL_CONNECTED) { 43 | Serial.println(""); 44 | Serial.println("WiFi connected"); 45 | } 46 | 47 | if (client.connect("arduinoClient")) { 48 | client.publish("outTopic", "hello world qos=0"); // Simple publish with qos=0 49 | 50 | client.publish(MQTT::Publish("outTopic", "hello world qos=1") 51 | .set_qos(1, client.next_packet_id())); 52 | 53 | client.publish(MQTT::Publish("outTopic", "hello world qos=2") 54 | .set_qos(2, client.next_packet_id())); 55 | } 56 | } 57 | 58 | void loop() 59 | { 60 | client.loop(); 61 | } 62 | 63 | -------------------------------------------------------------------------------- /libraries/pubsubclient/examples/mqtt_reconnect_nonblocking/mqtt_reconnect_nonblocking.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Reconnecting MQTT example - non-blocking 3 | 4 | This sketch demonstrates how to keep the client connected 5 | using a non-blocking reconnect function. If the client loses 6 | its connection, it attempts to reconnect every 5 seconds 7 | without blocking the main loop. 8 | 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | // Update these with values suitable for your hardware/network. 16 | byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED }; 17 | IPAddress ip(172, 16, 0, 100); 18 | IPAddress server(172, 16, 0, 2); 19 | 20 | void callback(char* topic, byte* payload, unsigned int length) { 21 | // handle message arrived 22 | } 23 | 24 | EthernetClient ethClient; 25 | PubSubClient client(ethClient); 26 | 27 | long lastReconnectAttempt = 0; 28 | 29 | boolean reconnect() { 30 | if (client.connect("arduinoClient")) { 31 | // Once connected, publish an announcement... 32 | client.publish("outTopic","hello world"); 33 | // ... and resubscribe 34 | client.subscribe("inTopic"); 35 | } 36 | return client.connected(); 37 | } 38 | 39 | void setup() 40 | { 41 | client.setServer(server, 1883); 42 | client.setCallback(callback); 43 | 44 | Ethernet.begin(mac, ip); 45 | delay(1500); 46 | lastReconnectAttempt = 0; 47 | } 48 | 49 | 50 | void loop() 51 | { 52 | if (!client.connected()) { 53 | long now = millis(); 54 | if (now - lastReconnectAttempt > 5000) { 55 | lastReconnectAttempt = now; 56 | // Attempt to reconnect 57 | if (reconnect()) { 58 | lastReconnectAttempt = 0; 59 | } 60 | } 61 | } else { 62 | // Client connected 63 | 64 | client.loop(); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /libraries/pubsubclient/examples/mqtt_stream/mqtt_stream.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Example of using a Stream object to store the message payload 3 | 4 | Uses SRAM library: https://github.com/ennui2342/arduino-sram 5 | but could use any Stream based class such as SD 6 | 7 | - connects to an MQTT server 8 | - publishes "hello world" to the topic "outTopic" 9 | - subscribes to the topic "inTopic" 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | // Update these with values suitable for your network. 18 | byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED }; 19 | IPAddress ip(172, 16, 0, 100); 20 | IPAddress server(172, 16, 0, 2); 21 | 22 | SRAM sram(4, SRAM_1024); 23 | 24 | void callback(char* topic, byte* payload, unsigned int length) { 25 | sram.seek(1); 26 | 27 | // do something with the message 28 | for(uint8_t i=0; i 9 | #include 10 | 11 | const char *ssid = "xxxxxxxx"; // cannot be longer than 32 characters! 12 | const char *pass = "yyyyyyyy"; // 13 | 14 | // Update these with values suitable for your network. 15 | IPAddress server(172, 16, 0, 2); 16 | 17 | void callback(const MQTT::Publish& pub) { 18 | Serial.print(pub.topic()); 19 | Serial.print(" => "); 20 | Serial.println(pub.payload_string()); 21 | } 22 | 23 | PubSubClient client(server); 24 | 25 | void setup() 26 | { 27 | // Setup console 28 | Serial.begin(115200); 29 | delay(10); 30 | Serial.println(); 31 | Serial.println(); 32 | 33 | client.set_callback(callback); 34 | 35 | WiFi.begin(ssid, pass); 36 | 37 | int retries = 0; 38 | while ((WiFi.status() != WL_CONNECTED) && (retries < 10)) { 39 | retries++; 40 | delay(500); 41 | Serial.print("."); 42 | } 43 | if (WiFi.status() == WL_CONNECTED) { 44 | Serial.println(""); 45 | Serial.println("WiFi connected"); 46 | } 47 | 48 | if (client.connect("arduinoClient")) { 49 | client.subscribe("inTopic"); 50 | } 51 | } 52 | 53 | void loop() 54 | { 55 | client.loop(); 56 | } 57 | -------------------------------------------------------------------------------- /libraries/pubsubclient/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For PubSubClient 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | PubSubClient KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | connect KEYWORD2 16 | disconnect KEYWORD2 17 | publish KEYWORD2 18 | publish_P KEYWORD2 19 | subscribe KEYWORD2 20 | unsubscribe KEYWORD2 21 | loop KEYWORD2 22 | connected KEYWORD2 23 | setServer KEYWORD2 24 | setCallback KEYWORD2 25 | setClient KEYWORD2 26 | setStream KEYWORD2 27 | 28 | ####################################### 29 | # Constants (LITERAL1) 30 | ####################################### 31 | -------------------------------------------------------------------------------- /libraries/pubsubclient/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "PubSubClient", 3 | "keywords": "ethernet, mqtt, m2m, iot", 4 | "description": "A client library for MQTT messaging. MQTT is a lightweight messaging protocol ideal for small devices. This library allows you to send and receive MQTT messages. It supports the latest MQTT 3.1.1 protocol and can be configured to use the older MQTT 3.1 if needed. It supports all Arduino Ethernet Client compatible hardware, including the Intel Galileo/Edison, ESP8266 and TI CC3000.", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/knolleary/pubsubclient.git" 8 | }, 9 | "version": "2.6", 10 | "exclude": "tests", 11 | "examples": "examples/*/*.ino", 12 | "frameworks": "arduino", 13 | "platforms": [ 14 | "atmelavr", 15 | "espressif" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /libraries/pubsubclient/library.properties: -------------------------------------------------------------------------------- 1 | name=PubSubClient 2 | version=2.6 3 | author=Nick O'Leary 4 | maintainer=Nick O'Leary 5 | sentence=A client library for MQTT messaging. 6 | paragraph=MQTT is a lightweight messaging protocol ideal for small devices. This library allows you to send and receive MQTT messages. It supports the latest MQTT 3.1.1 protocol and can be configured to use the older MQTT 3.1 if needed. It supports all Arduino Ethernet Client compatible hardware, including the Intel Galileo/Edison, ESP8266 and TI CC3000. 7 | category=Communication 8 | url=http://pubsubclient.knolleary.net 9 | architectures=* 10 | -------------------------------------------------------------------------------- /libraries/pubsubclient/tests/.gitignore: -------------------------------------------------------------------------------- 1 | .build 2 | tmpbin 3 | logs 4 | *.pyc 5 | -------------------------------------------------------------------------------- /libraries/pubsubclient/tests/Makefile: -------------------------------------------------------------------------------- 1 | SRC_PATH=./src 2 | OUT_PATH=./bin 3 | TEST_SRC=$(wildcard ${SRC_PATH}/*_spec.cpp) 4 | TEST_BIN= $(TEST_SRC:${SRC_PATH}/%.cpp=${OUT_PATH}/%) 5 | VPATH=${SRC_PATH} 6 | SHIM_FILES=${SRC_PATH}/lib/*.cpp 7 | PSC_FILE=../src/PubSubClient.cpp 8 | CC=g++ 9 | CFLAGS=-I${SRC_PATH}/lib -I../src 10 | 11 | all: $(TEST_BIN) 12 | 13 | ${OUT_PATH}/%: ${SRC_PATH}/%.cpp ${PSC_FILE} ${SHIM_FILES} 14 | mkdir -p ${OUT_PATH} 15 | ${CC} ${CFLAGS} $^ -o $@ 16 | 17 | clean: 18 | @rm -rf ${OUT_PATH} 19 | 20 | test: 21 | @bin/connect_spec 22 | @bin/publish_spec 23 | @bin/receive_spec 24 | @bin/subscribe_spec 25 | @bin/keepalive_spec 26 | -------------------------------------------------------------------------------- /libraries/pubsubclient/tests/README.md: -------------------------------------------------------------------------------- 1 | # Arduino Client for MQTT Test Suite 2 | 3 | This is a regression test suite for the `PubSubClient` library. 4 | 5 | There are two parts: 6 | 7 | - Tests that can be compiled and run on any machine 8 | - Tests that build the example sketches using the Arduino IDE 9 | 10 | 11 | It is a work-in-progress and is subject to complete refactoring as the whim takes 12 | me. 13 | 14 | 15 | ## Local tests 16 | 17 | These are a set of executables that can be run to test specific areas of functionality. 18 | They do not require a real Arduino to be attached, nor the use of the Arduino IDE. 19 | 20 | The tests include a set of mock files to stub out the parts of the Arduino environment the library 21 | depends on. 22 | 23 | ### Dependencies 24 | 25 | - g++ 26 | 27 | ### Running 28 | 29 | Build the tests using the provided `Makefile`: 30 | 31 | $ make 32 | 33 | This will create a set of executables in `./bin/`. Run each of these executables to test the corresponding functionality. 34 | 35 | *Note:* the `connect_spec` and `keepalive_spec` tests involve testing keepalive timers so naturally take a few minutes to run through. 36 | 37 | ## Arduino tests 38 | 39 | *Note:* INO Tool doesn't currently play nicely with Arduino 1.5. This has broken this test suite. 40 | 41 | Without a suitable arduino plugged in, the test suite will only check the 42 | example sketches compile cleanly against the library. 43 | 44 | With an arduino plugged in, each sketch that has a corresponding python 45 | test case is built, uploaded and then the tests run. 46 | 47 | ### Dependencies 48 | 49 | - Python 2.7+ 50 | - [INO Tool](http://inotool.org/) - this provides command-line build/upload of Arduino sketches 51 | 52 | ### Running 53 | 54 | The test suite _does not_ run an MQTT server - it is assumed to be running already. 55 | 56 | $ python testsuite.py 57 | 58 | A summary of activity is printed to the console. More comprehensive logs are written 59 | to the `logs` directory. 60 | 61 | ### What it does 62 | 63 | For each sketch in the library's `examples` directory, e.g. `mqtt_basic.ino`, the suite looks for a matching test case 64 | `testcases/mqtt_basic.py`. 65 | 66 | The test case must follow these conventions: 67 | - sub-class `unittest.TestCase` 68 | - provide the class methods `setUpClass` and `tearDownClass` (TODO: make this optional) 69 | - all test method names begin with `test_` 70 | 71 | The suite will call the `setUpClass` method _before_ uploading the sketch. This 72 | allows any test setup to be performed before the sketch runs - such as connecting 73 | a client and subscribing to topics. 74 | 75 | 76 | ### Settings 77 | 78 | The file `testcases/settings.py` is used to config the test environment. 79 | 80 | - `server_ip` - the IP address of the broker the client should connect to (the broker port is assumed to be 1883). 81 | - `arduino_ip` - the IP address the arduino should use (when not testing DHCP). 82 | 83 | Before each sketch is compiled, these values are automatically substituted in. To 84 | do this, the suite looks for lines that _start_ with the following: 85 | 86 | byte server[] = { 87 | byte ip[] = { 88 | 89 | and replaces them with the appropriate values. 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /libraries/pubsubclient/tests/src/lib/Arduino.h: -------------------------------------------------------------------------------- 1 | #ifndef Arduino_h 2 | #define Arduino_h 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | extern "C"{ 11 | typedef uint8_t byte ; 12 | typedef uint8_t boolean ; 13 | 14 | /* sketch */ 15 | extern void setup( void ) ; 16 | extern void loop( void ) ; 17 | uint32_t millis( void ); 18 | } 19 | 20 | #define PROGMEM 21 | #define pgm_read_byte_near(x) *(x) 22 | 23 | #endif // Arduino_h 24 | -------------------------------------------------------------------------------- /libraries/pubsubclient/tests/src/lib/BDDTest.cpp: -------------------------------------------------------------------------------- 1 | #include "BDDTest.h" 2 | #include "trace.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int testCount = 0; 9 | int testPasses = 0; 10 | const char* testDescription; 11 | 12 | std::list failureList; 13 | 14 | void bddtest_suite(const char* name) { 15 | LOG(name << "\n"); 16 | } 17 | 18 | int bddtest_test(const char* file, int line, const char* assertion, int result) { 19 | if (!result) { 20 | LOG("✗\n"); 21 | std::ostringstream os; 22 | os << " ! "<::iterator it = failureList.begin(); it != failureList.end(); it++) { 40 | LOG("\n"); 41 | LOG(*it); 42 | LOG("\n"); 43 | } 44 | 45 | LOG(std::dec << testPasses << "/" << testCount << " tests passed\n\n"); 46 | if (testPasses == testCount) { 47 | return 0; 48 | } 49 | return 1; 50 | } 51 | -------------------------------------------------------------------------------- /libraries/pubsubclient/tests/src/lib/BDDTest.h: -------------------------------------------------------------------------------- 1 | #ifndef bddtest_h 2 | #define bddtest_h 3 | 4 | void bddtest_suite(const char* name); 5 | int bddtest_test(const char*, int, const char*, int); 6 | void bddtest_start(const char*); 7 | void bddtest_end(); 8 | int bddtest_summary(); 9 | 10 | #define SUITE(x) { bddtest_suite(x); } 11 | #define TEST(x) { if (!bddtest_test(__FILE__, __LINE__, #x, (x))) return false; } 12 | 13 | #define IT(x) { bddtest_start(x); } 14 | #define END_IT { bddtest_end();return true;} 15 | 16 | #define FINISH { return bddtest_summary(); } 17 | 18 | #define IS_TRUE(x) TEST(x) 19 | #define IS_FALSE(x) TEST(!(x)) 20 | #define IS_EQUAL(x,y) TEST(x==y) 21 | #define IS_NOT_EQUAL(x,y) TEST(x!=y) 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /libraries/pubsubclient/tests/src/lib/Buffer.cpp: -------------------------------------------------------------------------------- 1 | #include "Buffer.h" 2 | #include "Arduino.h" 3 | 4 | Buffer::Buffer() { 5 | } 6 | 7 | Buffer::Buffer(uint8_t* buf, size_t size) { 8 | this->add(buf,size); 9 | } 10 | bool Buffer::available() { 11 | return this->pos < this->length; 12 | } 13 | 14 | uint8_t Buffer::next() { 15 | if (this->available()) { 16 | return this->buffer[this->pos++]; 17 | } 18 | return 0; 19 | } 20 | 21 | void Buffer::reset() { 22 | this->pos = 0; 23 | } 24 | 25 | void Buffer::add(uint8_t* buf, size_t size) { 26 | uint16_t i = 0; 27 | for (;ibuffer[this->length++] = buf[i]; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /libraries/pubsubclient/tests/src/lib/Buffer.h: -------------------------------------------------------------------------------- 1 | #ifndef buffer_h 2 | #define buffer_h 3 | 4 | #include "Arduino.h" 5 | 6 | class Buffer { 7 | private: 8 | uint8_t buffer[1024]; 9 | uint16_t pos; 10 | uint16_t length; 11 | 12 | public: 13 | Buffer(); 14 | Buffer(uint8_t* buf, size_t size); 15 | 16 | virtual bool available(); 17 | virtual uint8_t next(); 18 | virtual void reset(); 19 | 20 | virtual void add(uint8_t* buf, size_t size); 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /libraries/pubsubclient/tests/src/lib/Client.h: -------------------------------------------------------------------------------- 1 | #ifndef client_h 2 | #define client_h 3 | #include "IPAddress.h" 4 | 5 | class Client { 6 | public: 7 | virtual int connect(IPAddress ip, uint16_t port) =0; 8 | virtual int connect(const char *host, uint16_t port) =0; 9 | virtual size_t write(uint8_t) =0; 10 | virtual size_t write(const uint8_t *buf, size_t size) =0; 11 | virtual int available() = 0; 12 | virtual int read() = 0; 13 | virtual int read(uint8_t *buf, size_t size) = 0; 14 | virtual int peek() = 0; 15 | virtual void flush() = 0; 16 | virtual void stop() = 0; 17 | virtual uint8_t connected() = 0; 18 | virtual operator bool() = 0; 19 | }; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /libraries/pubsubclient/tests/src/lib/IPAddress.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | IPAddress::IPAddress() 6 | { 7 | memset(_address, 0, sizeof(_address)); 8 | } 9 | 10 | IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet) 11 | { 12 | _address[0] = first_octet; 13 | _address[1] = second_octet; 14 | _address[2] = third_octet; 15 | _address[3] = fourth_octet; 16 | } 17 | 18 | IPAddress::IPAddress(uint32_t address) 19 | { 20 | memcpy(_address, &address, sizeof(_address)); 21 | } 22 | 23 | IPAddress::IPAddress(const uint8_t *address) 24 | { 25 | memcpy(_address, address, sizeof(_address)); 26 | } 27 | 28 | IPAddress& IPAddress::operator=(const uint8_t *address) 29 | { 30 | memcpy(_address, address, sizeof(_address)); 31 | return *this; 32 | } 33 | 34 | IPAddress& IPAddress::operator=(uint32_t address) 35 | { 36 | memcpy(_address, (const uint8_t *)&address, sizeof(_address)); 37 | return *this; 38 | } 39 | 40 | bool IPAddress::operator==(const uint8_t* addr) 41 | { 42 | return memcmp(addr, _address, sizeof(_address)) == 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /libraries/pubsubclient/tests/src/lib/IPAddress.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * MIT License: 4 | * Copyright (c) 2011 Adrian McEwen 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | * 23 | * adrianm@mcqn.com 1/1/2011 24 | */ 25 | 26 | #ifndef IPAddress_h 27 | #define IPAddress_h 28 | 29 | 30 | // A class to make it easier to handle and pass around IP addresses 31 | 32 | class IPAddress { 33 | private: 34 | uint8_t _address[4]; // IPv4 address 35 | // Access the raw byte array containing the address. Because this returns a pointer 36 | // to the internal structure rather than a copy of the address this function should only 37 | // be used when you know that the usage of the returned uint8_t* will be transient and not 38 | // stored. 39 | uint8_t* raw_address() { return _address; }; 40 | 41 | public: 42 | // Constructors 43 | IPAddress(); 44 | IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet); 45 | IPAddress(uint32_t address); 46 | IPAddress(const uint8_t *address); 47 | 48 | // Overloaded cast operator to allow IPAddress objects to be used where a pointer 49 | // to a four-byte uint8_t array is expected 50 | operator uint32_t() { return *((uint32_t*)_address); }; 51 | bool operator==(const IPAddress& addr) { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); }; 52 | bool operator==(const uint8_t* addr); 53 | 54 | // Overloaded index operator to allow getting and setting individual octets of the address 55 | uint8_t operator[](int index) const { return _address[index]; }; 56 | uint8_t& operator[](int index) { return _address[index]; }; 57 | 58 | // Overloaded copy operators to allow initialisation of IPAddress objects from other types 59 | IPAddress& operator=(const uint8_t *address); 60 | IPAddress& operator=(uint32_t address); 61 | 62 | 63 | friend class EthernetClass; 64 | friend class UDP; 65 | friend class Client; 66 | friend class Server; 67 | friend class DhcpClass; 68 | friend class DNSClient; 69 | }; 70 | 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /libraries/pubsubclient/tests/src/lib/ShimClient.h: -------------------------------------------------------------------------------- 1 | #ifndef shimclient_h 2 | #define shimclient_h 3 | 4 | #include "Arduino.h" 5 | #include "Client.h" 6 | #include "IPAddress.h" 7 | #include "Buffer.h" 8 | 9 | 10 | class ShimClient : public Client { 11 | private: 12 | Buffer* responseBuffer; 13 | Buffer* expectBuffer; 14 | bool _allowConnect; 15 | bool _connected; 16 | bool expectAnything; 17 | bool _error; 18 | uint16_t _received; 19 | IPAddress _expectedIP; 20 | uint16_t _expectedPort; 21 | const char* _expectedHost; 22 | 23 | public: 24 | ShimClient(); 25 | virtual int connect(IPAddress ip, uint16_t port); 26 | virtual int connect(const char *host, uint16_t port); 27 | virtual size_t write(uint8_t); 28 | virtual size_t write(const uint8_t *buf, size_t size); 29 | virtual int available(); 30 | virtual int read(); 31 | virtual int read(uint8_t *buf, size_t size); 32 | virtual int peek(); 33 | virtual void flush(); 34 | virtual void stop(); 35 | virtual uint8_t connected(); 36 | virtual operator bool(); 37 | 38 | virtual ShimClient* respond(uint8_t *buf, size_t size); 39 | virtual ShimClient* expect(uint8_t *buf, size_t size); 40 | 41 | virtual void expectConnect(IPAddress ip, uint16_t port); 42 | virtual void expectConnect(const char *host, uint16_t port); 43 | 44 | virtual uint16_t received(); 45 | virtual bool error(); 46 | 47 | virtual void setAllowConnect(bool b); 48 | virtual void setConnected(bool b); 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /libraries/pubsubclient/tests/src/lib/Stream.cpp: -------------------------------------------------------------------------------- 1 | #include "Stream.h" 2 | #include "trace.h" 3 | #include 4 | #include 5 | 6 | Stream::Stream() { 7 | this->expectBuffer = new Buffer(); 8 | this->_error = false; 9 | this->_written = 0; 10 | } 11 | 12 | size_t Stream::write(uint8_t b) { 13 | this->_written++; 14 | TRACE(std::hex << (unsigned int)b); 15 | if (this->expectBuffer->available()) { 16 | uint8_t expected = this->expectBuffer->next(); 17 | if (expected != b) { 18 | this->_error = true; 19 | TRACE("!=" << (unsigned int)expected); 20 | } 21 | } else { 22 | this->_error = true; 23 | } 24 | TRACE("\n"<< std::dec); 25 | return 1; 26 | } 27 | 28 | 29 | bool Stream::error() { 30 | return this->_error; 31 | } 32 | 33 | void Stream::expect(uint8_t *buf, size_t size) { 34 | this->expectBuffer->add(buf,size); 35 | } 36 | 37 | uint16_t Stream::length() { 38 | return this->_written; 39 | } 40 | -------------------------------------------------------------------------------- /libraries/pubsubclient/tests/src/lib/Stream.h: -------------------------------------------------------------------------------- 1 | #ifndef Stream_h 2 | #define Stream_h 3 | 4 | #include "Arduino.h" 5 | #include "Buffer.h" 6 | 7 | class Stream { 8 | private: 9 | Buffer* expectBuffer; 10 | bool _error; 11 | uint16_t _written; 12 | 13 | public: 14 | Stream(); 15 | virtual size_t write(uint8_t); 16 | 17 | virtual bool error(); 18 | virtual void expect(uint8_t *buf, size_t size); 19 | virtual uint16_t length(); 20 | }; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /libraries/pubsubclient/tests/src/lib/trace.h: -------------------------------------------------------------------------------- 1 | #ifndef trace_h 2 | #define trace_h 3 | #include 4 | 5 | #include 6 | 7 | #define LOG(x) {std::cout << x << std::flush; } 8 | #define TRACE(x) {if (getenv("TRACE")) { std::cout << x << std::flush; }} 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /libraries/pubsubclient/tests/testcases/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abzman/esp-stuff/93f390c95d2fb8b4b88caee80a7901eb904328de/libraries/pubsubclient/tests/testcases/__init__.py -------------------------------------------------------------------------------- /libraries/pubsubclient/tests/testcases/mqtt_basic.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import settings 3 | 4 | import time 5 | import mosquitto 6 | 7 | import serial 8 | 9 | def on_message(mosq, obj, msg): 10 | obj.message_queue.append(msg) 11 | 12 | class mqtt_basic(unittest.TestCase): 13 | 14 | message_queue = [] 15 | 16 | @classmethod 17 | def setUpClass(self): 18 | self.client = mosquitto.Mosquitto("pubsubclient_ut", clean_session=True,obj=self) 19 | self.client.connect(settings.server_ip) 20 | self.client.on_message = on_message 21 | self.client.subscribe("outTopic",0) 22 | 23 | @classmethod 24 | def tearDownClass(self): 25 | self.client.disconnect() 26 | 27 | def test_one(self): 28 | i=30 29 | while len(self.message_queue) == 0 and i > 0: 30 | self.client.loop() 31 | time.sleep(0.5) 32 | i -= 1 33 | self.assertTrue(i>0, "message receive timed-out") 34 | self.assertEqual(len(self.message_queue), 1, "unexpected number of messages received") 35 | msg = self.message_queue[0] 36 | self.assertEqual(msg.mid,0,"message id not 0") 37 | self.assertEqual(msg.topic,"outTopic","message topic incorrect") 38 | self.assertEqual(msg.payload,"hello world") 39 | self.assertEqual(msg.qos,0,"message qos not 0") 40 | self.assertEqual(msg.retain,False,"message retain flag incorrect") 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /libraries/pubsubclient/tests/testcases/mqtt_publish_in_callback.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import settings 3 | 4 | import time 5 | import mosquitto 6 | 7 | import serial 8 | 9 | def on_message(mosq, obj, msg): 10 | obj.message_queue.append(msg) 11 | 12 | class mqtt_publish_in_callback(unittest.TestCase): 13 | 14 | message_queue = [] 15 | 16 | @classmethod 17 | def setUpClass(self): 18 | self.client = mosquitto.Mosquitto("pubsubclient_ut", clean_session=True,obj=self) 19 | self.client.connect(settings.server_ip) 20 | self.client.on_message = on_message 21 | self.client.subscribe("outTopic",0) 22 | 23 | @classmethod 24 | def tearDownClass(self): 25 | self.client.disconnect() 26 | 27 | def test_connect(self): 28 | i=30 29 | while len(self.message_queue) == 0 and i > 0: 30 | self.client.loop() 31 | time.sleep(0.5) 32 | i -= 1 33 | self.assertTrue(i>0, "message receive timed-out") 34 | self.assertEqual(len(self.message_queue), 1, "unexpected number of messages received") 35 | msg = self.message_queue.pop(0) 36 | self.assertEqual(msg.mid,0,"message id not 0") 37 | self.assertEqual(msg.topic,"outTopic","message topic incorrect") 38 | self.assertEqual(msg.payload,"hello world") 39 | self.assertEqual(msg.qos,0,"message qos not 0") 40 | self.assertEqual(msg.retain,False,"message retain flag incorrect") 41 | 42 | 43 | def test_publish(self): 44 | self.assertEqual(len(self.message_queue), 0, "message queue not empty") 45 | payload = "abcdefghij" 46 | self.client.publish("inTopic",payload) 47 | 48 | i=30 49 | while len(self.message_queue) == 0 and i > 0: 50 | self.client.loop() 51 | time.sleep(0.5) 52 | i -= 1 53 | 54 | self.assertTrue(i>0, "message receive timed-out") 55 | self.assertEqual(len(self.message_queue), 1, "unexpected number of messages received") 56 | msg = self.message_queue.pop(0) 57 | self.assertEqual(msg.mid,0,"message id not 0") 58 | self.assertEqual(msg.topic,"outTopic","message topic incorrect") 59 | self.assertEqual(msg.payload,payload) 60 | self.assertEqual(msg.qos,0,"message qos not 0") 61 | self.assertEqual(msg.retain,False,"message retain flag incorrect") 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /libraries/pubsubclient/tests/testcases/settings.py: -------------------------------------------------------------------------------- 1 | server_ip = "172.16.0.2" 2 | arduino_ip = "172.16.0.100" 3 | --------------------------------------------------------------------------------