├── .gitignore ├── LICENSE ├── README.md ├── examples ├── Blinker_AHRS │ ├── AHRS_BLE │ │ └── AHRS_BLE.ino │ └── AHRS_WiFi │ │ └── AHRS_WiFi.ino ├── Blinker_APCONFIG │ └── APCONFIG_WiFi │ │ └── APCONFIG_WiFi.ino ├── Blinker_AQI │ ├── AQI_MQTT │ │ └── AQI_MQTT.ino │ └── AQI_WiFi │ │ └── AQI_WiFi.ino ├── Blinker_AUTO │ └── AUTO_MQTT │ │ └── AUTO_MQTT.ino ├── Blinker_BUILTINSWITCH │ ├── BUILTINSWITCH_BLE │ │ └── BUILTINSWITCH_BLE.ino │ └── BUILTINSWITCH_WiFi │ │ └── BUILTINSWITCH_WiFi.ino ├── Blinker_Bridge │ └── Bridge_MQTT │ │ └── Bridge_MQTT.ino ├── Blinker_Button │ ├── Button_BLE │ │ └── Button_BLE.ino │ └── Button_WiFi │ │ └── Button_WiFi.ino ├── Blinker_CLOUD │ └── CLOUD_MQTT │ │ └── CLOUD_MQTT.ino ├── Blinker_DHT │ ├── DHT_BLE │ │ └── DHT_BLE.ino │ └── DHT_WiFi │ │ └── DHT_WiFi.ino ├── Blinker_ESPTOUCH │ ├── ESPTOUCH_MQTT │ │ └── ESPTOUCH_MQTT.ino │ └── ESPTOUCH_WiFi │ │ └── ESPTOUCH_WiFi.ino ├── Blinker_GPS │ ├── GPS_BLE │ │ └── GPS_BLE.ino │ └── GPS_WiFi │ │ └── GPS_WiFi.ino ├── Blinker_Joystick │ ├── Joystick_BLE │ │ └── Joystick_BLE.ino │ └── Joystick_WiFi │ │ └── Joystick_WiFi.ino ├── Blinker_MQTT │ └── MQTT_WiFi │ │ └── MQTT_WiFi.ino ├── Blinker_Notify │ ├── Notify_BLE │ │ └── Notify_BLE.ino │ └── Notify_WiFi │ │ └── Notify_WiFi.ino ├── Blinker_PRO │ └── Blinker_PRO │ │ └── Blinker_PRO.ino ├── Blinker_Print │ ├── Print_BLE │ │ └── Print_BLE.ino │ └── Print_WiFi │ │ └── Print_WiFi.ino ├── Blinker_Print_Format │ ├── Print_Format_BLE │ │ └── Print_Format_BLE.ino │ └── Print_Format_WiFi │ │ └── Print_Format_WiFi.ino ├── Blinker_RGB │ ├── RGB_BLE │ │ └── RGB_BLE.ino │ └── RGB_WiFi │ │ └── RGB_WiFi.ino ├── Blinker_SMS │ ├── SMS_MQTT │ │ └── SMS_MQTT.ino │ └── SMS_WiFi │ │ └── SMS_WiFi.ino ├── Blinker_SR04 │ ├── SR04_BLE │ │ └── SR04_BLE.ino │ └── SR04_WiFi │ │ └── SR04_WiFi.ino ├── Blinker_Slider │ ├── Slider_BLE │ │ └── Slider_BLE.ino │ └── Slider_WiFi │ │ └── Slider_WiFi.ino ├── Blinker_Time │ └── Time_WiFi │ │ └── Time_WiFi.ino ├── Blinker_Timer │ ├── Timer_WiFi_countdown │ │ └── Timer_WiFi_countdown.ino │ ├── Timer_WiFi_loop │ │ └── Timer_WiFi_loop.ino │ └── Timer_WiFi_timing │ │ └── Timer_WiFi_timing.ino ├── Blinker_Toggle │ ├── Toggle_BLE │ │ └── Toggle_BLE.ino │ └── Toggle_WiFi │ │ └── Toggle_WiFi.ino └── Blinker_Weather │ ├── Weather_MQTT │ └── Weather_MQTT.ino │ └── Weather_WiFi │ └── Weather_WiFi.ino ├── library.json ├── library.properties └── src ├── Adapters ├── BlinkerArduinoWS.h ├── BlinkerMQTT.h ├── BlinkerPRO.h ├── BlinkerSerial.h └── test.h ├── Blinker.h ├── Blinker ├── BlinkerApi.h ├── BlinkerAuto.h ├── BlinkerConfig.h └── BlinkerProtocol.h ├── BlinkerSimpleESP32_BLE.h ├── BlinkerSimpleESP32_MQTT.h ├── BlinkerSimpleESP32_PRO.h ├── BlinkerSimpleESP32_WS.h ├── BlinkerSimpleESP8266_MQTT.h ├── BlinkerSimpleESP8266_PRO.h ├── BlinkerSimpleESP8266_WS.h ├── BlinkerSimpleSerialBLE.h ├── modules ├── ArduinoJson │ ├── ArduinoJson.h │ ├── ArduinoJson.hpp │ └── ArduinoJson │ │ ├── Configuration.hpp │ │ ├── Data │ │ ├── Encoding.hpp │ │ ├── JsonBufferAllocated.hpp │ │ ├── JsonFloat.hpp │ │ ├── JsonInteger.hpp │ │ ├── JsonVariantAs.hpp │ │ ├── JsonVariantContent.hpp │ │ ├── JsonVariantDefault.hpp │ │ ├── JsonVariantType.hpp │ │ ├── List.hpp │ │ ├── ListConstIterator.hpp │ │ ├── ListIterator.hpp │ │ ├── ListNode.hpp │ │ ├── NonCopyable.hpp │ │ ├── ReferenceType.hpp │ │ └── ValueSaver.hpp │ │ ├── Deserialization │ │ ├── Comments.hpp │ │ ├── JsonParser.hpp │ │ ├── JsonParserImpl.hpp │ │ └── StringWriter.hpp │ │ ├── DynamicJsonBuffer.hpp │ │ ├── JsonArray.hpp │ │ ├── JsonArrayImpl.hpp │ │ ├── JsonArraySubscript.hpp │ │ ├── JsonBuffer.hpp │ │ ├── JsonBufferBase.hpp │ │ ├── JsonBufferImpl.hpp │ │ ├── JsonObject.hpp │ │ ├── JsonObjectImpl.hpp │ │ ├── JsonObjectSubscript.hpp │ │ ├── JsonPair.hpp │ │ ├── JsonVariant.hpp │ │ ├── JsonVariantBase.hpp │ │ ├── JsonVariantCasts.hpp │ │ ├── JsonVariantComparisons.hpp │ │ ├── JsonVariantImpl.hpp │ │ ├── JsonVariantOr.hpp │ │ ├── JsonVariantSubscripts.hpp │ │ ├── Polyfills │ │ ├── attributes.hpp │ │ ├── ctype.hpp │ │ ├── isFloat.hpp │ │ ├── isInteger.hpp │ │ ├── math.hpp │ │ ├── parseFloat.hpp │ │ └── parseInteger.hpp │ │ ├── RawJson.hpp │ │ ├── Serialization │ │ ├── DummyPrint.hpp │ │ ├── DynamicStringBuilder.hpp │ │ ├── FloatParts.hpp │ │ ├── IndentedPrint.hpp │ │ ├── JsonPrintable.hpp │ │ ├── JsonSerializer.hpp │ │ ├── JsonSerializerImpl.hpp │ │ ├── JsonWriter.hpp │ │ ├── Prettyfier.hpp │ │ ├── StaticStringBuilder.hpp │ │ └── StreamPrintAdapter.hpp │ │ ├── StaticJsonBuffer.hpp │ │ ├── StringTraits │ │ ├── ArduinoStream.hpp │ │ ├── CharPointer.hpp │ │ ├── FlashString.hpp │ │ ├── StdStream.hpp │ │ ├── StdString.hpp │ │ └── StringTraits.hpp │ │ ├── TypeTraits │ │ ├── EnableIf.hpp │ │ ├── FloatTraits.hpp │ │ ├── IsArray.hpp │ │ ├── IsBaseOf.hpp │ │ ├── IsChar.hpp │ │ ├── IsConst.hpp │ │ ├── IsFloatingPoint.hpp │ │ ├── IsIntegral.hpp │ │ ├── IsSame.hpp │ │ ├── IsSignedIntegral.hpp │ │ ├── IsUnsignedIntegral.hpp │ │ ├── IsVariant.hpp │ │ ├── RemoveConst.hpp │ │ └── RemoveReference.hpp │ │ └── version.hpp ├── OneButton │ ├── OneButton.cpp │ └── OneButton.h ├── Ultrasonic.cpp ├── Ultrasonic.h ├── WebSockets │ ├── WebSockets.cpp │ ├── WebSockets.h │ ├── WebSocketsClient.cpp │ ├── WebSocketsClient.h │ ├── WebSocketsServer.cpp │ ├── WebSocketsServer.h │ ├── libb64 │ │ ├── AUTHORS │ │ ├── LICENSE │ │ ├── cdecode.c │ │ ├── cdecode_inc.h │ │ ├── cencode.c │ │ └── cencode_inc.h │ └── libsha1 │ │ ├── libsha1.c │ │ └── libsha1.h ├── dht │ ├── DHT.cpp │ └── DHT.h └── mqtt │ ├── Adafruit_MQTT.cpp │ ├── Adafruit_MQTT.h │ ├── Adafruit_MQTT_Client.cpp │ ├── Adafruit_MQTT_Client.h │ └── Adafruit_MQTT_FONA.h └── utility ├── BlinkerAuto.h ├── BlinkerDebug.h ├── BlinkerOTA.h ├── BlinkerUtility.h └── BlinkerWlan.h /.gitignore: -------------------------------------------------------------------------------- 1 | __vm/ 2 | Debug/ 3 | *.vcxproj 4 | *.filters 5 | .vs/ 6 | *.sln 7 | .vscode/ 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 i3water 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # blinker-library 2 | Blinker library for embedded hardware. Works with Arduino, ESP8266, ESP32. 3 | 4 | # What's Blinker 5 | [Blinker](https://blinker-iot.com/) is a platform with iOS and Android apps to control embedded hardware like Arduino. You can easily build graphic interfaces for all your projects by simply dragging and dropping widgets. 6 | 7 | [Blinker](https://blinker-iot.com/) 是一个运行在 IOS 和 Android 上用于控制嵌入式硬件的应用程序。你可以通过拖放控制组件,轻松地为你的项目建立图形化控制界面。 8 | 9 | # Reference/参考 10 | * [EN-英文](https://github.com/blinker-iot/blinker-doc/wiki/Blinker-Arduino-library-reference) 11 | * [CN-中文](https://github.com/blinker-iot/blinker-doc/wiki/Blinker-Arduino-%E5%BA%93%E4%BD%BF%E7%94%A8%E6%89%8B%E5%86%8C) 12 | * [CN-中文/官网](https://doc.blinker.app/?file=003-%E7%A1%AC%E4%BB%B6%E5%BC%80%E5%8F%91/02-Arduino%E6%94%AF%E6%8C%81) 13 | 14 | -------------------------------------------------------------------------------- /examples/Blinker_AHRS/AHRS_BLE/AHRS_BLE.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_BLE 3 | 4 | #include 5 | 6 | void setup() 7 | { 8 | Serial.begin(115200); 9 | 10 | pinMode(LED_BUILTIN, OUTPUT); 11 | digitalWrite(LED_BUILTIN, LOW); 12 | 13 | Blinker.begin(); 14 | Blinker.attachAhrs(); 15 | } 16 | 17 | void loop() 18 | { 19 | Blinker.run(); 20 | 21 | if (Blinker.available()) { 22 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 23 | 24 | Blinker.vibrate(); 25 | 26 | uint32_t BlinkerTime = millis(); 27 | Blinker.print(BlinkerTime); 28 | Blinker.print("millis", BlinkerTime); 29 | } 30 | 31 | BLINKER_LOG2("AHRS Yaw: ", Blinker.ahrs(Yaw)); 32 | BLINKER_LOG2("AHRS Roll: ", Blinker.ahrs(Roll)); 33 | BLINKER_LOG2("AHRS Pitch: ", Blinker.ahrs(Pitch)); 34 | 35 | Blinker.delay(2000); 36 | } -------------------------------------------------------------------------------- /examples/Blinker_AHRS/AHRS_WiFi/AHRS_WiFi.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_WIFI 3 | 4 | #include 5 | 6 | char ssid[] = "Your WiFi network SSID or name"; 7 | char pswd[] = "Your WiFi network WPA password or WEP key"; 8 | 9 | void setup() 10 | { 11 | Serial.begin(115200); 12 | 13 | pinMode(LED_BUILTIN, OUTPUT); 14 | digitalWrite(LED_BUILTIN, LOW); 15 | 16 | Blinker.begin(ssid, pswd); 17 | Blinker.attachAhrs(); 18 | } 19 | 20 | void loop() 21 | { 22 | Blinker.run(); 23 | 24 | if (Blinker.available()) { 25 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 26 | 27 | Blinker.vibrate(); 28 | 29 | uint32_t BlinkerTime = millis(); 30 | Blinker.print(BlinkerTime); 31 | Blinker.print("millis", BlinkerTime); 32 | } 33 | 34 | BLINKER_LOG2("AHRS Yaw: ", Blinker.ahrs(Yaw)); 35 | BLINKER_LOG2("AHRS Roll: ", Blinker.ahrs(Roll)); 36 | BLINKER_LOG2("AHRS Pitch: ", Blinker.ahrs(Pitch)); 37 | 38 | Blinker.delay(2000); 39 | } -------------------------------------------------------------------------------- /examples/Blinker_APCONFIG/APCONFIG_WiFi/APCONFIG_WiFi.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_WIFI 3 | #define BLINKER_APCONFIG 4 | 5 | #include 6 | 7 | #define BUTTON_1 "ButtonKey" 8 | 9 | void setup() 10 | { 11 | Serial.begin(115200); 12 | 13 | pinMode(LED_BUILTIN, OUTPUT); 14 | digitalWrite(LED_BUILTIN, LOW); 15 | 16 | Blinker.begin(); 17 | Blinker.wInit(BUTTON_1, W_BUTTON); 18 | } 19 | 20 | void loop() 21 | { 22 | Blinker.run(); 23 | 24 | if (Blinker.available()) { 25 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 26 | 27 | uint32_t BlinkerTime = millis(); 28 | 29 | Blinker.beginFormat(); 30 | Blinker.vibrate(); 31 | Blinker.print("millis", BlinkerTime); 32 | Blinker.endFormat(); 33 | } 34 | 35 | if (Blinker.button(BUTTON_1)) { 36 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 37 | } 38 | } -------------------------------------------------------------------------------- /examples/Blinker_AQI/AQI_MQTT/AQI_MQTT.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_MQTT 3 | 4 | #include 5 | 6 | char auth[] = "Your MQTT Secret Key"; 7 | char ssid[] = "Your WiFi network SSID or name"; 8 | char pswd[] = "Your WiFi network WPA password or WEP key"; 9 | 10 | #define BUTTON_1 "ButtonKey" 11 | 12 | void setup() { 13 | Serial.begin(115200); 14 | 15 | pinMode(LED_BUILTIN, OUTPUT); 16 | digitalWrite(LED_BUILTIN, LOW); 17 | 18 | Blinker.begin(auth, ssid, pswd); 19 | Blinker.wInit(BUTTON_1, W_BUTTON); 20 | } 21 | 22 | void loop() 23 | { 24 | Blinker.run(); 25 | 26 | if (Blinker.available()) { 27 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 28 | 29 | uint32_t BlinkerTime = millis(); 30 | 31 | Blinker.beginFormat(); 32 | Blinker.vibrate(); 33 | Blinker.print("millis", BlinkerTime); 34 | Blinker.endFormat(); 35 | } 36 | 37 | if (Blinker.button(BUTTON_1)) { 38 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 39 | String get_aqi = Blinker.aqi(); 40 | 41 | BLINKER_LOG2("AQI: ", get_aqi); 42 | 43 | Blinker.delay(6000); 44 | } 45 | } -------------------------------------------------------------------------------- /examples/Blinker_AQI/AQI_WiFi/AQI_WiFi.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | 3 | #include 4 | 5 | char ssid[] = "Your WiFi network SSID or name"; 6 | char pswd[] = "Your WiFi network WPA password or WEP key"; 7 | 8 | #define BUTTON_1 "ButtonKey" 9 | 10 | void setup() { 11 | Serial.begin(115200); 12 | 13 | pinMode(LED_BUILTIN, OUTPUT); 14 | digitalWrite(LED_BUILTIN, LOW); 15 | 16 | Blinker.begin(ssid, pswd); 17 | Blinker.wInit(BUTTON_1, W_BUTTON); 18 | } 19 | 20 | void loop() 21 | { 22 | Blinker.run(); 23 | 24 | if (Blinker.available()) { 25 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 26 | 27 | uint32_t BlinkerTime = millis(); 28 | 29 | Blinker.beginFormat(); 30 | Blinker.vibrate(); 31 | Blinker.print("millis", BlinkerTime); 32 | Blinker.endFormat(); 33 | } 34 | 35 | if (Blinker.button(BUTTON_1)) { 36 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 37 | String get_aqi = Blinker.aqi(); 38 | 39 | BLINKER_LOG2("AQI: ", get_aqi); 40 | 41 | Blinker.delay(6000); 42 | } 43 | } -------------------------------------------------------------------------------- /examples/Blinker_AUTO/AUTO_MQTT/AUTO_MQTT.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * This example not complete at all, TODO. 4 | * 5 | * / 6 | 7 | // #define BLINKER_PRINT Serial 8 | // #define BLINKER_MQTT 9 | 10 | // #include 11 | 12 | // char auth[] = "Your MQTT Secret Key"; 13 | // char ssid[] = "Your WiFi network SSID or name"; 14 | // char pswd[] = "Your WiFi network WPA password or WEP key"; 15 | 16 | // #define BUTTON_1 "ButtonKey" 17 | 18 | // void setup() { 19 | // Serial.begin(115200); 20 | 21 | // pinMode(LED_BUILTIN, OUTPUT); 22 | // digitalWrite(LED_BUILTIN, LOW); 23 | 24 | // Blinker.begin(auth, ssid, pswd); 25 | // Blinker.beginAuto(); 26 | // Blinker.wInit(BUTTON_1, W_BUTTON); 27 | // } 28 | 29 | // void loop() 30 | // { 31 | // Blinker.run(); 32 | 33 | // if (Blinker.available()) { 34 | // BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 35 | 36 | // uint32_t BlinkerTime = millis(); 37 | 38 | // Blinker.beginFormat(); 39 | // Blinker.vibrate(); 40 | // Blinker.print("millis", BlinkerTime); 41 | // Blinker.endFormat(); 42 | // } 43 | 44 | // if (Blinker.button(BUTTON_1)) { 45 | // digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 46 | // } 47 | 48 | // Blinker.autoInput("key", "value"); 49 | // Blinker.autoRun(); 50 | 51 | // Blinker.delay(1000); 52 | // } -------------------------------------------------------------------------------- /examples/Blinker_BUILTINSWITCH/BUILTINSWITCH_BLE/BUILTINSWITCH_BLE.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_BLE 3 | 4 | #include 5 | 6 | void setup() { 7 | Serial.begin(115200); 8 | 9 | pinMode(LED_BUILTIN, OUTPUT); 10 | digitalWrite(LED_BUILTIN, LOW); 11 | 12 | Blinker.begin(); 13 | } 14 | 15 | void loop() 16 | { 17 | Blinker.run(); 18 | 19 | if (Blinker.available()) { 20 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 21 | 22 | uint32_t BlinkerTime = millis(); 23 | 24 | Blinker.beginFormat(); 25 | Blinker.vibrate(); 26 | Blinker.print("millis", BlinkerTime); 27 | Blinker.endFormat(); 28 | } 29 | 30 | if (Blinker.switchAvailable()) { 31 | if (Blinker.switchGet()) { 32 | digitalWrite(LED_BUILTIN, HIGH); 33 | 34 | BLINKER_LOG1("builtInSwitch on"); 35 | 36 | Blinker.switchUpdate(); 37 | } 38 | else { 39 | digitalWrite(LED_BUILTIN, LOW); 40 | 41 | BLINKER_LOG1("builtInSwitch off"); 42 | 43 | Blinker.switchUpdate(); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /examples/Blinker_BUILTINSWITCH/BUILTINSWITCH_WiFi/BUILTINSWITCH_WiFi.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_WIFI 3 | 4 | #include 5 | 6 | char ssid[] = "Your WiFi network SSID or name"; 7 | char pswd[] = "Your WiFi network WPA password or WEP key"; 8 | 9 | void setup() { 10 | Serial.begin(115200); 11 | 12 | pinMode(LED_BUILTIN, OUTPUT); 13 | digitalWrite(LED_BUILTIN, LOW); 14 | 15 | Blinker.begin(ssid, pswd); 16 | } 17 | 18 | void loop() 19 | { 20 | Blinker.run(); 21 | 22 | if (Blinker.available()) { 23 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 24 | 25 | uint32_t BlinkerTime = millis(); 26 | 27 | Blinker.beginFormat(); 28 | Blinker.vibrate(); 29 | Blinker.print("millis", BlinkerTime); 30 | Blinker.endFormat(); 31 | } 32 | 33 | if (Blinker.switchAvailable()) { 34 | if (Blinker.switchGet()) { 35 | digitalWrite(LED_BUILTIN, HIGH); 36 | 37 | BLINKER_LOG1("builtInSwitch on"); 38 | 39 | Blinker.switchUpdate(); 40 | } 41 | else { 42 | digitalWrite(LED_BUILTIN, LOW); 43 | 44 | BLINKER_LOG1("builtInSwitch off"); 45 | 46 | Blinker.switchUpdate(); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /examples/Blinker_Bridge/Bridge_MQTT/Bridge_MQTT.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_MQTT 3 | 4 | #include 5 | 6 | char auth[] = "Your MQTT Secret Key"; 7 | char ssid[] = "Your WiFi network SSID or name"; 8 | char pswd[] = "Your WiFi network WPA password or WEP key"; 9 | 10 | char bridgeKey[] = "Your MQTT Secret Key of bridge to device"; 11 | 12 | #define BUTTON_1 "ButtonKey" 13 | 14 | void setup() { 15 | Serial.begin(115200); 16 | 17 | pinMode(LED_BUILTIN, OUTPUT); 18 | digitalWrite(LED_BUILTIN, LOW); 19 | 20 | Blinker.begin(auth, ssid, pswd); 21 | Blinker.bridge(bridgeKey); 22 | Blinker.wInit(BUTTON_1, W_BUTTON); 23 | 24 | while (!Blinker.connected()) { 25 | Blinker.delay(10); 26 | } 27 | } 28 | 29 | void loop() 30 | { 31 | Blinker.run(); 32 | 33 | if (Blinker.available()) { 34 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 35 | 36 | uint32_t BlinkerTime = millis(); 37 | 38 | Blinker.beginFormat(); 39 | Blinker.vibrate(); 40 | Blinker.print("millis", BlinkerTime); 41 | Blinker.endFormat(); 42 | } 43 | 44 | if (Blinker.bridgeAvailable(bridgeKey)) { 45 | BLINKER_LOG2("Blinker.bridgeRead(): ", Blinker.bridgeRead(bridgeKey)); 46 | } 47 | 48 | if (Blinker.button(BUTTON_1)) { 49 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 50 | 51 | uint32_t BlinkerTime = millis(); 52 | 53 | Blinker.bridgeBeginFormat(); 54 | Blinker.bridgePrint(bridgeKey, "Hello", "Blinker"); 55 | Blinker.bridgePrint(bridgeKey, "millis", BlinkerTime); 56 | Blinker.bridgeEndFormat(); 57 | 58 | Blinker.delay(60000); 59 | } 60 | } -------------------------------------------------------------------------------- /examples/Blinker_Button/Button_BLE/Button_BLE.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_BLE 3 | 4 | #include 5 | 6 | #define BUTTON_1 "ButtonKey" 7 | #define TAP_EXAMPLE 8 | 9 | void setup() 10 | { 11 | Serial.begin(115200); 12 | 13 | pinMode(LED_BUILTIN, OUTPUT); 14 | digitalWrite(LED_BUILTIN, LOW); 15 | 16 | Blinker.begin(); 17 | Blinker.wInit(BUTTON_1, W_BUTTON); 18 | } 19 | 20 | void loop() 21 | { 22 | Blinker.run(); 23 | 24 | if (Blinker.available()) { 25 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 26 | 27 | Blinker.vibrate(); 28 | 29 | uint32_t BlinkerTime = millis(); 30 | Blinker.print(BlinkerTime); 31 | Blinker.print("millis", BlinkerTime); 32 | } 33 | 34 | #if defined(TAP_EXAMPLE) 35 | if (Blinker.button(BUTTON_1)) { 36 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 37 | } // simple tap 38 | #else 39 | if (Blinker.button(BUTTON_1)) { 40 | digitalWrite(LED_BUILTIN, LOW); 41 | } 42 | else { 43 | digitalWrite(LED_BUILTIN, HIGH); 44 | } //long press 45 | #endif 46 | } -------------------------------------------------------------------------------- /examples/Blinker_Button/Button_WiFi/Button_WiFi.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_WIFI 3 | 4 | #include 5 | 6 | char ssid[] = "Your WiFi network SSID or name"; 7 | char pswd[] = "Your WiFi network WPA password or WEP key"; 8 | 9 | #define BUTTON_1 "ButtonKey" 10 | #define TAP_EXAMPLE 11 | 12 | void setup() 13 | { 14 | Serial.begin(115200); 15 | 16 | pinMode(LED_BUILTIN, OUTPUT); 17 | digitalWrite(LED_BUILTIN, LOW); 18 | 19 | Blinker.begin(ssid, pswd); 20 | Blinker.wInit(BUTTON_1, W_BUTTON); 21 | } 22 | 23 | void loop() 24 | { 25 | Blinker.run(); 26 | 27 | if (Blinker.available()) { 28 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 29 | 30 | Blinker.vibrate(); 31 | 32 | uint32_t BlinkerTime = millis(); 33 | Blinker.print(BlinkerTime); 34 | Blinker.print("millis", BlinkerTime); 35 | } 36 | 37 | #if defined(TAP_EXAMPLE) 38 | if (Blinker.button(BUTTON_1)) { 39 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 40 | } // simple tap 41 | #else 42 | if (Blinker.button(BUTTON_1)) { 43 | digitalWrite(LED_BUILTIN, LOW); 44 | } 45 | else { 46 | digitalWrite(LED_BUILTIN, HIGH); 47 | } //long press 48 | #endif 49 | } 50 | -------------------------------------------------------------------------------- /examples/Blinker_CLOUD/CLOUD_MQTT/CLOUD_MQTT.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_MQTT 3 | 4 | #include 5 | 6 | char auth[] = "Your MQTT Secret Key"; 7 | char ssid[] = "Your WiFi network SSID or name"; 8 | char pswd[] = "Your WiFi network WPA password or WEP key"; 9 | 10 | #define BUTTON_1 "ButtonKey" 11 | 12 | void setup() { 13 | Serial.begin(115200); 14 | 15 | pinMode(LED_BUILTIN, OUTPUT); 16 | digitalWrite(LED_BUILTIN, LOW); 17 | 18 | Blinker.begin(auth, ssid, pswd); 19 | Blinker.wInit(BUTTON_1, W_BUTTON); 20 | } 21 | 22 | void loop() 23 | { 24 | Blinker.run(); 25 | 26 | if (Blinker.available()) { 27 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 28 | 29 | uint32_t BlinkerTime = millis(); 30 | 31 | Blinker.beginFormat(); 32 | Blinker.vibrate(); 33 | Blinker.print("millis", BlinkerTime); 34 | Blinker.endFormat(); 35 | } 36 | 37 | if (Blinker.button(BUTTON_1)) { 38 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 39 | if (Blinker.cloudUpdate("Hello blinker!")) { 40 | String cloud_data = Blinker.cloudGet(); 41 | 42 | BLINKER_LOG2("Blinker.cloudGet(): ", cloud_data); 43 | } 44 | 45 | Blinker.delay(6000); 46 | } 47 | } -------------------------------------------------------------------------------- /examples/Blinker_DHT/DHT_BLE/DHT_BLE.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_BLE 3 | 4 | #include 5 | 6 | #include 7 | 8 | #define DHTPIN 4 9 | 10 | //#define DHTTYPE DHT11 // DHT 11 11 | #define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 12 | //#define DHTTYPE DHT21 // DHT 21 (AM2301) 13 | 14 | DHT dht(DHTPIN, DHTTYPE); 15 | 16 | void setup() 17 | { 18 | Serial.begin(115200); 19 | 20 | pinMode(LED_BUILTIN, OUTPUT); 21 | digitalWrite(LED_BUILTIN, LOW); 22 | 23 | Blinker.begin(); 24 | dht.begin(); 25 | } 26 | 27 | void loop() 28 | { 29 | Blinker.run(); 30 | 31 | if (Blinker.available()) { 32 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 33 | 34 | Blinker.vibrate(); 35 | 36 | uint32_t BlinkerTime = millis(); 37 | Blinker.print(BlinkerTime); 38 | Blinker.print("millis", BlinkerTime); 39 | } 40 | 41 | float h = dht.readHumidity(); 42 | float t = dht.readTemperature(); 43 | 44 | if (isnan(h) || isnan(t)) { 45 | BLINKER_LOG1("Failed to read from DHT sensor!"); 46 | return; 47 | } 48 | 49 | float hic = dht.computeHeatIndex(t, h, false); 50 | 51 | BLINKER_LOG3("Humidity: ", h, " %"); 52 | BLINKER_LOG3("Temperature: ", t, " *C"); 53 | BLINKER_LOG3("Heat index: ", hic, " *C"); 54 | 55 | Blinker.print("humi", h, " %"); 56 | Blinker.print("temp", t, " *C"); 57 | Blinker.print("hic", hic, " *C"); 58 | 59 | Blinker.delay(2000); 60 | } -------------------------------------------------------------------------------- /examples/Blinker_DHT/DHT_WiFi/DHT_WiFi.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_WIFI 3 | 4 | #include 5 | 6 | char ssid[] = "Your WiFi network SSID or name"; 7 | char pswd[] = "Your WiFi network WPA password or WEP key"; 8 | 9 | #include 10 | 11 | #define DHTPIN 4 12 | 13 | //#define DHTTYPE DHT11 // DHT 11 14 | #define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 15 | //#define DHTTYPE DHT21 // DHT 21 (AM2301) 16 | 17 | DHT dht(DHTPIN, DHTTYPE); 18 | 19 | void setup() 20 | { 21 | Serial.begin(115200); 22 | 23 | pinMode(LED_BUILTIN, OUTPUT); 24 | digitalWrite(LED_BUILTIN, LOW); 25 | 26 | Blinker.begin(ssid, pswd); 27 | dht.begin(); 28 | } 29 | 30 | void loop() 31 | { 32 | Blinker.run(); 33 | 34 | if (Blinker.available()) { 35 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 36 | 37 | Blinker.vibrate(); 38 | 39 | uint32_t BlinkerTime = millis(); 40 | Blinker.print(BlinkerTime); 41 | Blinker.print("millis", BlinkerTime); 42 | } 43 | 44 | float h = dht.readHumidity(); 45 | float t = dht.readTemperature(); 46 | 47 | if (isnan(h) || isnan(t)) { 48 | BLINKER_LOG1("Failed to read from DHT sensor!"); 49 | return; 50 | } 51 | 52 | float hic = dht.computeHeatIndex(t, h, false); 53 | 54 | BLINKER_LOG3("Humidity: ", h, " %"); 55 | BLINKER_LOG3("Temperature: ", t, " *C"); 56 | BLINKER_LOG3("Heat index: ", hic, " *C"); 57 | 58 | Blinker.print("humi", h, " %"); 59 | Blinker.print("temp", t, " *C"); 60 | Blinker.print("hic", hic, " *C"); 61 | 62 | Blinker.delay(2000); 63 | } -------------------------------------------------------------------------------- /examples/Blinker_ESPTOUCH/ESPTOUCH_MQTT/ESPTOUCH_MQTT.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_MQTT 3 | #define BLINKER_ESP_SMARTCONFIG 4 | 5 | #include 6 | 7 | char auth[] = "Your MQTT Secret Key"; 8 | 9 | #define BUTTON_1 "ButtonKey" 10 | 11 | void setup() 12 | { 13 | Serial.begin(115200); 14 | 15 | pinMode(LED_BUILTIN, OUTPUT); 16 | digitalWrite(LED_BUILTIN, LOW); 17 | 18 | Blinker.begin(auth); 19 | Blinker.wInit(BUTTON_1, W_BUTTON); 20 | } 21 | 22 | void loop() 23 | { 24 | Blinker.run(); 25 | 26 | if (Blinker.available()) { 27 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 28 | 29 | uint32_t BlinkerTime = millis(); 30 | 31 | Blinker.beginFormat(); 32 | Blinker.vibrate(); 33 | Blinker.print("millis", BlinkerTime); 34 | Blinker.endFormat(); 35 | } 36 | 37 | if (Blinker.button(BUTTON_1)) { 38 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 39 | } 40 | } -------------------------------------------------------------------------------- /examples/Blinker_ESPTOUCH/ESPTOUCH_WiFi/ESPTOUCH_WiFi.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_WIFI 3 | #define BLINKER_ESP_SMARTCONFIG 4 | 5 | #include 6 | 7 | #define BUTTON_1 "ButtonKey" 8 | 9 | void setup() 10 | { 11 | Serial.begin(115200); 12 | 13 | pinMode(LED_BUILTIN, OUTPUT); 14 | digitalWrite(LED_BUILTIN, LOW); 15 | 16 | Blinker.begin(); 17 | Blinker.wInit(BUTTON_1, W_BUTTON); 18 | } 19 | 20 | void loop() 21 | { 22 | Blinker.run(); 23 | 24 | if (Blinker.available()) { 25 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 26 | 27 | uint32_t BlinkerTime = millis(); 28 | 29 | Blinker.beginFormat(); 30 | Blinker.vibrate(); 31 | Blinker.print("millis", BlinkerTime); 32 | Blinker.endFormat(); 33 | } 34 | 35 | if (Blinker.button(BUTTON_1)) { 36 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 37 | } 38 | } -------------------------------------------------------------------------------- /examples/Blinker_GPS/GPS_BLE/GPS_BLE.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_BLE 3 | 4 | #include 5 | 6 | void setup() 7 | { 8 | Serial.begin(115200); 9 | 10 | pinMode(LED_BUILTIN, OUTPUT); 11 | digitalWrite(LED_BUILTIN, LOW); 12 | 13 | Blinker.begin(); 14 | } 15 | 16 | void loop() 17 | { 18 | Blinker.run(); 19 | 20 | if (Blinker.available()) { 21 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 22 | 23 | Blinker.vibrate(); 24 | 25 | uint32_t BlinkerTime = millis(); 26 | Blinker.print(BlinkerTime); 27 | Blinker.print("millis", BlinkerTime); 28 | } 29 | 30 | BLINKER_LOG2("GPS LONG.: ", Blinker.gps(LONG)); 31 | BLINKER_LOG2("GPS LAT.: ", Blinker.gps(LAT)); 32 | 33 | Blinker.delay(2000); 34 | } -------------------------------------------------------------------------------- /examples/Blinker_GPS/GPS_WiFi/GPS_WiFi.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_WIFI 3 | 4 | #include 5 | 6 | char ssid[] = "Your WiFi network SSID or name"; 7 | char pswd[] = "Your WiFi network WPA password or WEP key"; 8 | 9 | void setup() 10 | { 11 | Serial.begin(115200); 12 | 13 | pinMode(LED_BUILTIN, OUTPUT); 14 | digitalWrite(LED_BUILTIN, LOW); 15 | 16 | Blinker.begin(ssid, pswd); 17 | } 18 | 19 | void loop() 20 | { 21 | Blinker.run(); 22 | 23 | if (Blinker.available()) { 24 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 25 | 26 | Blinker.vibrate(); 27 | 28 | uint32_t BlinkerTime = millis(); 29 | Blinker.print(BlinkerTime); 30 | Blinker.print("millis", BlinkerTime); 31 | } 32 | 33 | BLINKER_LOG2("GPS LONG.: ", Blinker.gps(LONG)); 34 | BLINKER_LOG2("GPS LAT.: ", Blinker.gps(LAT)); 35 | 36 | Blinker.delay(2000); 37 | } -------------------------------------------------------------------------------- /examples/Blinker_Joystick/Joystick_BLE/Joystick_BLE.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_BLE 3 | 4 | #include 5 | 6 | void setup() 7 | { 8 | Serial.begin(115200); 9 | 10 | pinMode(LED_BUILTIN, OUTPUT); 11 | digitalWrite(LED_BUILTIN, LOW); 12 | 13 | Blinker.begin(); 14 | } 15 | 16 | void loop() 17 | { 18 | Blinker.run(); 19 | 20 | if (Blinker.available()) { 21 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 22 | 23 | Blinker.vibrate(); 24 | 25 | uint32_t BlinkerTime = millis(); 26 | Blinker.print(BlinkerTime); 27 | Blinker.print("millis", BlinkerTime); 28 | } 29 | 30 | BLINKER_LOG2("Joystick X axis: ", Blinker.joystick(J_Xaxis)); 31 | BLINKER_LOG2("Joystick Y axis: ", Blinker.joystick(J_Yaxis)); 32 | 33 | Blinker.delay(2000); 34 | } -------------------------------------------------------------------------------- /examples/Blinker_Joystick/Joystick_WiFi/Joystick_WiFi.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_WIFI 3 | 4 | #include 5 | 6 | char ssid[] = "Your WiFi network SSID or name"; 7 | char pswd[] = "Your WiFi network WPA password or WEP key"; 8 | 9 | void setup() 10 | { 11 | Serial.begin(115200); 12 | 13 | pinMode(LED_BUILTIN, OUTPUT); 14 | digitalWrite(LED_BUILTIN, LOW); 15 | 16 | Blinker.begin(ssid, pswd); 17 | } 18 | 19 | void loop() 20 | { 21 | Blinker.run(); 22 | 23 | if (Blinker.available()) { 24 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 25 | 26 | Blinker.vibrate(); 27 | 28 | uint32_t BlinkerTime = millis(); 29 | Blinker.print(BlinkerTime); 30 | Blinker.print("millis", BlinkerTime); 31 | } 32 | 33 | BLINKER_LOG2("Joystick X axis: ", Blinker.joystick(J_Xaxis)); 34 | BLINKER_LOG2("Joystick Y axis: ", Blinker.joystick(J_Yaxis)); 35 | 36 | Blinker.delay(2000); 37 | } -------------------------------------------------------------------------------- /examples/Blinker_MQTT/MQTT_WiFi/MQTT_WiFi.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_MQTT 3 | 4 | #include 5 | 6 | char auth[] = "Your MQTT Secret Key"; 7 | char ssid[] = "Your WiFi network SSID or name"; 8 | char pswd[] = "Your WiFi network WPA password or WEP key"; 9 | 10 | #define BUTTON_1 "ButtonKey" 11 | 12 | void setup() { 13 | Serial.begin(115200); 14 | 15 | pinMode(LED_BUILTIN, OUTPUT); 16 | digitalWrite(LED_BUILTIN, LOW); 17 | 18 | Blinker.begin(auth, ssid, pswd); 19 | Blinker.wInit(BUTTON_1, W_BUTTON); 20 | } 21 | 22 | void loop() 23 | { 24 | Blinker.run(); 25 | 26 | if (Blinker.available()) { 27 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 28 | 29 | uint32_t BlinkerTime = millis(); 30 | 31 | Blinker.beginFormat(); 32 | Blinker.vibrate(); 33 | Blinker.print("millis", BlinkerTime); 34 | Blinker.endFormat(); 35 | } 36 | 37 | if (Blinker.button(BUTTON_1)) { 38 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 39 | } 40 | } -------------------------------------------------------------------------------- /examples/Blinker_Notify/Notify_BLE/Notify_BLE.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_BLE 3 | 4 | #include 5 | 6 | #define BUTTON_1 "ButtonKey" 7 | 8 | void setup() 9 | { 10 | Serial.begin(115200); 11 | 12 | pinMode(LED_BUILTIN, OUTPUT); 13 | digitalWrite(LED_BUILTIN, LOW); 14 | 15 | Blinker.begin(); 16 | Blinker.wInit(BUTTON_1, W_BUTTON); 17 | } 18 | 19 | void loop() 20 | { 21 | Blinker.run(); 22 | 23 | if (Blinker.available()) { 24 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 25 | 26 | Blinker.vibrate(); 27 | 28 | uint32_t BlinkerTime = millis(); 29 | Blinker.print(BlinkerTime); 30 | Blinker.print("millis", BlinkerTime); 31 | } 32 | 33 | if (Blinker.button(BUTTON_1)) { 34 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 35 | Blinker.notify("!Button Pressed!"); 36 | } 37 | } -------------------------------------------------------------------------------- /examples/Blinker_Notify/Notify_WiFi/Notify_WiFi.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_WIFI 3 | 4 | #define BUTTON_1 "ButtonKey" 5 | 6 | #include 7 | 8 | char ssid[] = "Your WiFi network SSID or name"; 9 | char pswd[] = "Your WiFi network WPA password or WEP key"; 10 | 11 | void setup() 12 | { 13 | Serial.begin(115200); 14 | 15 | pinMode(LED_BUILTIN, OUTPUT); 16 | digitalWrite(LED_BUILTIN, LOW); 17 | 18 | Blinker.begin(ssid, pswd); 19 | Blinker.wInit(BUTTON_1, W_BUTTON); 20 | } 21 | 22 | void loop() 23 | { 24 | Blinker.run(); 25 | 26 | if (Blinker.available()) { 27 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 28 | 29 | Blinker.vibrate(); 30 | 31 | uint32_t BlinkerTime = millis(); 32 | Blinker.print(BlinkerTime); 33 | Blinker.print("millis", BlinkerTime); 34 | } 35 | 36 | if (Blinker.button(BUTTON_1)) { 37 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 38 | Blinker.notify("!Button Pressed!"); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /examples/Blinker_PRO/Blinker_PRO/Blinker_PRO.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * BLINKER_PRO is use for professional device 3 | * 4 | * Please make sure you have permission to modify professional device! 5 | * Please read usermanual first! Thanks! 6 | * https://doc.blinker.app/ 7 | * 8 | * Written by i3water for blinker. 9 | * Learn more:https://blinker.app/ 10 | */ 11 | 12 | #define BLINKER_PRINT Serial 13 | #define BLINKER_PRO 14 | #define BLINKER_BUTTON 15 | #define BLINKER_BUTTON_PIN D7 16 | 17 | #include 18 | 19 | #define BUTTON_1 "ButtonKey" 20 | 21 | /* 22 | * Add your command parse code in this function 23 | * 24 | * When get a command and device not parsed this command, device will call this function 25 | */ 26 | bool dataParse(const JsonObject & data) { 27 | String getData; 28 | 29 | data.printTo(getData); 30 | 31 | BLINKER_LOG2("Get user command: ", getData); 32 | return true; 33 | } 34 | 35 | /* 36 | * Add your heartbeat message detail in this function 37 | * 38 | * When get heartbeat command {"get": "state"}, device will call this function 39 | * For example, you can print message back 40 | * 41 | * Every 30s will get a heartbeat command from app 42 | */ 43 | void heartbeat() { 44 | Blinker.print("hello", "blinker"); 45 | 46 | BLINKER_LOG1("heartbeat!"); 47 | } 48 | 49 | #if defined(BLINKER_BUTTON) 50 | /* 51 | * Blinker provide a button parse function for user if you defined BLINKER_BUTTON 52 | * 53 | * Blinker button can detect singal click/ double click/ long press 54 | * 55 | * Blinker.tick() will run by default, use interrupt will be better 56 | */ 57 | void buttonTick() { 58 | Blinker.tick(); 59 | } 60 | 61 | /* 62 | * Add your code in this function 63 | * 64 | * When button clicked, device will call this function 65 | */ 66 | void singalClick() { 67 | BLINKER_LOG1("Button clicked!"); 68 | } 69 | 70 | /* 71 | * Add your code in this function 72 | * 73 | * When button double clicked, device will call this function 74 | */ 75 | void doubleClick() { 76 | BLINKER_LOG1("Button double clicked!"); 77 | } 78 | #endif 79 | 80 | void setup() { 81 | Serial.begin(115200); 82 | 83 | pinMode(LED_BUILTIN, OUTPUT); 84 | digitalWrite(LED_BUILTIN, LOW); 85 | 86 | 87 | Blinker.begin(BLINKER_AIR_DETECTOR); 88 | Blinker.wInit(BUTTON_1, W_BUTTON); 89 | 90 | Blinker.attachParse(dataParse); 91 | Blinker.attachHeartbeat(heartbeat); 92 | 93 | #if defined(BLINKER_BUTTON) 94 | Blinker.attachClick(singalClick); 95 | Blinker.attachDoubleClick(doubleClick); 96 | attachInterrupt(BLINKER_BUTTON_PIN, buttonTick, CHANGE); 97 | #endif 98 | } 99 | 100 | void loop() 101 | { 102 | Blinker.run(); 103 | 104 | if (Blinker.available()) { 105 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 106 | 107 | uint32_t BlinkerTime = millis(); 108 | 109 | Blinker.beginFormat(); 110 | Blinker.vibrate(); 111 | Blinker.print("millis", BlinkerTime); 112 | Blinker.endFormat(); 113 | } 114 | 115 | if (Blinker.button(BUTTON_1)) { 116 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 117 | } 118 | } -------------------------------------------------------------------------------- /examples/Blinker_Print/Print_BLE/Print_BLE.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_BLE 3 | 4 | #include 5 | 6 | #define SLIDER_1 "SliderKey" 7 | #define TOGGLE_1 "ToggleKey" 8 | #define TEXT_1 "millis" 9 | 10 | void setup() 11 | { 12 | Serial.begin(115200); 13 | 14 | pinMode(LED_BUILTIN, OUTPUT); 15 | digitalWrite(LED_BUILTIN, LOW); 16 | 17 | Blinker.begin(); 18 | Blinker.wInit(SLIDER_1, W_SLIDER); 19 | Blinker.wInit(TOGGLE_1, W_TOGGLE); 20 | } 21 | 22 | uint8_t s_value = 0; 23 | bool on_off = false; 24 | 25 | void loop() 26 | { 27 | Blinker.run(); 28 | 29 | if (Blinker.available()) { 30 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 31 | 32 | Blinker.vibrate(); 33 | 34 | uint32_t BlinkerTime = millis(); 35 | Blinker.print(BlinkerTime); 36 | Blinker.print(TEXT_1, BlinkerTime); 37 | } 38 | 39 | Blinker.print(SLIDER_1, s_value); 40 | Blinker.print(TOGGLE_1, on_off?"on":"off"); 41 | Blinker.print(TEXT_1, millis()); 42 | 43 | digitalWrite(LED_BUILTIN, on_off); 44 | 45 | s_value++; 46 | on_off = !on_off; 47 | 48 | Blinker.delay(1000); 49 | } -------------------------------------------------------------------------------- /examples/Blinker_Print/Print_WiFi/Print_WiFi.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_WIFI 3 | 4 | #include 5 | 6 | char ssid[] = "Your WiFi network SSID or name"; 7 | char pswd[] = "Your WiFi network WPA password or WEP key"; 8 | 9 | #define SLIDER_1 "SliderKey" 10 | #define TOGGLE_1 "ToggleKey" 11 | #define TEXT_1 "millis" 12 | 13 | void setup() 14 | { 15 | Serial.begin(115200); 16 | 17 | pinMode(LED_BUILTIN, OUTPUT); 18 | digitalWrite(LED_BUILTIN, LOW); 19 | 20 | Blinker.begin(ssid, pswd); 21 | Blinker.wInit(SLIDER_1, W_SLIDER); 22 | Blinker.wInit(TOGGLE_1, W_TOGGLE); 23 | } 24 | 25 | uint8_t s_value = 0; 26 | bool on_off = false; 27 | 28 | void loop() 29 | { 30 | Blinker.run(); 31 | 32 | if (Blinker.available()) { 33 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 34 | 35 | Blinker.vibrate(); 36 | 37 | uint32_t BlinkerTime = millis(); 38 | Blinker.print(BlinkerTime); 39 | Blinker.print(TEXT_1, BlinkerTime); 40 | } 41 | 42 | Blinker.print(SLIDER_1, s_value); 43 | Blinker.print(TOGGLE_1, on_off?"on":"off"); 44 | Blinker.print(TEXT_1, millis()); 45 | 46 | digitalWrite(LED_BUILTIN, on_off); 47 | 48 | s_value++; 49 | on_off = !on_off; 50 | 51 | Blinker.delay(1000); 52 | } -------------------------------------------------------------------------------- /examples/Blinker_Print_Format/Print_Format_BLE/Print_Format_BLE.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_BLE 3 | 4 | #include 5 | 6 | #define SLIDER_1 "SliderKey" 7 | #define TOGGLE_1 "ToggleKey" 8 | #define TEXT_1 "millis" 9 | 10 | void setup() 11 | { 12 | Serial.begin(115200); 13 | 14 | pinMode(LED_BUILTIN, OUTPUT); 15 | digitalWrite(LED_BUILTIN, LOW); 16 | 17 | Blinker.begin(); 18 | Blinker.wInit(SLIDER_1, W_SLIDER); 19 | Blinker.wInit(TOGGLE_1, W_TOGGLE); 20 | } 21 | 22 | uint8_t s_value = 0; 23 | bool on_off = false; 24 | 25 | void loop() 26 | { 27 | Blinker.run(); 28 | 29 | if (Blinker.available()) { 30 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 31 | 32 | Blinker.vibrate(); 33 | 34 | uint32_t BlinkerTime = millis(); 35 | Blinker.print(BlinkerTime); 36 | Blinker.print(TEXT_1, BlinkerTime); 37 | } 38 | 39 | Blinker.beginFormat(); 40 | Blinker.print(SLIDER_1, s_value); 41 | Blinker.print(TOGGLE_1, on_off?"on":"off"); 42 | Blinker.print(TEXT_1, millis()); 43 | Blinker.endFormat(); 44 | 45 | digitalWrite(LED_BUILTIN, on_off); 46 | 47 | s_value++; 48 | on_off = !on_off; 49 | 50 | Blinker.delay(1000); 51 | } -------------------------------------------------------------------------------- /examples/Blinker_Print_Format/Print_Format_WiFi/Print_Format_WiFi.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_WIFI 3 | 4 | #include 5 | 6 | char ssid[] = "Your WiFi network SSID or name"; 7 | char pswd[] = "Your WiFi network WPA password or WEP key"; 8 | 9 | #define SLIDER_1 "SliderKey" 10 | #define TOGGLE_1 "ToggleKey" 11 | #define TEXT_1 "millis" 12 | 13 | void setup() 14 | { 15 | Serial.begin(115200); 16 | 17 | pinMode(LED_BUILTIN, OUTPUT); 18 | digitalWrite(LED_BUILTIN, LOW); 19 | 20 | Blinker.begin(ssid, pswd); 21 | Blinker.wInit(SLIDER_1, W_SLIDER); 22 | Blinker.wInit(TOGGLE_1, W_TOGGLE); 23 | } 24 | 25 | uint8_t s_value = 0; 26 | bool on_off = false; 27 | 28 | void loop() 29 | { 30 | Blinker.run(); 31 | 32 | if (Blinker.available()) { 33 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 34 | 35 | Blinker.vibrate(); 36 | 37 | uint32_t BlinkerTime = millis(); 38 | Blinker.print(BlinkerTime); 39 | Blinker.print(TEXT_1, BlinkerTime); 40 | } 41 | 42 | Blinker.beginFormat(); 43 | Blinker.print(SLIDER_1, s_value); 44 | Blinker.print(TOGGLE_1, on_off?"on":"off"); 45 | Blinker.print(TEXT_1, millis()); 46 | Blinker.endFormat(); 47 | 48 | digitalWrite(LED_BUILTIN, on_off); 49 | 50 | s_value++; 51 | on_off = !on_off; 52 | 53 | Blinker.delay(1000); 54 | } -------------------------------------------------------------------------------- /examples/Blinker_RGB/RGB_BLE/RGB_BLE.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_BLE 3 | 4 | #include 5 | 6 | #define RGB1 "RGBKEY" 7 | 8 | void setup() 9 | { 10 | Serial.begin(115200); 11 | 12 | pinMode(LED_BUILTIN, OUTPUT); 13 | digitalWrite(LED_BUILTIN, LOW); 14 | 15 | Blinker.begin(); 16 | Blinker.wInit(RGB1, W_RGB); 17 | } 18 | 19 | void loop() 20 | { 21 | Blinker.run(); 22 | 23 | if (Blinker.available()) { 24 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 25 | 26 | Blinker.vibrate(); 27 | 28 | uint32_t BlinkerTime = millis(); 29 | Blinker.print(BlinkerTime); 30 | Blinker.print("millis", BlinkerTime); 31 | } 32 | 33 | BLINKER_LOG2("Red color: ", Blinker.rgb(RGB1,R)); 34 | BLINKER_LOG2("Green color: ", Blinker.rgb(RGB1,G)); 35 | BLINKER_LOG2("Blue color: ", Blinker.rgb(RGB1,B)); 36 | 37 | Blinker.delay(2000); 38 | } -------------------------------------------------------------------------------- /examples/Blinker_RGB/RGB_WiFi/RGB_WiFi.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_WIFI 3 | 4 | #include 5 | 6 | char ssid[] = "Your WiFi network SSID or name"; 7 | char pswd[] = "Your WiFi network WPA password or WEP key"; 8 | 9 | #define RGB1 "RGBKEY" 10 | 11 | void setup() 12 | { 13 | Serial.begin(115200); 14 | 15 | pinMode(LED_BUILTIN, OUTPUT); 16 | digitalWrite(LED_BUILTIN, LOW); 17 | 18 | Blinker.begin(ssid, pswd); 19 | Blinker.wInit(RGB1, W_RGB); 20 | } 21 | 22 | void loop() 23 | { 24 | Blinker.run(); 25 | 26 | if (Blinker.available()) { 27 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 28 | 29 | Blinker.vibrate(); 30 | 31 | uint32_t BlinkerTime = millis(); 32 | Blinker.print(BlinkerTime); 33 | Blinker.print("millis", BlinkerTime); 34 | } 35 | 36 | BLINKER_LOG2("Red color: ", Blinker.rgb(RGB1,R)); 37 | BLINKER_LOG2("Green color: ", Blinker.rgb(RGB1,G)); 38 | BLINKER_LOG2("Blue color: ", Blinker.rgb(RGB1,B)); 39 | 40 | Blinker.delay(2000); 41 | } -------------------------------------------------------------------------------- /examples/Blinker_SMS/SMS_MQTT/SMS_MQTT.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_MQTT 3 | 4 | #include 5 | 6 | char auth[] = "Your MQTT Secret Key"; 7 | char ssid[] = "Your WiFi network SSID or name"; 8 | char pswd[] = "Your WiFi network WPA password or WEP key"; 9 | 10 | #define BUTTON_1 "ButtonKey" 11 | 12 | void setup() { 13 | Serial.begin(115200); 14 | 15 | pinMode(LED_BUILTIN, OUTPUT); 16 | digitalWrite(LED_BUILTIN, LOW); 17 | 18 | Blinker.begin(auth, ssid, pswd); 19 | Blinker.wInit(BUTTON_1, W_BUTTON); 20 | } 21 | 22 | void loop() 23 | { 24 | Blinker.run(); 25 | 26 | if (Blinker.available()) { 27 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 28 | 29 | uint32_t BlinkerTime = millis(); 30 | 31 | Blinker.beginFormat(); 32 | Blinker.vibrate(); 33 | Blinker.print("millis", BlinkerTime); 34 | Blinker.endFormat(); 35 | } 36 | 37 | if (Blinker.button(BUTTON_1)) { 38 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 39 | Blinker.sms("Hello blinker!"); 40 | 41 | Blinker.delay(6000); 42 | } 43 | } -------------------------------------------------------------------------------- /examples/Blinker_SMS/SMS_WiFi/SMS_WiFi.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | 3 | #include 4 | 5 | char ssid[] = "Your WiFi network SSID or name"; 6 | char pswd[] = "Your WiFi network WPA password or WEP key"; 7 | 8 | #define BUTTON_1 "ButtonKey" 9 | 10 | void setup() { 11 | Serial.begin(115200); 12 | 13 | pinMode(LED_BUILTIN, OUTPUT); 14 | digitalWrite(LED_BUILTIN, LOW); 15 | 16 | Blinker.begin(ssid, pswd); 17 | Blinker.wInit(BUTTON_1, W_BUTTON); 18 | } 19 | 20 | void loop() 21 | { 22 | Blinker.run(); 23 | 24 | if (Blinker.available()) { 25 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 26 | 27 | uint32_t BlinkerTime = millis(); 28 | 29 | Blinker.beginFormat(); 30 | Blinker.vibrate(); 31 | Blinker.print("millis", BlinkerTime); 32 | Blinker.endFormat(); 33 | } 34 | 35 | if (Blinker.button(BUTTON_1)) { 36 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 37 | Blinker.sms("Hello blinker!"); 38 | 39 | Blinker.delay(6000); 40 | } 41 | } -------------------------------------------------------------------------------- /examples/Blinker_SR04/SR04_BLE/SR04_BLE.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_BLE 3 | 4 | #include 5 | 6 | #include 7 | 8 | Ultrasonic SR04(9, 8);// Trig, Echo 9 | 10 | void setup() 11 | { 12 | Serial.begin(115200); 13 | 14 | pinMode(LED_BUILTIN, OUTPUT); 15 | digitalWrite(LED_BUILTIN, LOW); 16 | 17 | Blinker.begin(); 18 | } 19 | 20 | void loop() 21 | { 22 | Blinker.run(); 23 | 24 | if (Blinker.available()) { 25 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 26 | 27 | Blinker.vibrate(); 28 | 29 | uint32_t BlinkerTime = millis(); 30 | Blinker.print(BlinkerTime); 31 | Blinker.print("millis", BlinkerTime); 32 | } 33 | 34 | BLINKER_LOG3("SR04: ", SR04.cm(), " cm"); 35 | 36 | Blinker.print("SR04", SR04.cm()); 37 | 38 | Blinker.delay(1000); 39 | } -------------------------------------------------------------------------------- /examples/Blinker_SR04/SR04_WiFi/SR04_WiFi.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_WIFI 3 | 4 | #include 5 | 6 | char ssid[] = "Your WiFi network SSID or name"; 7 | char pswd[] = "Your WiFi network WPA password or WEP key"; 8 | 9 | #include 10 | 11 | Ultrasonic SR04(9, 8);// Trig, Echo 12 | 13 | void setup() 14 | { 15 | Serial.begin(115200); 16 | 17 | pinMode(LED_BUILTIN, OUTPUT); 18 | digitalWrite(LED_BUILTIN, LOW); 19 | 20 | Blinker.begin(ssid, pswd); 21 | } 22 | 23 | void loop() 24 | { 25 | Blinker.run(); 26 | 27 | if (Blinker.available()) { 28 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 29 | 30 | Blinker.vibrate(); 31 | 32 | uint32_t BlinkerTime = millis(); 33 | Blinker.print(BlinkerTime); 34 | Blinker.print("millis", BlinkerTime); 35 | } 36 | 37 | BLINKER_LOG3("SR04: ", SR04.cm(), " cm"); 38 | 39 | Blinker.print("SR04", SR04.cm()); 40 | 41 | Blinker.delay(1000); 42 | } -------------------------------------------------------------------------------- /examples/Blinker_Slider/Slider_BLE/Slider_BLE.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_BLE 3 | 4 | #include 5 | 6 | #define SLIDER_1 "SliderKey" 7 | 8 | void setup() 9 | { 10 | Serial.begin(115200); 11 | 12 | pinMode(LED_BUILTIN, OUTPUT); 13 | digitalWrite(LED_BUILTIN, LOW); 14 | 15 | Blinker.begin(); 16 | Blinker.wInit(SLIDER_1, W_SLIDER); 17 | } 18 | 19 | void loop() 20 | { 21 | Blinker.run(); 22 | 23 | if (Blinker.available()) { 24 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 25 | 26 | Blinker.vibrate(); 27 | 28 | uint32_t BlinkerTime = millis(); 29 | Blinker.print(BlinkerTime); 30 | Blinker.print("millis", BlinkerTime); 31 | } 32 | 33 | BLINKER_LOG2("Slider read: ", Blinker.slider(SLIDER_1)); 34 | 35 | Blinker.delay(2000); 36 | } -------------------------------------------------------------------------------- /examples/Blinker_Slider/Slider_WiFi/Slider_WiFi.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_WIFI 3 | 4 | #include 5 | 6 | char ssid[] = "Your WiFi network SSID or name"; 7 | char pswd[] = "Your WiFi network WPA password or WEP key"; 8 | 9 | #define SLIDER_1 "SliderKey" 10 | 11 | void setup() 12 | { 13 | Serial.begin(115200); 14 | 15 | pinMode(LED_BUILTIN, OUTPUT); 16 | digitalWrite(LED_BUILTIN, LOW); 17 | 18 | Blinker.begin(ssid, pswd); 19 | Blinker.wInit(SLIDER_1, W_SLIDER); 20 | } 21 | 22 | void loop() 23 | { 24 | Blinker.run(); 25 | 26 | if (Blinker.available()) { 27 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 28 | 29 | Blinker.vibrate(); 30 | 31 | uint32_t BlinkerTime = millis(); 32 | Blinker.print(BlinkerTime); 33 | Blinker.print("millis", BlinkerTime); 34 | } 35 | 36 | BLINKER_LOG2("Slider read: ", Blinker.slider(SLIDER_1)); 37 | 38 | Blinker.delay(2000); 39 | } 40 | -------------------------------------------------------------------------------- /examples/Blinker_Time/Time_WiFi/Time_WiFi.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_WIFI 3 | 4 | #include 5 | 6 | char ssid[] = "Your WiFi network SSID or name"; 7 | char pswd[] = "Your WiFi network WPA password or WEP key"; 8 | 9 | #define BUTTON_1 "ButtonKey" 10 | 11 | void setup() 12 | { 13 | Serial.begin(115200); 14 | 15 | pinMode(LED_BUILTIN, OUTPUT); 16 | digitalWrite(LED_BUILTIN, LOW); 17 | 18 | Blinker.begin(ssid, pswd); 19 | Blinker.setTimezone(8.0); 20 | Blinker.wInit(BUTTON_1, W_BUTTON); 21 | } 22 | 23 | void loop() 24 | { 25 | Blinker.run(); 26 | 27 | if (Blinker.available()) { 28 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 29 | 30 | Blinker.vibrate(); 31 | 32 | uint32_t BlinkerTime = millis(); 33 | Blinker.print(BlinkerTime); 34 | Blinker.print("millis", BlinkerTime); 35 | } 36 | 37 | if (Blinker.button(BUTTON_1)) { 38 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 39 | 40 | BLINKER_LOG2("Now second: ", Blinker.second()); 41 | BLINKER_LOG2("Now minute: ", Blinker.minute()); 42 | BLINKER_LOG2("Now hour: ", Blinker.hour()); 43 | BLINKER_LOG2("Now wday: ", Blinker.wday()); 44 | BLINKER_LOG2("Now month: ", Blinker.month()); 45 | BLINKER_LOG2("Now mday: ", Blinker.mday()); 46 | BLINKER_LOG2("Now year: ", Blinker.year()); 47 | BLINKER_LOG2("Now yday: ", Blinker.yday()); 48 | BLINKER_LOG2("Now ntp time: ", Blinker.time()); 49 | } // simple tap 50 | } 51 | -------------------------------------------------------------------------------- /examples/Blinker_Timer/Timer_WiFi_countdown/Timer_WiFi_countdown.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_WIFI 3 | 4 | #include 5 | 6 | char ssid[] = "Your WiFi network SSID or name"; 7 | char pswd[] = "Your WiFi network WPA password or WEP key"; 8 | 9 | #define BUTTON_1 "ButtonKey" 10 | 11 | BlinkerTimer BlinkerCountDown; 12 | 13 | void blink() { 14 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 15 | } 16 | 17 | void setup() 18 | { 19 | Serial.begin(115200); 20 | 21 | pinMode(LED_BUILTIN, OUTPUT); 22 | digitalWrite(LED_BUILTIN, LOW); 23 | 24 | Blinker.begin(ssid, pswd); 25 | Blinker.wInit(BUTTON_1, W_BUTTON); 26 | BlinkerCountDown.countdown(5, blink); 27 | } 28 | 29 | void loop() 30 | { 31 | Blinker.run(); 32 | 33 | if (Blinker.available()) { 34 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 35 | 36 | Blinker.vibrate(); 37 | 38 | uint32_t BlinkerTime = millis(); 39 | Blinker.print(BlinkerTime); 40 | Blinker.print("millis", BlinkerTime); 41 | } 42 | 43 | if (Blinker.button(BUTTON_1)) { 44 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 45 | } // simple tap 46 | } 47 | -------------------------------------------------------------------------------- /examples/Blinker_Timer/Timer_WiFi_loop/Timer_WiFi_loop.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_WIFI 3 | 4 | #include 5 | 6 | char ssid[] = "Your WiFi network SSID or name"; 7 | char pswd[] = "Your WiFi network WPA password or WEP key"; 8 | 9 | #define BUTTON_1 "ButtonKey" 10 | 11 | BlinkerTimer BlinkerLoop; 12 | 13 | void blink() { 14 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 15 | } 16 | 17 | void setup() 18 | { 19 | Serial.begin(115200); 20 | 21 | pinMode(LED_BUILTIN, OUTPUT); 22 | digitalWrite(LED_BUILTIN, LOW); 23 | 24 | Blinker.begin(ssid, pswd); 25 | Blinker.wInit(BUTTON_1, W_BUTTON); 26 | BlinkerLoop.loop(1, blink); 27 | } 28 | 29 | void loop() 30 | { 31 | Blinker.run(); 32 | 33 | if (Blinker.available()) { 34 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 35 | 36 | Blinker.vibrate(); 37 | 38 | uint32_t BlinkerTime = millis(); 39 | Blinker.print(BlinkerTime); 40 | Blinker.print("millis", BlinkerTime); 41 | } 42 | 43 | if (Blinker.button(BUTTON_1)) { 44 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 45 | } // simple tap 46 | } 47 | -------------------------------------------------------------------------------- /examples/Blinker_Timer/Timer_WiFi_timing/Timer_WiFi_timing.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_WIFI 3 | 4 | #include 5 | 6 | char ssid[] = "Your WiFi network SSID or name"; 7 | char pswd[] = "Your WiFi network WPA password or WEP key"; 8 | 9 | #define BUTTON_1 "ButtonKey" 10 | 11 | BlinkerTimer BlinkerTiming; 12 | 13 | void blink_high() { 14 | digitalWrite(LED_BUILTIN, HIGH); 15 | } 16 | 17 | void blink_low() { 18 | digitalWrite(LED_BUILTIN, LOW); 19 | } 20 | 21 | void setup() 22 | { 23 | Serial.begin(115200); 24 | 25 | pinMode(LED_BUILTIN, OUTPUT); 26 | digitalWrite(LED_BUILTIN, LOW); 27 | 28 | Blinker.begin(ssid, pswd); 29 | Blinker.wInit(BUTTON_1, W_BUTTON); 30 | BlinkerTiming.timing(5, blink_high, 10, blink_low); 31 | } 32 | 33 | void loop() 34 | { 35 | Blinker.run(); 36 | 37 | if (Blinker.available()) { 38 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 39 | 40 | Blinker.vibrate(); 41 | 42 | uint32_t BlinkerTime = millis(); 43 | Blinker.print(BlinkerTime); 44 | Blinker.print("millis", BlinkerTime); 45 | } 46 | 47 | if (Blinker.button(BUTTON_1)) { 48 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 49 | } // simple tap 50 | } 51 | -------------------------------------------------------------------------------- /examples/Blinker_Toggle/Toggle_BLE/Toggle_BLE.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_BLE 3 | 4 | #include 5 | 6 | #define TOGGLE_1 "ToggleKey" 7 | 8 | void setup() 9 | { 10 | Serial.begin(115200); 11 | 12 | pinMode(LED_BUILTIN, OUTPUT); 13 | digitalWrite(LED_BUILTIN, LOW); 14 | 15 | Blinker.begin(); 16 | Blinker.wInit(TOGGLE_1, W_TOGGLE); 17 | } 18 | 19 | void loop() 20 | { 21 | Blinker.run(); 22 | 23 | if (Blinker.available()) { 24 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 25 | 26 | Blinker.vibrate(); 27 | 28 | uint32_t BlinkerTime = millis(); 29 | Blinker.print(BlinkerTime); 30 | Blinker.print("millis", BlinkerTime); 31 | } 32 | 33 | if (Blinker.toggle(TOGGLE_1)) { 34 | digitalWrite(LED_BUILTIN, HIGH); 35 | } 36 | else { 37 | digitalWrite(LED_BUILTIN, LOW); 38 | } 39 | } -------------------------------------------------------------------------------- /examples/Blinker_Toggle/Toggle_WiFi/Toggle_WiFi.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_WIFI 3 | 4 | #include 5 | 6 | char ssid[] = "Your WiFi network SSID or name"; 7 | char pswd[] = "Your WiFi network WPA password or WEP key"; 8 | 9 | #define TOGGLE_1 "ToggleKey" 10 | 11 | void setup() 12 | { 13 | Serial.begin(115200); 14 | 15 | pinMode(LED_BUILTIN, OUTPUT); 16 | digitalWrite(LED_BUILTIN, LOW); 17 | 18 | Blinker.begin(ssid, pswd); 19 | Blinker.wInit(TOGGLE_1, W_TOGGLE); 20 | } 21 | 22 | void loop() 23 | { 24 | Blinker.run(); 25 | 26 | if (Blinker.available()) { 27 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 28 | 29 | Blinker.vibrate(); 30 | 31 | uint32_t BlinkerTime = millis(); 32 | Blinker.print(BlinkerTime); 33 | Blinker.print("millis", BlinkerTime); 34 | } 35 | 36 | if (Blinker.toggle(TOGGLE_1)) { 37 | digitalWrite(LED_BUILTIN, HIGH); 38 | } 39 | else { 40 | digitalWrite(LED_BUILTIN, LOW); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /examples/Blinker_Weather/Weather_MQTT/Weather_MQTT.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | #define BLINKER_MQTT 3 | 4 | #include 5 | 6 | char auth[] = "Your MQTT Secret Key"; 7 | char ssid[] = "Your WiFi network SSID or name"; 8 | char pswd[] = "Your WiFi network WPA password or WEP key"; 9 | 10 | #define BUTTON_1 "ButtonKey" 11 | 12 | void setup() { 13 | Serial.begin(115200); 14 | 15 | pinMode(LED_BUILTIN, OUTPUT); 16 | digitalWrite(LED_BUILTIN, LOW); 17 | 18 | Blinker.begin(auth, ssid, pswd); 19 | Blinker.wInit(BUTTON_1, W_BUTTON); 20 | } 21 | 22 | void loop() 23 | { 24 | Blinker.run(); 25 | 26 | if (Blinker.available()) { 27 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 28 | 29 | uint32_t BlinkerTime = millis(); 30 | 31 | Blinker.beginFormat(); 32 | Blinker.vibrate(); 33 | Blinker.print("millis", BlinkerTime); 34 | Blinker.endFormat(); 35 | } 36 | 37 | if (Blinker.button(BUTTON_1)) { 38 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 39 | String get_weather = Blinker.weather(); 40 | 41 | BLINKER_LOG2("weather: ", get_weather); 42 | 43 | Blinker.delay(6000); 44 | } 45 | } -------------------------------------------------------------------------------- /examples/Blinker_Weather/Weather_WiFi/Weather_WiFi.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_PRINT Serial 2 | 3 | #include 4 | 5 | char ssid[] = "Your WiFi network SSID or name"; 6 | char pswd[] = "Your WiFi network WPA password or WEP key"; 7 | 8 | #define BUTTON_1 "ButtonKey" 9 | 10 | void setup() { 11 | Serial.begin(115200); 12 | 13 | pinMode(LED_BUILTIN, OUTPUT); 14 | digitalWrite(LED_BUILTIN, LOW); 15 | 16 | Blinker.begin(ssid, pswd); 17 | Blinker.wInit(BUTTON_1, W_BUTTON); 18 | } 19 | 20 | void loop() 21 | { 22 | Blinker.run(); 23 | 24 | if (Blinker.available()) { 25 | BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); 26 | 27 | uint32_t BlinkerTime = millis(); 28 | 29 | Blinker.beginFormat(); 30 | Blinker.vibrate(); 31 | Blinker.print("millis", BlinkerTime); 32 | Blinker.endFormat(); 33 | } 34 | 35 | if (Blinker.button(BUTTON_1)) { 36 | digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 37 | String get_weather = Blinker.weather(); 38 | 39 | BLINKER_LOG2("weather: ", get_weather); 40 | 41 | Blinker.delay(6000); 42 | } 43 | } -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Blinker", 3 | "description": "Blinker library for embedded hardware. Works with Arduino, ESP8266, ESP32.", 4 | "keywords": "wifi, websocket, Bluetooth, mqtt", 5 | "authors": [ 6 | { 7 | "name": "i3water", 8 | "url": "https://github.com/i3water", 9 | "maintainer": true 10 | } 11 | ], 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/blinker-iot/blinker-library.git" 15 | }, 16 | "version": "0.1.5", 17 | "homepage": "https://blinker.app/", 18 | "export": { 19 | "exclude": [ 20 | "tests" 21 | ] 22 | }, 23 | "frameworks": "arduino", 24 | "platforms": "*", 25 | "examples": [ 26 | "examples/*/*/*.ino" 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Blinker 2 | version=0.1.5 3 | author=i3water 4 | maintainer=i3wawter 5 | sentence=Build a easy way for your project to communicate with smartphone, works with smartphone app Blinker. 6 | paragraph=Blinker library for embedded hardware. Support Arduino, ESP8266, ESP32, WiFi, BLE, MQTT. 7 | category=Communication 8 | url=https://blinker.app/ 9 | architectures=* 10 | -------------------------------------------------------------------------------- /src/Adapters/test.h: -------------------------------------------------------------------------------- 1 | "-----BEGIN CERTIFICATE-----" 2 | "MIIEgDCCA2igAwIBAgIQDKTfhr9lmWbWUT0hjX36oDANBgkqhkiG9w0BAQsFADBy" 3 | "MQswCQYDVQQGEwJDTjElMCMGA1UEChMcVHJ1c3RBc2lhIFRlY2hub2xvZ2llcywg" 4 | "SW5jLjEdMBsGA1UECxMURG9tYWluIFZhbGlkYXRlZCBTU0wxHTAbBgNVBAMTFFRy" 5 | "dXN0QXNpYSBUTFMgUlNBIENBMB4XDTE4MDEwNDAwMDAwMFoXDTE5MDEwNDEyMDAw" 6 | "MFowGDEWMBQGA1UEAxMNaW90ZGV2LmNsei5tZTCCASIwDQYJKoZIhvcNAQEBBQAD" 7 | "ggEPADCCAQoCggEBALbOFn7cJ2I/FKMJqIaEr38n4kCuJCCeNf1bWdWvOizmU2A8" 8 | "QeTAr5e6Q3GKeJRdPnc8xXhqkTm4LOhgdZB8KzuVZARtu23D4vj4sVzxgC/zwJlZ" 9 | "MRMxN+cqI37kXE8gGKW46l2H9vcukylJX+cx/tjWDfS2YuyXdFuS/RjhCxLgXzbS" 10 | "cve1W0oBZnBPRSMV0kgxTWj7hEGZNWKIzK95BSCiMN59b+XEu3NWGRb/VzSAiJEy" 11 | "Hy9DcDPBC9TEg+p5itHtdMhy2gq1OwsPgl9HUT0xmDATSNEV2RB3vwviNfu9/Eif" 12 | "ObhsV078zf30TqdiESqISEB68gJ0Otru67ePoTkCAwEAAaOCAWowggFmMB8GA1Ud" 13 | "IwQYMBaAFH/TmfOgRw4xAFZWIo63zJ7dygGKMB0GA1UdDgQWBBR/KLqnke61779P" 14 | "xc9htonQwLOxPDAYBgNVHREEETAPgg1pb3RkZXYuY2x6Lm1lMA4GA1UdDwEB/wQE" 15 | "AwIFoDAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwTAYDVR0gBEUwQzA3" 16 | "BglghkgBhv1sAQIwKjAoBggrBgEFBQcCARYcaHR0cHM6Ly93d3cuZGlnaWNlcnQu" 17 | "Y29tL0NQUzAIBgZngQwBAgEwgYEGCCsGAQUFBwEBBHUwczAlBggrBgEFBQcwAYYZ" 18 | "aHR0cDovL29jc3AyLmRpZ2ljZXJ0LmNvbTBKBggrBgEFBQcwAoY+aHR0cDovL2Nh" 19 | "Y2VydHMuZGlnaXRhbGNlcnR2YWxpZGF0aW9uLmNvbS9UcnVzdEFzaWFUTFNSU0FD" 20 | "QS5jcnQwCQYDVR0TBAIwADANBgkqhkiG9w0BAQsFAAOCAQEAhtM4eyrWB14ajJpQ" 21 | "ibZ5FbzVuvv2Le0FOSoss7UFCDJUYiz2LiV8yOhL4KTY+oVVkqHaYtcFS1CYZNzj" 22 | "6xWcqYZJ+pgsto3WBEgNEEe0uLSiTW6M10hm0LFW9Det3k8fqwSlljqMha3gkpZ6" 23 | "8WB0f2clXOuC+f1SxAOymnGUsSqbU0eFSgevcOIBKR7Hr3YXBXH3jjED76Q52OMS" 24 | "ucfOM9/HB3jN8o/ioQbkI7xyd/DUQtzK6hSArEoYRl3p5H2P4fr9XqmpoZV3i3gQ" 25 | "oOdVycVtpLunyUoVAB2DcOElfDxxXCvDH3XsgoIU216VY03MCaUZf7kZ2GiNL+UX" 26 | "9UBd0Q==" 27 | "-----END CERTIFICATE-----" -------------------------------------------------------------------------------- /src/Blinker.h: -------------------------------------------------------------------------------- 1 | #ifndef Blinker_H 2 | #define Blinker_H 3 | 4 | #if defined(BLINKER_BLE) 5 | 6 | #if defined(ESP32) 7 | #include 8 | #else 9 | #include 10 | #endif 11 | 12 | #elif defined(BLINKER_WIFI) 13 | 14 | #if defined(ESP8266) 15 | #include 16 | #elif defined(ESP32) 17 | #include 18 | #else 19 | #error This code is intended to run on the ESP8266/ESP32 platform! Please check your Tools->Board setting. 20 | #endif 21 | 22 | #elif defined(BLINKER_MQTT) 23 | 24 | #if defined(ESP8266) 25 | #include 26 | #elif defined(ESP32) 27 | #include 28 | #else 29 | #error This code is intended to run on the ESP8266/ESP32 platform! Please check your Tools->Board setting. 30 | #endif 31 | 32 | #elif defined(BLINKER_PRO) 33 | 34 | #ifndef BLINKER_ESP_SMARTCONFIG 35 | #ifndef BLINKER_APCONFIG 36 | #define BLINKER_ESP_SMARTCONFIG 37 | #endif 38 | #endif 39 | 40 | #if defined(ESP8266) 41 | #include 42 | #elif defined(ESP32) 43 | #include 44 | #else 45 | #error This code is intended to run on the ESP8266/ESP32 platform! Please check your Tools->Board setting. 46 | #endif 47 | 48 | #else 49 | #error Please setting connect mode ahead! Here provided BLINKER_BLE/BLINKER_WIFI/BLINKER_MQTT mode! 50 | #endif 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/BlinkerSimpleESP32_PRO.h: -------------------------------------------------------------------------------- 1 | #ifndef BlinkerSimplerESP32_PRO_H 2 | #define BlinkerSimplerESP32_PRO_H 3 | 4 | #include "Adapters/BlinkerPRO.h" 5 | 6 | class BlinkerSimpleESP32_PRO 7 | : public BlinkerProtocol 8 | { 9 | typedef BlinkerProtocol Base; 10 | 11 | public : 12 | BlinkerSimpleESP32_PRO(BlinkerPRO &transp) 13 | : Base(transp) 14 | {} 15 | 16 | void begin(const char* _type = BLINKER_AIR_DETECTOR) { 17 | Base::begin(_type); 18 | // while(!Base::beginPro()) { 19 | // ::delay(1); 20 | // } 21 | // this->conn.begin(_type); 22 | BLINKER_LOG1("ESP8266_PRO Initialled..."); 23 | } 24 | 25 | // #if defined(BLINKER_ESP_SMARTCONFIG) 26 | // void begin(const char* _auth) { 27 | // Base::begin(_auth); 28 | // smartconfig(); 29 | // this->conn.begin(_auth); 30 | // BLINKER_LOG1("ESP32_MQTT Initialled..."); 31 | // } 32 | // #endif 33 | 34 | // void begin( const char* _auth, 35 | // const char* _ssid, 36 | // const char* _pswd) 37 | // { 38 | // Base::begin(_auth); 39 | // connectWiFi(_ssid, _pswd); 40 | // this->conn.begin(_auth); 41 | // BLINKER_LOG1("ESP32_MQTT Initialled..."); 42 | // } 43 | 44 | // private : 45 | // #if defined(BLINKER_ESP_SMARTCONFIG) 46 | // void smartconfig() { 47 | // WiFi.mode(WIFI_AP_STA); 48 | // WiFi.beginSmartConfig(); 49 | 50 | // BLINKER_LOG1("Waiting for SmartConfig."); 51 | // while (!WiFi.smartConfigDone()) { 52 | // ::delay(500); 53 | // } 54 | 55 | // BLINKER_LOG1("SmartConfig received."); 56 | 57 | // BLINKER_LOG1("Waiting for WiFi"); 58 | // while (WiFi.status() != WL_CONNECTED) { 59 | // ::delay(500); 60 | // } 61 | 62 | // BLINKER_LOG1("WiFi Connected."); 63 | 64 | // BLINKER_LOG1("IP Address: "); 65 | // BLINKER_LOG1(WiFi.localIP()); 66 | 67 | // // mDNSInit(); 68 | // } 69 | // #endif 70 | 71 | // void connectWiFi(const char* _ssid, const char* _pswd) 72 | // { 73 | // uint32_t connectTime = millis(); 74 | 75 | // BLINKER_LOG2(("Connecting to "), _ssid); 76 | // WiFi.mode(WIFI_STA); 77 | // if (_pswd && strlen(_pswd)) { 78 | // WiFi.begin(_ssid, _pswd); 79 | // } 80 | // else { 81 | // WiFi.begin(_ssid); 82 | // } 83 | 84 | // while (WiFi.status() != WL_CONNECTED) { 85 | // ::delay(50); 86 | 87 | // if (millis() - connectTime > BLINKER_CONNECT_TIMEOUT_MS && WiFi.status() != WL_CONNECTED) { 88 | // connectTime = millis(); 89 | // BLINKER_LOG1(("WiFi connect timeout, please check ssid and pswd!")); 90 | // BLINKER_LOG1(("Retring WiFi connect again!")); 91 | // } 92 | // } 93 | // BLINKER_LOG1(("Connected")); 94 | 95 | // IPAddress myip = WiFi.localIP(); 96 | // BLINKER_LOG2(("Your IP is: "), myip); 97 | 98 | // // mDNSInit(); 99 | // } 100 | }; 101 | 102 | static BlinkerPRO _blinkerTransport; 103 | BlinkerSimpleESP32_PRO Blinker(_blinkerTransport); 104 | 105 | #endif -------------------------------------------------------------------------------- /src/BlinkerSimpleESP8266_PRO.h: -------------------------------------------------------------------------------- 1 | #ifndef BlinkerSimplerESP8266_PRO_H 2 | #define BlinkerSimplerESP8266_PRO_H 3 | 4 | #include "Adapters/BlinkerPRO.h" 5 | 6 | class BlinkerSimpleESP8266_PRO 7 | : public BlinkerProtocol 8 | { 9 | typedef BlinkerProtocol Base; 10 | 11 | public : 12 | BlinkerSimpleESP8266_PRO(BlinkerPRO &transp) 13 | : Base(transp) 14 | {} 15 | 16 | void begin(const char* _type = BLINKER_AIR_DETECTOR) { 17 | Base::begin(_type); 18 | // while(!Base::beginPro()) { 19 | // ::delay(1); 20 | // } 21 | // this->conn.begin(_type); 22 | BLINKER_LOG1("ESP8266_PRO Initialled..."); 23 | } 24 | 25 | // #if defined(BLINKER_ESP_SMARTCONFIG) 26 | // void begin(const char* _auth) { 27 | // Base::begin(_auth); 28 | // smartconfig(); 29 | // this->conn.begin(_auth); 30 | // BLINKER_LOG1("ESP8266_MQTT Initialled..."); 31 | // } 32 | // #endif 33 | 34 | // void begin( const char* _auth, 35 | // const char* _ssid, 36 | // const char* _pswd) 37 | // { 38 | // Base::begin(_auth); 39 | // connectWiFi(_ssid, _pswd); 40 | // this->conn.begin(_auth); 41 | // BLINKER_LOG1("ESP8266_MQTT Initialled..."); 42 | // } 43 | 44 | // private : 45 | // #if defined(BLINKER_ESP_SMARTCONFIG) 46 | // void smartconfig() { 47 | // WiFi.mode(WIFI_STA); 48 | // WiFi.beginSmartConfig(); 49 | 50 | // BLINKER_LOG1("Waiting for SmartConfig."); 51 | // while (!WiFi.smartConfigDone()) { 52 | // ::delay(500); 53 | // } 54 | 55 | // BLINKER_LOG1("SmartConfig received."); 56 | 57 | // BLINKER_LOG1("Waiting for WiFi"); 58 | // while (WiFi.status() != WL_CONNECTED) { 59 | // ::delay(500); 60 | // } 61 | 62 | // BLINKER_LOG1("WiFi Connected."); 63 | 64 | // BLINKER_LOG1("IP Address: "); 65 | // BLINKER_LOG1(WiFi.localIP()); 66 | 67 | // // mDNSInit(); 68 | // } 69 | // #endif 70 | // // void mDNSInit() 71 | // // { 72 | // // if (!MDNS.begin(macDeviceName().c_str(), WiFi.localIP())) { 73 | // // while(1) { 74 | // // ::delay(100); 75 | // // } 76 | // // } 77 | 78 | // // BLINKER_LOG1(("mDNS responder started")); 79 | 80 | // // MDNS.addService("DiyArduino", "tcp", WS_SERVERPORT); 81 | 82 | // // this->conn.begin(macDeviceName()); 83 | // // } 84 | 85 | // void connectWiFi(const char* _ssid, const char* _pswd) 86 | // { 87 | // uint32_t connectTime = millis(); 88 | 89 | // BLINKER_LOG2(("Connecting to "), _ssid); 90 | // WiFi.mode(WIFI_STA); 91 | // if (_pswd && strlen(_pswd)) { 92 | // WiFi.begin(_ssid, _pswd); 93 | // } 94 | // else { 95 | // WiFi.begin(_ssid); 96 | // } 97 | 98 | // while (WiFi.status() != WL_CONNECTED) { 99 | // ::delay(50); 100 | 101 | // if (millis() - connectTime > BLINKER_CONNECT_TIMEOUT_MS && WiFi.status() != WL_CONNECTED) { 102 | // connectTime = millis(); 103 | // BLINKER_LOG1(("WiFi connect timeout, please check ssid and pswd!")); 104 | // BLINKER_LOG1(("Retring WiFi connect again!")); 105 | // } 106 | // } 107 | // BLINKER_LOG1(("Connected")); 108 | 109 | // IPAddress myip = WiFi.localIP(); 110 | // BLINKER_LOG2(("Your IP is: "), myip); 111 | 112 | // // mDNSInit(); 113 | // } 114 | }; 115 | 116 | static BlinkerPRO _blinkerTransport; 117 | BlinkerSimpleESP8266_PRO Blinker(_blinkerTransport); 118 | 119 | #endif -------------------------------------------------------------------------------- /src/BlinkerSimpleSerialBLE.h: -------------------------------------------------------------------------------- 1 | #ifndef BlinkerSimpleSerialBLE_H 2 | #define BlinkerSimpleSerialBLE_H 3 | 4 | #include 5 | 6 | static BlinkerTransportStream _blinkerTransport; 7 | BlinkerSerial Blinker(_blinkerTransport); 8 | 9 | #endif -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson.h: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #ifdef __cplusplus 8 | 9 | #include "ArduinoJson.hpp" 10 | 11 | using namespace ArduinoJson; 12 | 13 | #else 14 | 15 | #error ArduinoJson requires a C++ compiler, please change file extension to .cc or .cpp 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "ArduinoJson/version.hpp" 8 | 9 | #include "ArduinoJson/DynamicJsonBuffer.hpp" 10 | #include "ArduinoJson/JsonArray.hpp" 11 | #include "ArduinoJson/JsonObject.hpp" 12 | #include "ArduinoJson/StaticJsonBuffer.hpp" 13 | 14 | #include "ArduinoJson/Deserialization/JsonParserImpl.hpp" 15 | #include "ArduinoJson/JsonArrayImpl.hpp" 16 | #include "ArduinoJson/JsonBufferImpl.hpp" 17 | #include "ArduinoJson/JsonObjectImpl.hpp" 18 | #include "ArduinoJson/JsonVariantImpl.hpp" 19 | #include "ArduinoJson/Serialization/JsonSerializerImpl.hpp" 20 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Configuration.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | // Small or big machine? 8 | #ifndef ARDUINOJSON_EMBEDDED_MODE 9 | #if defined(ARDUINO) || defined(__IAR_SYSTEMS_ICC__) || defined(__XC) || \ 10 | defined(__ARMCC_VERSION) 11 | #define ARDUINOJSON_EMBEDDED_MODE 1 12 | #else 13 | #define ARDUINOJSON_EMBEDDED_MODE 0 14 | #endif 15 | #endif 16 | 17 | #if ARDUINOJSON_EMBEDDED_MODE 18 | 19 | // Store floats by default to reduce the memory usage (issue #134) 20 | #ifndef ARDUINOJSON_USE_DOUBLE 21 | #define ARDUINOJSON_USE_DOUBLE 0 22 | #endif 23 | 24 | // Store longs by default, because they usually match the size of a float. 25 | #ifndef ARDUINOJSON_USE_LONG_LONG 26 | #define ARDUINOJSON_USE_LONG_LONG 0 27 | #endif 28 | #ifndef ARDUINOJSON_USE_INT64 29 | #define ARDUINOJSON_USE_INT64 0 30 | #endif 31 | 32 | // Embedded systems usually don't have std::string 33 | #ifndef ARDUINOJSON_ENABLE_STD_STRING 34 | #define ARDUINOJSON_ENABLE_STD_STRING 0 35 | #endif 36 | 37 | // Embedded systems usually don't have std::stream 38 | #ifndef ARDUINOJSON_ENABLE_STD_STREAM 39 | #define ARDUINOJSON_ENABLE_STD_STREAM 0 40 | #endif 41 | 42 | // Limit nesting as the stack is likely to be small 43 | #ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT 44 | #define ARDUINOJSON_DEFAULT_NESTING_LIMIT 10 45 | #endif 46 | 47 | #else // ARDUINOJSON_EMBEDDED_MODE 48 | 49 | // On a computer we have plenty of memory so we can use doubles 50 | #ifndef ARDUINOJSON_USE_DOUBLE 51 | #define ARDUINOJSON_USE_DOUBLE 1 52 | #endif 53 | 54 | // Use long long when available 55 | #ifndef ARDUINOJSON_USE_LONG_LONG 56 | #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800) 57 | #define ARDUINOJSON_USE_LONG_LONG 1 58 | #else 59 | #define ARDUINOJSON_USE_LONG_LONG 0 60 | #endif 61 | #endif 62 | 63 | // Use _int64 on old versions of Visual Studio 64 | #ifndef ARDUINOJSON_USE_INT64 65 | #if defined(_MSC_VER) && _MSC_VER <= 1700 66 | #define ARDUINOJSON_USE_INT64 1 67 | #else 68 | #define ARDUINOJSON_USE_INT64 0 69 | #endif 70 | #endif 71 | 72 | // On a computer, we can use std::string 73 | #ifndef ARDUINOJSON_ENABLE_STD_STRING 74 | #define ARDUINOJSON_ENABLE_STD_STRING 1 75 | #endif 76 | 77 | // On a computer, we can assume std::stream 78 | #ifndef ARDUINOJSON_ENABLE_STD_STREAM 79 | #define ARDUINOJSON_ENABLE_STD_STREAM 1 80 | #endif 81 | 82 | // On a computer, the stack is large so we can increase nesting limit 83 | #ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT 84 | #define ARDUINOJSON_DEFAULT_NESTING_LIMIT 50 85 | #endif 86 | 87 | #endif // ARDUINOJSON_EMBEDDED_MODE 88 | 89 | #ifdef ARDUINO 90 | 91 | // Enable support for Arduino String 92 | #ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING 93 | #define ARDUINOJSON_ENABLE_ARDUINO_STRING 1 94 | #endif 95 | 96 | // Enable support for Arduino Stream 97 | #ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM 98 | #define ARDUINOJSON_ENABLE_ARDUINO_STREAM 1 99 | #endif 100 | 101 | #else // ARDUINO 102 | 103 | // Disable support for Arduino String 104 | #ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING 105 | #define ARDUINOJSON_ENABLE_ARDUINO_STRING 0 106 | #endif 107 | 108 | // Disable support for Arduino Stream 109 | #ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM 110 | #define ARDUINOJSON_ENABLE_ARDUINO_STREAM 0 111 | #endif 112 | 113 | #endif // ARDUINO 114 | 115 | #ifndef ARDUINOJSON_ENABLE_PROGMEM 116 | #ifdef PROGMEM 117 | #define ARDUINOJSON_ENABLE_PROGMEM 1 118 | #else 119 | #define ARDUINOJSON_ENABLE_PROGMEM 0 120 | #endif 121 | #endif 122 | 123 | #ifndef ARDUINOJSON_ENABLE_ALIGNMENT 124 | #ifdef ARDUINO_ARCH_AVR 125 | // alignment isn't needed for 8-bit AVR 126 | #define ARDUINOJSON_ENABLE_ALIGNMENT 0 127 | #else 128 | // but most processors need pointers to be align on word size 129 | #define ARDUINOJSON_ENABLE_ALIGNMENT 1 130 | #endif 131 | #endif 132 | 133 | // Enable deprecated functions by default 134 | #ifndef ARDUINOJSON_ENABLE_DEPRECATED 135 | #define ARDUINOJSON_ENABLE_DEPRECATED 1 136 | #endif 137 | 138 | // Control the exponentiation threshold for big numbers 139 | // CAUTION: cannot be more that 1e9 !!!! 140 | #ifndef ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD 141 | #define ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD 1e7 142 | #endif 143 | 144 | // Control the exponentiation threshold for small numbers 145 | #ifndef ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD 146 | #define ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD 1e-5 147 | #endif 148 | 149 | #if ARDUINOJSON_USE_LONG_LONG && ARDUINOJSON_USE_INT64 150 | #error ARDUINOJSON_USE_LONG_LONG and ARDUINOJSON_USE_INT64 cannot be set together 151 | #endif 152 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Data/Encoding.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | class Encoding { 11 | public: 12 | // Optimized for code size on a 8-bit AVR 13 | static char escapeChar(char c) { 14 | const char *p = escapeTable(false); 15 | while (p[0] && p[1] != c) { 16 | p += 2; 17 | } 18 | return p[0]; 19 | } 20 | 21 | // Optimized for code size on a 8-bit AVR 22 | static char unescapeChar(char c) { 23 | const char *p = escapeTable(true); 24 | for (;;) { 25 | if (p[0] == '\0') return c; 26 | if (p[0] == c) return p[1]; 27 | p += 2; 28 | } 29 | } 30 | 31 | private: 32 | static const char *escapeTable(bool excludeIdenticals) { 33 | return &"\"\"\\\\b\bf\fn\nr\rt\t"[excludeIdenticals ? 4 : 0]; 34 | } 35 | }; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Data/JsonBufferAllocated.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../JsonBuffer.hpp" 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | 12 | class JsonBufferAllocated { 13 | public: 14 | void *operator new(size_t n, JsonBuffer *jsonBuffer) throw() { 15 | if (!jsonBuffer) return NULL; 16 | return jsonBuffer->alloc(n); 17 | } 18 | 19 | void operator delete(void *, JsonBuffer *)throw(); 20 | }; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Data/JsonFloat.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../Configuration.hpp" 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | 12 | #if ARDUINOJSON_USE_DOUBLE 13 | typedef double JsonFloat; 14 | #else 15 | typedef float JsonFloat; 16 | #endif 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Data/JsonInteger.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../Configuration.hpp" 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | 12 | #if ARDUINOJSON_USE_LONG_LONG 13 | typedef long long JsonInteger; 14 | typedef unsigned long long JsonUInt; 15 | #elif ARDUINOJSON_USE_INT64 16 | typedef __int64 JsonInteger; 17 | typedef unsigned _int64 JsonUInt; 18 | #else 19 | typedef long JsonInteger; 20 | typedef unsigned long JsonUInt; 21 | #endif 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Data/JsonVariantAs.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // A metafunction that returns the type of the value returned by 11 | // JsonVariant::as() 12 | template 13 | struct JsonVariantAs { 14 | typedef T type; 15 | }; 16 | 17 | template <> 18 | struct JsonVariantAs { 19 | typedef const char* type; 20 | }; 21 | 22 | template <> 23 | struct JsonVariantAs { 24 | typedef JsonArray& type; 25 | }; 26 | 27 | template <> 28 | struct JsonVariantAs { 29 | typedef const JsonArray& type; 30 | }; 31 | 32 | template <> 33 | struct JsonVariantAs { 34 | typedef JsonObject& type; 35 | }; 36 | 37 | template <> 38 | struct JsonVariantAs { 39 | typedef const JsonObject& type; 40 | }; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Data/JsonVariantContent.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "JsonFloat.hpp" 8 | #include "JsonInteger.hpp" 9 | 10 | namespace ArduinoJson { 11 | 12 | // Forward declarations 13 | class JsonArray; 14 | class JsonObject; 15 | 16 | namespace Internals { 17 | // A union that defines the actual content of a JsonVariant. 18 | // The enum JsonVariantType determines which member is in use. 19 | union JsonVariantContent { 20 | JsonFloat asFloat; // used for double and float 21 | JsonUInt asInteger; // used for bool, char, short, int and longs 22 | const char* asString; // asString can be null 23 | JsonArray* asArray; // asArray cannot be null 24 | JsonObject* asObject; // asObject cannot be null 25 | }; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Data/JsonVariantDefault.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | template 11 | struct JsonVariantDefault { 12 | static T get() { 13 | return T(); 14 | } 15 | }; 16 | 17 | template 18 | struct JsonVariantDefault : JsonVariantDefault {}; 19 | 20 | template 21 | struct JsonVariantDefault : JsonVariantDefault {}; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Data/JsonVariantType.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | class JsonArray; 9 | class JsonObject; 10 | 11 | namespace Internals { 12 | 13 | // Enumerated type to know the current type of a JsonVariant. 14 | // The value determines which member of JsonVariantContent is used. 15 | enum JsonVariantType { 16 | JSON_UNDEFINED, // JsonVariant has not been initialized 17 | JSON_UNPARSED, // JsonVariant contains an unparsed string 18 | JSON_STRING, // JsonVariant stores a const char* 19 | JSON_BOOLEAN, // JsonVariant stores a bool 20 | JSON_POSITIVE_INTEGER, // JsonVariant stores an JsonUInt 21 | JSON_NEGATIVE_INTEGER, // JsonVariant stores an JsonUInt that must be negated 22 | JSON_ARRAY, // JsonVariant stores a pointer to a JsonArray 23 | JSON_OBJECT, // JsonVariant stores a pointer to a JsonObject 24 | JSON_FLOAT // JsonVariant stores a JsonFloat 25 | }; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Data/List.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../JsonBuffer.hpp" 8 | #include "ListConstIterator.hpp" 9 | #include "ListIterator.hpp" 10 | 11 | namespace ArduinoJson { 12 | namespace Internals { 13 | 14 | // A singly linked list of T. 15 | // The linked list is composed of ListNode. 16 | // It is derived by JsonArray and JsonObject 17 | template 18 | class List { 19 | public: 20 | typedef T value_type; 21 | typedef ListNode node_type; 22 | typedef ListIterator iterator; 23 | typedef ListConstIterator const_iterator; 24 | 25 | // Creates an empty List attached to a JsonBuffer. 26 | // The JsonBuffer allows to allocate new nodes. 27 | // When buffer is NULL, the List is not able to grow and success() returns 28 | // false. This is used to identify bad memory allocations and parsing 29 | // failures. 30 | explicit List(JsonBuffer *buffer) : _buffer(buffer), _firstNode(NULL) {} 31 | 32 | // Returns true if the object is valid 33 | // Would return false in the following situation: 34 | // - the memory allocation failed (StaticJsonBuffer was too small) 35 | // - the JSON parsing failed 36 | bool success() const { 37 | return _buffer != NULL; 38 | } 39 | 40 | // Returns the numbers of elements in the list. 41 | // For a JsonObject, it would return the number of key-value pairs 42 | size_t size() const { 43 | size_t nodeCount = 0; 44 | for (node_type *node = _firstNode; node; node = node->next) nodeCount++; 45 | return nodeCount; 46 | } 47 | 48 | iterator add() { 49 | node_type *newNode = new (_buffer) node_type(); 50 | 51 | if (_firstNode) { 52 | node_type *lastNode = _firstNode; 53 | while (lastNode->next) lastNode = lastNode->next; 54 | lastNode->next = newNode; 55 | } else { 56 | _firstNode = newNode; 57 | } 58 | 59 | return iterator(newNode); 60 | } 61 | 62 | iterator begin() { 63 | return iterator(_firstNode); 64 | } 65 | iterator end() { 66 | return iterator(NULL); 67 | } 68 | 69 | const_iterator begin() const { 70 | return const_iterator(_firstNode); 71 | } 72 | const_iterator end() const { 73 | return const_iterator(NULL); 74 | } 75 | 76 | void remove(iterator it) { 77 | node_type *nodeToRemove = it._node; 78 | if (!nodeToRemove) return; 79 | if (nodeToRemove == _firstNode) { 80 | _firstNode = nodeToRemove->next; 81 | } else { 82 | for (node_type *node = _firstNode; node; node = node->next) 83 | if (node->next == nodeToRemove) node->next = nodeToRemove->next; 84 | } 85 | } 86 | 87 | protected: 88 | JsonBuffer *_buffer; 89 | 90 | private: 91 | node_type *_firstNode; 92 | }; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Data/ListConstIterator.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "ListNode.hpp" 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | 12 | // A read-only forward itertor for List 13 | template 14 | class ListConstIterator { 15 | public: 16 | explicit ListConstIterator(const ListNode *node = NULL) : _node(node) {} 17 | 18 | const T &operator*() const { 19 | return _node->content; 20 | } 21 | const T *operator->() { 22 | return &_node->content; 23 | } 24 | 25 | bool operator==(const ListConstIterator &other) const { 26 | return _node == other._node; 27 | } 28 | 29 | bool operator!=(const ListConstIterator &other) const { 30 | return _node != other._node; 31 | } 32 | 33 | ListConstIterator &operator++() { 34 | if (_node) _node = _node->next; 35 | return *this; 36 | } 37 | 38 | ListConstIterator &operator+=(size_t distance) { 39 | while (_node && distance) { 40 | _node = _node->next; 41 | --distance; 42 | } 43 | return *this; 44 | } 45 | 46 | private: 47 | const ListNode *_node; 48 | }; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Data/ListIterator.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "ListConstIterator.hpp" 8 | #include "ListNode.hpp" 9 | 10 | namespace ArduinoJson { 11 | namespace Internals { 12 | 13 | template 14 | class List; 15 | 16 | // A read-write forward iterator for List 17 | template 18 | class ListIterator { 19 | friend class List; 20 | 21 | public: 22 | explicit ListIterator(ListNode *node = NULL) : _node(node) {} 23 | 24 | T &operator*() const { 25 | return _node->content; 26 | } 27 | T *operator->() { 28 | return &_node->content; 29 | } 30 | 31 | bool operator==(const ListIterator &other) const { 32 | return _node == other._node; 33 | } 34 | 35 | bool operator!=(const ListIterator &other) const { 36 | return _node != other._node; 37 | } 38 | 39 | ListIterator &operator++() { 40 | if (_node) _node = _node->next; 41 | return *this; 42 | } 43 | 44 | ListIterator &operator+=(size_t distance) { 45 | while (_node && distance) { 46 | _node = _node->next; 47 | --distance; 48 | } 49 | return *this; 50 | } 51 | 52 | operator ListConstIterator() const { 53 | return ListConstIterator(_node); 54 | } 55 | 56 | private: 57 | ListNode *_node; 58 | }; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Data/ListNode.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include // for NULL 8 | 9 | #include "JsonBufferAllocated.hpp" 10 | 11 | namespace ArduinoJson { 12 | namespace Internals { 13 | 14 | // A node for a singly-linked list. 15 | // Used by List and its iterators. 16 | template 17 | struct ListNode : public Internals::JsonBufferAllocated { 18 | ListNode() throw() : next(NULL) {} 19 | 20 | ListNode *next; 21 | T content; 22 | }; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Data/NonCopyable.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // A type that cannot be copied 11 | class NonCopyable { 12 | protected: 13 | NonCopyable() {} 14 | 15 | private: 16 | // copy constructor is private 17 | NonCopyable(const NonCopyable&); 18 | 19 | // copy operator is private 20 | NonCopyable& operator=(const NonCopyable&); 21 | }; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Data/ReferenceType.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // A type that is meant to be used by reference only (JsonArray and JsonObject) 11 | class ReferenceType { 12 | public: 13 | bool operator==(const ReferenceType& other) const { 14 | // two JsonArray are equal if they are the same instance 15 | // (we don't compare the content) 16 | return this == &other; 17 | } 18 | 19 | bool operator!=(const ReferenceType& other) const { 20 | return this != &other; 21 | } 22 | }; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Data/ValueSaver.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../JsonBuffer.hpp" 8 | #include "../JsonVariant.hpp" 9 | #include "../StringTraits/StringTraits.hpp" 10 | #include "../TypeTraits/EnableIf.hpp" 11 | 12 | namespace ArduinoJson { 13 | namespace Internals { 14 | 15 | template 16 | struct ValueSaver { 17 | template 18 | static bool save(JsonBuffer*, Destination& destination, Source source) { 19 | destination = source; 20 | return true; 21 | } 22 | }; 23 | 24 | template 25 | struct ValueSaver< 26 | Source, typename EnableIf::should_duplicate>::type> { 27 | template 28 | static bool save(JsonBuffer* buffer, Destination& dest, Source source) { 29 | if (!StringTraits::is_null(source)) { 30 | typename StringTraits::duplicate_t dup = 31 | StringTraits::duplicate(source, buffer); 32 | if (!dup) return false; 33 | dest = dup; 34 | } else { 35 | dest = reinterpret_cast(0); 36 | } 37 | return true; 38 | } 39 | }; 40 | 41 | // const char*, const signed char*, const unsigned char* 42 | template 43 | struct ValueSaver< 44 | Char*, typename EnableIf::should_duplicate>::type> { 45 | template 46 | static bool save(JsonBuffer*, Destination& dest, Char* source) { 47 | dest = reinterpret_cast(source); 48 | return true; 49 | } 50 | }; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Deserialization/Comments.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | template 10 | void skipSpacesAndComments(TInput& input) { 11 | for (;;) { 12 | switch (input.current()) { 13 | // spaces 14 | case ' ': 15 | case '\t': 16 | case '\r': 17 | case '\n': 18 | input.move(); 19 | continue; 20 | 21 | // comments 22 | case '/': 23 | switch (input.next()) { 24 | // C-style block comment 25 | case '*': 26 | input.move(); // skip '/' 27 | // no need to skip '*' 28 | for (;;) { 29 | input.move(); 30 | if (input.current() == '\0') return; 31 | if (input.current() == '*' && input.next() == '/') { 32 | input.move(); // skip '*' 33 | input.move(); // skip '/' 34 | break; 35 | } 36 | } 37 | break; 38 | 39 | // C++-style line comment 40 | case '/': 41 | // not need to skip "//" 42 | for (;;) { 43 | input.move(); 44 | if (input.current() == '\0') return; 45 | if (input.current() == '\n') break; 46 | } 47 | break; 48 | 49 | // not a comment, just a '/' 50 | default: 51 | return; 52 | } 53 | break; 54 | 55 | default: 56 | return; 57 | } 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Deserialization/JsonParser.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../JsonBuffer.hpp" 8 | #include "../JsonVariant.hpp" 9 | #include "../TypeTraits/IsConst.hpp" 10 | #include "StringWriter.hpp" 11 | 12 | namespace ArduinoJson { 13 | namespace Internals { 14 | 15 | // Parse JSON string to create JsonArrays and JsonObjects 16 | // This internal class is not indended to be used directly. 17 | // Instead, use JsonBuffer.parseArray() or .parseObject() 18 | template 19 | class JsonParser { 20 | public: 21 | JsonParser(JsonBuffer *buffer, TReader reader, TWriter writer, 22 | uint8_t nestingLimit) 23 | : _buffer(buffer), 24 | _reader(reader), 25 | _writer(writer), 26 | _nestingLimit(nestingLimit) {} 27 | 28 | JsonArray &parseArray(); 29 | JsonObject &parseObject(); 30 | 31 | JsonVariant parseVariant() { 32 | JsonVariant result; 33 | parseAnythingTo(&result); 34 | return result; 35 | } 36 | 37 | private: 38 | JsonParser &operator=(const JsonParser &); // non-copiable 39 | 40 | static bool eat(TReader &, char charToSkip); 41 | FORCE_INLINE bool eat(char charToSkip) { 42 | return eat(_reader, charToSkip); 43 | } 44 | 45 | const char *parseString(); 46 | bool parseAnythingTo(JsonVariant *destination); 47 | 48 | inline bool parseArrayTo(JsonVariant *destination); 49 | inline bool parseObjectTo(JsonVariant *destination); 50 | inline bool parseStringTo(JsonVariant *destination); 51 | 52 | static inline bool isBetween(char c, char min, char max) { 53 | return min <= c && c <= max; 54 | } 55 | 56 | static inline bool canBeInNonQuotedString(char c) { 57 | return isBetween(c, '0', '9') || isBetween(c, '_', 'z') || 58 | isBetween(c, 'A', 'Z') || c == '+' || c == '-' || c == '.'; 59 | } 60 | 61 | static inline bool isQuote(char c) { 62 | return c == '\'' || c == '\"'; 63 | } 64 | 65 | JsonBuffer *_buffer; 66 | TReader _reader; 67 | TWriter _writer; 68 | uint8_t _nestingLimit; 69 | }; 70 | 71 | template 72 | struct JsonParserBuilder { 73 | typedef typename StringTraits::Reader InputReader; 74 | typedef JsonParser TParser; 75 | 76 | static TParser makeParser(TJsonBuffer *buffer, TString &json, 77 | uint8_t nestingLimit) { 78 | return TParser(buffer, InputReader(json), *buffer, nestingLimit); 79 | } 80 | }; 81 | 82 | template 83 | struct JsonParserBuilder::value>::type> { 85 | typedef typename StringTraits::Reader TReader; 86 | typedef StringWriter TWriter; 87 | typedef JsonParser TParser; 88 | 89 | static TParser makeParser(TJsonBuffer *buffer, TChar *json, 90 | uint8_t nestingLimit) { 91 | return TParser(buffer, TReader(json), TWriter(json), nestingLimit); 92 | } 93 | }; 94 | 95 | template 96 | inline typename JsonParserBuilder::TParser makeParser( 97 | TJsonBuffer *buffer, TString &json, uint8_t nestingLimit) { 98 | return JsonParserBuilder::makeParser(buffer, json, 99 | nestingLimit); 100 | } 101 | } // namespace Internals 102 | } // namespace ArduinoJson 103 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Deserialization/StringWriter.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | template 11 | class StringWriter { 12 | public: 13 | class String { 14 | public: 15 | String(TChar** ptr) : _writePtr(ptr), _startPtr(*ptr) {} 16 | 17 | void append(char c) { 18 | *(*_writePtr)++ = TChar(c); 19 | } 20 | 21 | const char* c_str() const { 22 | *(*_writePtr)++ = 0; 23 | return reinterpret_cast(_startPtr); 24 | } 25 | 26 | private: 27 | TChar** _writePtr; 28 | TChar* _startPtr; 29 | }; 30 | 31 | StringWriter(TChar* buffer) : _ptr(buffer) {} 32 | 33 | String startString() { 34 | return String(&_ptr); 35 | } 36 | 37 | private: 38 | TChar* _ptr; 39 | }; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/DynamicJsonBuffer.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "JsonBufferBase.hpp" 8 | 9 | #include 10 | 11 | #if defined(__clang__) 12 | #pragma clang diagnostic push 13 | #pragma clang diagnostic ignored "-Wnon-virtual-dtor" 14 | #elif defined(__GNUC__) 15 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) 16 | #pragma GCC diagnostic push 17 | #endif 18 | #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" 19 | #endif 20 | 21 | namespace ArduinoJson { 22 | namespace Internals { 23 | class DefaultAllocator { 24 | public: 25 | void* allocate(size_t size) { 26 | return malloc(size); 27 | } 28 | void deallocate(void* pointer) { 29 | free(pointer); 30 | } 31 | }; 32 | 33 | template 34 | class DynamicJsonBufferBase 35 | : public JsonBufferBase > { 36 | struct Block; 37 | struct EmptyBlock { 38 | Block* next; 39 | size_t capacity; 40 | size_t size; 41 | }; 42 | struct Block : EmptyBlock { 43 | uint8_t data[1]; 44 | }; 45 | 46 | public: 47 | enum { EmptyBlockSize = sizeof(EmptyBlock) }; 48 | 49 | DynamicJsonBufferBase(size_t initialSize = 256) 50 | : _head(NULL), _nextBlockCapacity(initialSize) {} 51 | 52 | ~DynamicJsonBufferBase() { 53 | clear(); 54 | } 55 | 56 | // Gets the number of bytes occupied in the buffer 57 | size_t size() const { 58 | size_t total = 0; 59 | for (const Block* b = _head; b; b = b->next) total += b->size; 60 | return total; 61 | } 62 | 63 | // Allocates the specified amount of bytes in the buffer 64 | virtual void* alloc(size_t bytes) { 65 | alignNextAlloc(); 66 | return canAllocInHead(bytes) ? allocInHead(bytes) : allocInNewBlock(bytes); 67 | } 68 | 69 | // Resets the buffer. 70 | // USE WITH CAUTION: this invalidates all previously allocated data 71 | void clear() { 72 | Block* currentBlock = _head; 73 | while (currentBlock != NULL) { 74 | _nextBlockCapacity = currentBlock->capacity; 75 | Block* nextBlock = currentBlock->next; 76 | _allocator.deallocate(currentBlock); 77 | currentBlock = nextBlock; 78 | } 79 | _head = 0; 80 | } 81 | 82 | class String { 83 | public: 84 | String(DynamicJsonBufferBase* parent) 85 | : _parent(parent), _start(NULL), _length(0) {} 86 | 87 | void append(char c) { 88 | if (_parent->canAllocInHead(1)) { 89 | char* end = static_cast(_parent->allocInHead(1)); 90 | *end = c; 91 | if (_length == 0) _start = end; 92 | } else { 93 | char* newStart = 94 | static_cast(_parent->allocInNewBlock(_length + 1)); 95 | if (_start && newStart) memcpy(newStart, _start, _length); 96 | if (newStart) newStart[_length] = c; 97 | _start = newStart; 98 | } 99 | _length++; 100 | } 101 | 102 | const char* c_str() { 103 | append(0); 104 | return _start; 105 | } 106 | 107 | private: 108 | DynamicJsonBufferBase* _parent; 109 | char* _start; 110 | size_t _length; 111 | }; 112 | 113 | String startString() { 114 | return String(this); 115 | } 116 | 117 | private: 118 | void alignNextAlloc() { 119 | if (_head) _head->size = this->round_size_up(_head->size); 120 | } 121 | 122 | bool canAllocInHead(size_t bytes) const { 123 | return _head != NULL && _head->size + bytes <= _head->capacity; 124 | } 125 | 126 | void* allocInHead(size_t bytes) { 127 | void* p = _head->data + _head->size; 128 | _head->size += bytes; 129 | return p; 130 | } 131 | 132 | void* allocInNewBlock(size_t bytes) { 133 | size_t capacity = _nextBlockCapacity; 134 | if (bytes > capacity) capacity = bytes; 135 | if (!addNewBlock(capacity)) return NULL; 136 | _nextBlockCapacity *= 2; 137 | return allocInHead(bytes); 138 | } 139 | 140 | bool addNewBlock(size_t capacity) { 141 | size_t bytes = EmptyBlockSize + capacity; 142 | Block* block = static_cast(_allocator.allocate(bytes)); 143 | if (block == NULL) return false; 144 | block->capacity = capacity; 145 | block->size = 0; 146 | block->next = _head; 147 | _head = block; 148 | return true; 149 | } 150 | 151 | TAllocator _allocator; 152 | Block* _head; 153 | size_t _nextBlockCapacity; 154 | }; 155 | } 156 | 157 | #if defined(__clang__) 158 | #pragma clang diagnostic pop 159 | #elif defined(__GNUC__) 160 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) 161 | #pragma GCC diagnostic pop 162 | #endif 163 | #endif 164 | 165 | // Implements a JsonBuffer with dynamic memory allocation. 166 | // You are strongly encouraged to consider using StaticJsonBuffer which is much 167 | // more suitable for embedded systems. 168 | typedef Internals::DynamicJsonBufferBase 169 | DynamicJsonBuffer; 170 | } 171 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/JsonArrayImpl.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "JsonArray.hpp" 8 | #include "JsonArraySubscript.hpp" 9 | #include "JsonObject.hpp" 10 | 11 | namespace ArduinoJson { 12 | 13 | inline JsonArray &JsonArray::createNestedArray() { 14 | if (!_buffer) return JsonArray::invalid(); 15 | JsonArray &array = _buffer->createArray(); 16 | add(array); 17 | return array; 18 | } 19 | 20 | inline JsonObject &JsonArray::createNestedObject() { 21 | if (!_buffer) return JsonObject::invalid(); 22 | JsonObject &object = _buffer->createObject(); 23 | add(object); 24 | return object; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/JsonArraySubscript.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "Configuration.hpp" 8 | #include "JsonVariantBase.hpp" 9 | 10 | #ifdef _MSC_VER 11 | #pragma warning(push) 12 | #pragma warning(disable : 4522) 13 | #endif 14 | 15 | namespace ArduinoJson { 16 | namespace Internals { 17 | class JsonArraySubscript : public JsonVariantBase { 18 | public: 19 | FORCE_INLINE JsonArraySubscript(JsonArray& array, size_t index) 20 | : _array(array), _index(index) {} 21 | 22 | FORCE_INLINE JsonArraySubscript& operator=(const JsonArraySubscript& src) { 23 | _array.set(_index, src); 24 | return *this; 25 | } 26 | 27 | // Replaces the value 28 | // 29 | // operator=(const TValue&) 30 | // TValue = bool, long, int, short, float, double, RawJson, JsonVariant, 31 | // std::string, String, JsonArray, JsonObject 32 | template 33 | FORCE_INLINE JsonArraySubscript& operator=(const T& src) { 34 | _array.set(_index, src); 35 | return *this; 36 | } 37 | // 38 | // operator=(TValue) 39 | // TValue = char*, const char*, const FlashStringHelper* 40 | template 41 | FORCE_INLINE JsonArraySubscript& operator=(T* src) { 42 | _array.set(_index, src); 43 | return *this; 44 | } 45 | 46 | FORCE_INLINE bool success() const { 47 | return _index < _array.size(); 48 | } 49 | 50 | template 51 | FORCE_INLINE typename JsonVariantAs::type as() const { 52 | return _array.get(_index); 53 | } 54 | 55 | template 56 | FORCE_INLINE bool is() const { 57 | return _array.is(_index); 58 | } 59 | 60 | // Replaces the value 61 | // 62 | // bool set(const TValue&) 63 | // TValue = bool, long, int, short, float, double, RawJson, JsonVariant, 64 | // std::string, String, JsonArray, JsonObject 65 | template 66 | FORCE_INLINE bool set(const TValue& value) { 67 | return _array.set(_index, value); 68 | } 69 | // 70 | // bool set(TValue) 71 | // TValue = char*, const char*, const FlashStringHelper* 72 | template 73 | FORCE_INLINE bool set(TValue* value) { 74 | return _array.set(_index, value); 75 | } 76 | // 77 | // bool set(TValue, uint8_t decimals); 78 | // TValue = float, double 79 | template 80 | DEPRECATED("Second argument is not supported anymore") 81 | FORCE_INLINE bool set(const TValue& value, uint8_t) { 82 | return _array.set(_index, value); 83 | } 84 | 85 | private: 86 | JsonArray& _array; 87 | const size_t _index; 88 | }; 89 | 90 | template 91 | inline JsonArraySubscript JsonVariantSubscripts::operator[]( 92 | size_t index) { 93 | return impl()->template as()[index]; 94 | } 95 | 96 | template 97 | inline const JsonArraySubscript JsonVariantSubscripts::operator[]( 98 | size_t index) const { 99 | return impl()->template as()[index]; 100 | } 101 | 102 | #if ARDUINOJSON_ENABLE_STD_STREAM 103 | inline std::ostream& operator<<(std::ostream& os, 104 | const JsonArraySubscript& source) { 105 | return source.printTo(os); 106 | } 107 | #endif 108 | } 109 | 110 | inline Internals::JsonArraySubscript JsonArray::operator[](size_t index) { 111 | return Internals::JsonArraySubscript(*this, index); 112 | } 113 | 114 | inline const Internals::JsonArraySubscript JsonArray::operator[]( 115 | size_t index) const { 116 | return Internals::JsonArraySubscript(*const_cast(this), index); 117 | } 118 | } 119 | 120 | #ifdef _MSC_VER 121 | #pragma warning(pop) 122 | #endif 123 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/JsonBuffer.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include // for size_t 8 | #include // for uint8_t 9 | #include 10 | 11 | #include "Data/NonCopyable.hpp" 12 | #include "JsonVariant.hpp" 13 | #include "TypeTraits/EnableIf.hpp" 14 | #include "TypeTraits/IsArray.hpp" 15 | 16 | namespace ArduinoJson { 17 | class JsonArray; 18 | class JsonObject; 19 | 20 | // Entry point for using the library. 21 | // 22 | // Handle the memory management (done in derived classes) and calls the parser. 23 | // This abstract class is implemented by StaticJsonBuffer which implements a 24 | // fixed memory allocation. 25 | class JsonBuffer : Internals::NonCopyable { 26 | public: 27 | // Allocates an empty JsonArray. 28 | // 29 | // Returns a reference to the new JsonArray or JsonArray::invalid() if the 30 | // allocation fails. 31 | JsonArray &createArray(); 32 | 33 | // Allocates an empty JsonObject. 34 | // 35 | // Returns a reference to the new JsonObject or JsonObject::invalid() if the 36 | // allocation fails. 37 | JsonObject &createObject(); 38 | 39 | // Duplicates a string 40 | // 41 | // const char* strdup(TValue); 42 | // TValue = const std::string&, const String&, 43 | template 44 | DEPRECATED("char* are duplicated, you don't need strdup() anymore") 45 | typename Internals::EnableIf::value, 46 | const char *>::type strdup(const TString &src) { 47 | return Internals::StringTraits::duplicate(src, this); 48 | } 49 | // 50 | // const char* strdup(TValue); 51 | // TValue = char*, const char*, const FlashStringHelper* 52 | template 53 | DEPRECATED("char* are duplicated, you don't need strdup() anymore") 54 | const char *strdup(TString *src) { 55 | return Internals::StringTraits::duplicate(src, this); 56 | } 57 | 58 | // Allocates n bytes in the JsonBuffer. 59 | // Return a pointer to the allocated memory or NULL if allocation fails. 60 | virtual void *alloc(size_t size) = 0; 61 | 62 | protected: 63 | // CAUTION: NO VIRTUAL DESTRUCTOR! 64 | // If we add a virtual constructor the Arduino compiler will add malloc() 65 | // and free() to the binary, adding 706 useless bytes. 66 | ~JsonBuffer() {} 67 | 68 | // Preserve aligment if necessary 69 | static FORCE_INLINE size_t round_size_up(size_t bytes) { 70 | #if ARDUINOJSON_ENABLE_ALIGNMENT 71 | const size_t x = sizeof(void *) - 1; 72 | return (bytes + x) & ~x; 73 | #else 74 | return bytes; 75 | #endif 76 | } 77 | }; 78 | } 79 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/JsonBufferImpl.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "Deserialization/JsonParser.hpp" 8 | 9 | inline ArduinoJson::JsonArray &ArduinoJson::JsonBuffer::createArray() { 10 | JsonArray *ptr = new (this) JsonArray(this); 11 | return ptr ? *ptr : JsonArray::invalid(); 12 | } 13 | 14 | inline ArduinoJson::JsonObject &ArduinoJson::JsonBuffer::createObject() { 15 | JsonObject *ptr = new (this) JsonObject(this); 16 | return ptr ? *ptr : JsonObject::invalid(); 17 | } 18 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/JsonObjectImpl.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "JsonArray.hpp" 8 | #include "JsonObject.hpp" 9 | #include "JsonObjectSubscript.hpp" 10 | 11 | namespace ArduinoJson { 12 | 13 | template 14 | inline JsonArray &JsonObject::createNestedArray_impl(TStringRef key) { 15 | if (!_buffer) return JsonArray::invalid(); 16 | JsonArray &array = _buffer->createArray(); 17 | set(key, array); 18 | return array; 19 | } 20 | 21 | template 22 | inline JsonObject &JsonObject::createNestedObject_impl(TStringRef key) { 23 | if (!_buffer) return JsonObject::invalid(); 24 | JsonObject &object = _buffer->createObject(); 25 | set(key, object); 26 | return object; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/JsonObjectSubscript.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "Configuration.hpp" 8 | #include "JsonVariantBase.hpp" 9 | #include "TypeTraits/EnableIf.hpp" 10 | 11 | #ifdef _MSC_VER 12 | #pragma warning(push) 13 | #pragma warning(disable : 4522) 14 | #endif 15 | 16 | namespace ArduinoJson { 17 | namespace Internals { 18 | 19 | template 20 | class JsonObjectSubscript 21 | : public JsonVariantBase > { 22 | typedef JsonObjectSubscript this_type; 23 | 24 | public: 25 | FORCE_INLINE JsonObjectSubscript(JsonObject& object, TStringRef key) 26 | : _object(object), _key(key) {} 27 | 28 | FORCE_INLINE this_type& operator=(const this_type& src) { 29 | _object.set(_key, src); 30 | return *this; 31 | } 32 | 33 | // Set the specified value 34 | // 35 | // operator=(const TValue&); 36 | // TValue = bool, char, long, int, short, float, double, 37 | // std::string, String, JsonArray, JsonObject 38 | template 39 | FORCE_INLINE typename EnableIf::value, this_type&>::type 40 | operator=(const TValue& src) { 41 | _object.set(_key, src); 42 | return *this; 43 | } 44 | // 45 | // operator=(TValue); 46 | // TValue = char*, const char*, const FlashStringHelper* 47 | template 48 | FORCE_INLINE this_type& operator=(TValue* src) { 49 | _object.set(_key, src); 50 | return *this; 51 | } 52 | 53 | FORCE_INLINE bool success() const { 54 | return _object.containsKey(_key); 55 | } 56 | 57 | template 58 | FORCE_INLINE typename JsonVariantAs::type as() const { 59 | return _object.get(_key); 60 | } 61 | 62 | template 63 | FORCE_INLINE bool is() const { 64 | return _object.is(_key); 65 | } 66 | 67 | // Sets the specified value. 68 | // 69 | // bool set(const TValue&); 70 | // TValue = bool, char, long, int, short, float, double, RawJson, JsonVariant, 71 | // std::string, String, JsonArray, JsonObject 72 | template 73 | FORCE_INLINE typename EnableIf::value, bool>::type set( 74 | const TValue& value) { 75 | return _object.set(_key, value); 76 | } 77 | // 78 | // bool set(TValue); 79 | // TValue = char*, const char, const FlashStringHelper* 80 | template 81 | FORCE_INLINE bool set(const TValue* value) { 82 | return _object.set(_key, value); 83 | } 84 | // 85 | // bool set(TValue, uint8_t decimals); 86 | // TValue = float, double 87 | template 88 | DEPRECATED("Second argument is not supported anymore") 89 | FORCE_INLINE bool set(const TValue& value, uint8_t) { 90 | return _object.set(_key, value); 91 | } 92 | 93 | private: 94 | JsonObject& _object; 95 | TStringRef _key; 96 | }; 97 | 98 | #if ARDUINOJSON_ENABLE_STD_STREAM 99 | template 100 | inline std::ostream& operator<<(std::ostream& os, 101 | const JsonObjectSubscript& source) { 102 | return source.printTo(os); 103 | } 104 | #endif 105 | } 106 | } 107 | 108 | #ifdef _MSC_VER 109 | #pragma warning(pop) 110 | #endif 111 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/JsonPair.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "JsonVariant.hpp" 8 | 9 | namespace ArduinoJson { 10 | 11 | // A key value pair for JsonObject. 12 | struct JsonPair { 13 | const char* key; 14 | JsonVariant value; 15 | }; 16 | } 17 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/JsonVariantBase.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "JsonVariantCasts.hpp" 8 | #include "JsonVariantComparisons.hpp" 9 | #include "JsonVariantOr.hpp" 10 | #include "JsonVariantSubscripts.hpp" 11 | #include "Serialization/JsonPrintable.hpp" 12 | 13 | namespace ArduinoJson { 14 | namespace Internals { 15 | 16 | template 17 | class JsonVariantBase : public JsonPrintable, 18 | public JsonVariantCasts, 19 | public JsonVariantComparisons, 20 | public JsonVariantOr, 21 | public JsonVariantSubscripts, 22 | public JsonVariantTag {}; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/JsonVariantCasts.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "Data/JsonVariantAs.hpp" 8 | #include "Polyfills/attributes.hpp" 9 | 10 | namespace ArduinoJson { 11 | namespace Internals { 12 | 13 | template 14 | class JsonVariantCasts { 15 | public: 16 | #if ARDUINOJSON_ENABLE_DEPRECATED 17 | DEPRECATED("use as() instead") 18 | FORCE_INLINE JsonArray &asArray() const { 19 | return impl()->template as(); 20 | } 21 | 22 | DEPRECATED("use as() instead") 23 | FORCE_INLINE JsonObject &asObject() const { 24 | return impl()->template as(); 25 | } 26 | 27 | DEPRECATED("use as() instead") 28 | FORCE_INLINE const char *asString() const { 29 | return impl()->template as(); 30 | } 31 | #endif 32 | 33 | // Gets the variant as an array. 34 | // Returns a reference to the JsonArray or JsonArray::invalid() if the 35 | // variant 36 | // is not an array. 37 | FORCE_INLINE operator JsonArray &() const { 38 | return impl()->template as(); 39 | } 40 | 41 | // Gets the variant as an object. 42 | // Returns a reference to the JsonObject or JsonObject::invalid() if the 43 | // variant is not an object. 44 | FORCE_INLINE operator JsonObject &() const { 45 | return impl()->template as(); 46 | } 47 | 48 | template 49 | FORCE_INLINE operator T() const { 50 | return impl()->template as(); 51 | } 52 | 53 | private: 54 | const TImpl *impl() const { 55 | return static_cast(this); 56 | } 57 | }; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/JsonVariantImpl.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "Configuration.hpp" 8 | #include "JsonArray.hpp" 9 | #include "JsonObject.hpp" 10 | #include "JsonVariant.hpp" 11 | #include "Polyfills/isFloat.hpp" 12 | #include "Polyfills/isInteger.hpp" 13 | #include "Polyfills/parseFloat.hpp" 14 | #include "Polyfills/parseInteger.hpp" 15 | 16 | #include // for strcmp 17 | 18 | namespace ArduinoJson { 19 | 20 | inline JsonVariant::JsonVariant(const JsonArray &array) { 21 | if (array.success()) { 22 | _type = Internals::JSON_ARRAY; 23 | _content.asArray = const_cast(&array); 24 | } else { 25 | _type = Internals::JSON_UNDEFINED; 26 | } 27 | } 28 | 29 | inline JsonVariant::JsonVariant(const JsonObject &object) { 30 | if (object.success()) { 31 | _type = Internals::JSON_OBJECT; 32 | _content.asObject = const_cast(&object); 33 | } else { 34 | _type = Internals::JSON_UNDEFINED; 35 | } 36 | } 37 | 38 | inline JsonArray &JsonVariant::variantAsArray() const { 39 | if (_type == Internals::JSON_ARRAY) return *_content.asArray; 40 | return JsonArray::invalid(); 41 | } 42 | 43 | inline JsonObject &JsonVariant::variantAsObject() const { 44 | if (_type == Internals::JSON_OBJECT) return *_content.asObject; 45 | return JsonObject::invalid(); 46 | } 47 | 48 | template 49 | inline T JsonVariant::variantAsInteger() const { 50 | using namespace Internals; 51 | switch (_type) { 52 | case JSON_UNDEFINED: 53 | return 0; 54 | case JSON_POSITIVE_INTEGER: 55 | case JSON_BOOLEAN: 56 | return T(_content.asInteger); 57 | case JSON_NEGATIVE_INTEGER: 58 | return T(~_content.asInteger + 1); 59 | case JSON_STRING: 60 | case JSON_UNPARSED: 61 | return parseInteger(_content.asString); 62 | default: 63 | return T(_content.asFloat); 64 | } 65 | } 66 | 67 | inline const char *JsonVariant::variantAsString() const { 68 | using namespace Internals; 69 | if (_type == JSON_UNPARSED && _content.asString && 70 | !strcmp("null", _content.asString)) 71 | return NULL; 72 | if (_type == JSON_STRING || _type == JSON_UNPARSED) return _content.asString; 73 | return NULL; 74 | } 75 | 76 | template 77 | inline T JsonVariant::variantAsFloat() const { 78 | using namespace Internals; 79 | switch (_type) { 80 | case JSON_UNDEFINED: 81 | return 0; 82 | case JSON_POSITIVE_INTEGER: 83 | case JSON_BOOLEAN: 84 | return static_cast(_content.asInteger); 85 | case JSON_NEGATIVE_INTEGER: 86 | return -static_cast(_content.asInteger); 87 | case JSON_STRING: 88 | case JSON_UNPARSED: 89 | return parseFloat(_content.asString); 90 | default: 91 | return static_cast(_content.asFloat); 92 | } 93 | } 94 | 95 | inline bool JsonVariant::variantIsBoolean() const { 96 | using namespace Internals; 97 | if (_type == JSON_BOOLEAN) return true; 98 | 99 | if (_type != JSON_UNPARSED || _content.asString == NULL) return false; 100 | 101 | return !strcmp(_content.asString, "true") || 102 | !strcmp(_content.asString, "false"); 103 | } 104 | 105 | inline bool JsonVariant::variantIsInteger() const { 106 | using namespace Internals; 107 | 108 | return _type == JSON_POSITIVE_INTEGER || _type == JSON_NEGATIVE_INTEGER || 109 | (_type == JSON_UNPARSED && isInteger(_content.asString)); 110 | } 111 | 112 | inline bool JsonVariant::variantIsFloat() const { 113 | using namespace Internals; 114 | 115 | return _type == JSON_FLOAT || _type == JSON_POSITIVE_INTEGER || 116 | _type == JSON_NEGATIVE_INTEGER || 117 | (_type == JSON_UNPARSED && isFloat(_content.asString)); 118 | } 119 | 120 | #if ARDUINOJSON_ENABLE_STD_STREAM 121 | inline std::ostream &operator<<(std::ostream &os, const JsonVariant &source) { 122 | return source.printTo(os); 123 | } 124 | #endif 125 | 126 | } // namespace ArduinoJson 127 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/JsonVariantOr.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "Data/JsonVariantAs.hpp" 8 | #include "Polyfills/attributes.hpp" 9 | #include "TypeTraits/EnableIf.hpp" 10 | #include "TypeTraits/IsIntegral.hpp" 11 | 12 | namespace ArduinoJson { 13 | namespace Internals { 14 | 15 | template 16 | class JsonVariantOr { 17 | public: 18 | // Returns the default value if the JsonVariant is undefined of incompatible 19 | template 20 | typename EnableIf::value, T>::type operator|( 21 | const T &defaultValue) const { 22 | if (impl()->template is()) 23 | return impl()->template as(); 24 | else 25 | return defaultValue; 26 | } 27 | 28 | // Returns the default value if the JsonVariant is undefined of incompatible 29 | // Special case for string: null is treated as undefined 30 | const char *operator|(const char *defaultValue) const { 31 | const char *value = impl()->template as(); 32 | return value ? value : defaultValue; 33 | } 34 | 35 | // Returns the default value if the JsonVariant is undefined of incompatible 36 | // Special case for integers: we also accept double 37 | template 38 | typename EnableIf::value, Integer>::type operator|( 39 | const Integer &defaultValue) const { 40 | if (impl()->template is()) 41 | return impl()->template as(); 42 | else 43 | return defaultValue; 44 | } 45 | 46 | private: 47 | const TImpl *impl() const { 48 | return static_cast(this); 49 | } 50 | }; 51 | } // namespace Internals 52 | } // namespace ArduinoJson 53 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/JsonVariantSubscripts.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "Data/JsonVariantAs.hpp" 8 | #include "Polyfills/attributes.hpp" 9 | #include "StringTraits/StringTraits.hpp" 10 | #include "TypeTraits/EnableIf.hpp" 11 | 12 | namespace ArduinoJson { 13 | namespace Internals { 14 | 15 | // Forward declarations. 16 | class JsonArraySubscript; 17 | template 18 | class JsonObjectSubscript; 19 | 20 | template 21 | class JsonVariantSubscripts { 22 | public: 23 | // Mimics an array or an object. 24 | // Returns the size of the array or object if the variant has that type. 25 | // Returns 0 if the variant is neither an array nor an object 26 | size_t size() const { 27 | return impl()->template as().size() + 28 | impl()->template as().size(); 29 | } 30 | 31 | // Mimics an array. 32 | // Returns the element at specified index if the variant is an array. 33 | // Returns JsonVariant::invalid() if the variant is not an array. 34 | FORCE_INLINE const JsonArraySubscript operator[](size_t index) const; 35 | FORCE_INLINE JsonArraySubscript operator[](size_t index); 36 | 37 | // Mimics an object. 38 | // Returns the value associated with the specified key if the variant is 39 | // an object. 40 | // Return JsonVariant::invalid() if the variant is not an object. 41 | // 42 | // const JsonObjectSubscript operator[](TKey) const; 43 | // TKey = const std::string&, const String& 44 | template 45 | FORCE_INLINE 46 | typename EnableIf::has_equals, 47 | const JsonObjectSubscript >::type 48 | operator[](const TString &key) const { 49 | return impl()->template as()[key]; 50 | } 51 | // 52 | // const JsonObjectSubscript operator[](TKey) const; 53 | // TKey = const std::string&, const String& 54 | template 55 | FORCE_INLINE typename EnableIf::has_equals, 56 | JsonObjectSubscript >::type 57 | operator[](const TString &key) { 58 | return impl()->template as()[key]; 59 | } 60 | // 61 | // JsonObjectSubscript operator[](TKey); 62 | // TKey = const char*, const char[N], const FlashStringHelper* 63 | template 64 | FORCE_INLINE typename EnableIf::has_equals, 65 | JsonObjectSubscript >::type 66 | operator[](const TString *key) { 67 | return impl()->template as()[key]; 68 | } 69 | // 70 | // JsonObjectSubscript operator[](TKey); 71 | // TKey = const char*, const char[N], const FlashStringHelper* 72 | template 73 | FORCE_INLINE 74 | typename EnableIf::has_equals, 75 | const JsonObjectSubscript >::type 76 | operator[](const TString *key) const { 77 | return impl()->template as()[key]; 78 | } 79 | 80 | private: 81 | const TImpl *impl() const { 82 | return static_cast(this); 83 | } 84 | }; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Polyfills/attributes.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #ifdef _MSC_VER // Visual Studio 8 | 9 | #define FORCE_INLINE // __forceinline causes C4714 when returning std::string 10 | #define NO_INLINE __declspec(noinline) 11 | #define DEPRECATED(msg) __declspec(deprecated(msg)) 12 | 13 | #elif defined(__GNUC__) // GCC or Clang 14 | 15 | #define FORCE_INLINE __attribute__((always_inline)) 16 | #define NO_INLINE __attribute__((noinline)) 17 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) 18 | #define DEPRECATED(msg) __attribute__((deprecated(msg))) 19 | #else 20 | #define DEPRECATED(msg) __attribute__((deprecated)) 21 | #endif 22 | 23 | #else // Other compilers 24 | 25 | #define FORCE_INLINE 26 | #define NO_INLINE 27 | #define DEPRECATED(msg) 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Polyfills/ctype.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | inline bool isdigit(char c) { 11 | return '0' <= c && c <= '9'; 12 | } 13 | 14 | inline bool issign(char c) { 15 | return '-' == c || c == '+'; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Polyfills/isFloat.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include // for strcmp 8 | #include "./ctype.hpp" 9 | 10 | namespace ArduinoJson { 11 | namespace Internals { 12 | 13 | inline bool isFloat(const char* s) { 14 | if (!s) return false; 15 | 16 | if (!strcmp(s, "NaN")) return true; 17 | if (issign(*s)) s++; 18 | if (!strcmp(s, "Infinity")) return true; 19 | if (*s == '\0') return false; 20 | 21 | while (isdigit(*s)) s++; 22 | 23 | if (*s == '.') { 24 | s++; 25 | while (isdigit(*s)) s++; 26 | } 27 | 28 | if (*s == 'e' || *s == 'E') { 29 | s++; 30 | if (issign(*s)) s++; 31 | if (!isdigit(*s)) return false; 32 | while (isdigit(*s)) s++; 33 | } 34 | 35 | return *s == '\0'; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Polyfills/isInteger.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "./ctype.hpp" 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | 12 | inline bool isInteger(const char* s) { 13 | if (!s) return false; 14 | if (issign(*s)) s++; 15 | while (isdigit(*s)) s++; 16 | return *s == '\0'; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Polyfills/math.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | template 10 | bool isNaN(T x) { 11 | return x != x; 12 | } 13 | 14 | template 15 | bool isInfinity(T x) { 16 | return x != 0.0 && x * 2 == x; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Polyfills/parseFloat.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../TypeTraits/FloatTraits.hpp" 8 | #include "./ctype.hpp" 9 | #include "./math.hpp" 10 | 11 | namespace ArduinoJson { 12 | namespace Internals { 13 | 14 | template 15 | inline T parseFloat(const char* s) { 16 | typedef FloatTraits traits; 17 | typedef typename traits::mantissa_type mantissa_t; 18 | typedef typename traits::exponent_type exponent_t; 19 | 20 | if (!s) return 0; // NULL 21 | 22 | bool negative_result = false; 23 | switch (*s) { 24 | case '-': 25 | negative_result = true; 26 | s++; 27 | break; 28 | case '+': 29 | s++; 30 | break; 31 | } 32 | 33 | if (*s == 't') return 1; // true 34 | if (*s == 'n' || *s == 'N') return traits::nan(); 35 | if (*s == 'i' || *s == 'I') 36 | return negative_result ? -traits::inf() : traits::inf(); 37 | 38 | mantissa_t mantissa = 0; 39 | exponent_t exponent_offset = 0; 40 | 41 | while (isdigit(*s)) { 42 | if (mantissa < traits::mantissa_max / 10) 43 | mantissa = mantissa * 10 + (*s - '0'); 44 | else 45 | exponent_offset++; 46 | s++; 47 | } 48 | 49 | if (*s == '.') { 50 | s++; 51 | while (isdigit(*s)) { 52 | if (mantissa < traits::mantissa_max / 10) { 53 | mantissa = mantissa * 10 + (*s - '0'); 54 | exponent_offset--; 55 | } 56 | s++; 57 | } 58 | } 59 | 60 | int exponent = 0; 61 | if (*s == 'e' || *s == 'E') { 62 | s++; 63 | bool negative_exponent = false; 64 | if (*s == '-') { 65 | negative_exponent = true; 66 | s++; 67 | } else if (*s == '+') { 68 | s++; 69 | } 70 | 71 | while (isdigit(*s)) { 72 | exponent = exponent * 10 + (*s - '0'); 73 | if (exponent + exponent_offset > traits::exponent_max) { 74 | if (negative_exponent) 75 | return negative_result ? -0.0f : 0.0f; 76 | else 77 | return negative_result ? -traits::inf() : traits::inf(); 78 | } 79 | s++; 80 | } 81 | if (negative_exponent) exponent = -exponent; 82 | } 83 | exponent += exponent_offset; 84 | 85 | T result = traits::make_float(static_cast(mantissa), exponent); 86 | 87 | return negative_result ? -result : result; 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Polyfills/parseInteger.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | #include "../Configuration.hpp" 10 | #include "./ctype.hpp" 11 | 12 | namespace ArduinoJson { 13 | namespace Internals { 14 | template 15 | T parseInteger(const char *s) { 16 | if (!s) return 0; // NULL 17 | 18 | if (*s == 't') return 1; // "true" 19 | 20 | T result = 0; 21 | bool negative_result = false; 22 | 23 | switch (*s) { 24 | case '-': 25 | negative_result = true; 26 | s++; 27 | break; 28 | case '+': 29 | s++; 30 | break; 31 | } 32 | 33 | while (isdigit(*s)) { 34 | result = T(result * 10 + T(*s - '0')); 35 | s++; 36 | } 37 | 38 | return negative_result ? T(~result + 1) : result; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/RawJson.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | 9 | namespace Internals { 10 | // A special type of data that can be used to insert pregenerated JSON portions. 11 | template 12 | class RawJsonString { 13 | public: 14 | explicit RawJsonString(T str) : _str(str) {} 15 | operator T() const { 16 | return _str; 17 | } 18 | 19 | private: 20 | T _str; 21 | }; 22 | 23 | template 24 | struct StringTraits, void> { 25 | static bool is_null(RawJsonString source) { 26 | return StringTraits::is_null(static_cast(source)); 27 | } 28 | 29 | typedef RawJsonString duplicate_t; 30 | 31 | template 32 | static duplicate_t duplicate(RawJsonString source, Buffer* buffer) { 33 | return duplicate_t(StringTraits::duplicate(source, buffer)); 34 | } 35 | 36 | static const bool has_append = false; 37 | static const bool has_equals = false; 38 | static const bool should_duplicate = StringTraits::should_duplicate; 39 | }; 40 | } 41 | 42 | template 43 | inline Internals::RawJsonString RawJson(T str) { 44 | return Internals::RawJsonString(str); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Serialization/DummyPrint.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // A dummy Print implementation used in JsonPrintable::measureLength() 11 | class DummyPrint { 12 | public: 13 | size_t print(char) { 14 | return 1; 15 | } 16 | 17 | size_t print(const char* s) { 18 | return strlen(s); 19 | } 20 | }; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Serialization/DynamicStringBuilder.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../StringTraits/StringTraits.hpp" 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | 12 | // A Print implementation that allows to write in a String 13 | template 14 | class DynamicStringBuilder { 15 | public: 16 | DynamicStringBuilder(TString &str) : _str(str) {} 17 | 18 | size_t print(char c) { 19 | StringTraits::append(_str, c); 20 | return 1; 21 | } 22 | 23 | size_t print(const char *s) { 24 | size_t initialLen = _str.length(); 25 | StringTraits::append(_str, s); 26 | return _str.length() - initialLen; 27 | } 28 | 29 | private: 30 | DynamicStringBuilder &operator=(const DynamicStringBuilder &); 31 | 32 | TString &_str; 33 | }; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Serialization/FloatParts.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../Configuration.hpp" 8 | #include "../Polyfills/math.hpp" 9 | #include "../TypeTraits/FloatTraits.hpp" 10 | 11 | namespace ArduinoJson { 12 | namespace Internals { 13 | 14 | template 15 | struct FloatParts { 16 | uint32_t integral; 17 | uint32_t decimal; 18 | int16_t exponent; 19 | int8_t decimalPlaces; 20 | 21 | FloatParts(TFloat value) { 22 | uint32_t maxDecimalPart = sizeof(TFloat) >= 8 ? 1000000000 : 1000000; 23 | decimalPlaces = sizeof(TFloat) >= 8 ? 9 : 6; 24 | 25 | exponent = normalize(value); 26 | 27 | integral = uint32_t(value); 28 | // reduce number of decimal places by the number of integral places 29 | for (uint32_t tmp = integral; tmp >= 10; tmp /= 10) { 30 | maxDecimalPart /= 10; 31 | decimalPlaces--; 32 | } 33 | 34 | TFloat remainder = (value - TFloat(integral)) * TFloat(maxDecimalPart); 35 | 36 | decimal = uint32_t(remainder); 37 | remainder = remainder - TFloat(decimal); 38 | 39 | // rounding: 40 | // increment by 1 if remainder >= 0.5 41 | decimal += uint32_t(remainder * 2); 42 | if (decimal >= maxDecimalPart) { 43 | decimal = 0; 44 | integral++; 45 | if (exponent && integral >= 10) { 46 | exponent++; 47 | integral = 1; 48 | } 49 | } 50 | 51 | // remove trailing zeros 52 | while (decimal % 10 == 0 && decimalPlaces > 0) { 53 | decimal /= 10; 54 | decimalPlaces--; 55 | } 56 | } 57 | 58 | static int16_t normalize(TFloat& value) { 59 | typedef FloatTraits traits; 60 | int16_t powersOf10 = 0; 61 | 62 | int8_t index = sizeof(TFloat) == 8 ? 8 : 5; 63 | int bit = 1 << index; 64 | 65 | if (value >= ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD) { 66 | for (; index >= 0; index--) { 67 | if (value >= traits::positiveBinaryPowerOfTen(index)) { 68 | value *= traits::negativeBinaryPowerOfTen(index); 69 | powersOf10 = int16_t(powersOf10 + bit); 70 | } 71 | bit >>= 1; 72 | } 73 | } 74 | 75 | if (value > 0 && value <= ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD) { 76 | for (; index >= 0; index--) { 77 | if (value < traits::negativeBinaryPowerOfTenPlusOne(index)) { 78 | value *= traits::positiveBinaryPowerOfTen(index); 79 | powersOf10 = int16_t(powersOf10 - bit); 80 | } 81 | bit >>= 1; 82 | } 83 | } 84 | 85 | return powersOf10; 86 | } 87 | }; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Serialization/IndentedPrint.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // Decorator on top of Print to allow indented output. 11 | // This class is used by JsonPrintable::prettyPrintTo() but can also be used 12 | // for your own purpose, like logging. 13 | template 14 | class IndentedPrint { 15 | public: 16 | explicit IndentedPrint(Print &p) : sink(&p) { 17 | level = 0; 18 | tabSize = 2; 19 | isNewLine = true; 20 | } 21 | 22 | size_t print(char c) { 23 | size_t n = 0; 24 | if (isNewLine) n += writeTabs(); 25 | n += sink->print(c); 26 | isNewLine = c == '\n'; 27 | return n; 28 | } 29 | 30 | size_t print(const char *s) { 31 | // TODO: optimize 32 | size_t n = 0; 33 | while (*s) n += print(*s++); 34 | return n; 35 | } 36 | 37 | // Adds one level of indentation 38 | void indent() { 39 | if (level < MAX_LEVEL) level++; 40 | } 41 | 42 | // Removes one level of indentation 43 | void unindent() { 44 | if (level > 0) level--; 45 | } 46 | 47 | // Set the number of space printed for each level of indentation 48 | void setTabSize(uint8_t n) { 49 | if (n < MAX_TAB_SIZE) tabSize = n & MAX_TAB_SIZE; 50 | } 51 | 52 | private: 53 | Print *sink; 54 | uint8_t level : 4; 55 | uint8_t tabSize : 3; 56 | bool isNewLine : 1; 57 | 58 | size_t writeTabs() { 59 | size_t n = 0; 60 | for (int i = 0; i < level * tabSize; i++) n += sink->print(' '); 61 | return n; 62 | } 63 | 64 | static const int MAX_LEVEL = 15; // because it's only 4 bits 65 | static const int MAX_TAB_SIZE = 7; // because it's only 3 bits 66 | }; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Serialization/JsonPrintable.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../Configuration.hpp" 8 | #include "../TypeTraits/EnableIf.hpp" 9 | #include "DummyPrint.hpp" 10 | #include "DynamicStringBuilder.hpp" 11 | #include "IndentedPrint.hpp" 12 | #include "JsonSerializer.hpp" 13 | #include "JsonWriter.hpp" 14 | #include "Prettyfier.hpp" 15 | #include "StaticStringBuilder.hpp" 16 | 17 | #if ARDUINOJSON_ENABLE_STD_STREAM 18 | #include "StreamPrintAdapter.hpp" 19 | #endif 20 | 21 | namespace ArduinoJson { 22 | namespace Internals { 23 | 24 | // Implements all the overloads of printTo() and prettyPrintTo() 25 | // Caution: this class use a template parameter to avoid virtual methods. 26 | // This is a bit curious but allows to reduce the size of JsonVariant, JsonArray 27 | // and JsonObject. 28 | template 29 | class JsonPrintable { 30 | public: 31 | template 32 | typename EnableIf::has_append, size_t>::type printTo( 33 | Print &print) const { 34 | JsonWriter writer(print); 35 | JsonSerializer >::serialize(downcast(), writer); 36 | return writer.bytesWritten(); 37 | } 38 | 39 | #if ARDUINOJSON_ENABLE_STD_STREAM 40 | std::ostream &printTo(std::ostream &os) const { 41 | StreamPrintAdapter adapter(os); 42 | printTo(adapter); 43 | return os; 44 | } 45 | #endif 46 | 47 | size_t printTo(char *buffer, size_t bufferSize) const { 48 | StaticStringBuilder sb(buffer, bufferSize); 49 | return printTo(sb); 50 | } 51 | 52 | template 53 | size_t printTo(char (&buffer)[N]) const { 54 | return printTo(buffer, N); 55 | } 56 | 57 | template 58 | typename EnableIf::has_append, size_t>::type printTo( 59 | TString &str) const { 60 | DynamicStringBuilder sb(str); 61 | return printTo(sb); 62 | } 63 | 64 | template 65 | size_t prettyPrintTo(IndentedPrint &print) const { 66 | Prettyfier p(print); 67 | return printTo(p); 68 | } 69 | 70 | size_t prettyPrintTo(char *buffer, size_t bufferSize) const { 71 | StaticStringBuilder sb(buffer, bufferSize); 72 | return prettyPrintTo(sb); 73 | } 74 | 75 | template 76 | size_t prettyPrintTo(char (&buffer)[N]) const { 77 | return prettyPrintTo(buffer, N); 78 | } 79 | 80 | template 81 | typename EnableIf::has_append, size_t>::type 82 | prettyPrintTo(Print &print) const { 83 | IndentedPrint indentedPrint(print); 84 | return prettyPrintTo(indentedPrint); 85 | } 86 | 87 | template 88 | typename EnableIf::has_append, size_t>::type 89 | prettyPrintTo(TString &str) const { 90 | DynamicStringBuilder sb(str); 91 | return prettyPrintTo(sb); 92 | } 93 | 94 | size_t measureLength() const { 95 | DummyPrint dp; 96 | return printTo(dp); 97 | } 98 | 99 | size_t measurePrettyLength() const { 100 | DummyPrint dp; 101 | return prettyPrintTo(dp); 102 | } 103 | 104 | private: 105 | const T &downcast() const { 106 | return *static_cast(this); 107 | } 108 | }; 109 | 110 | #if ARDUINOJSON_ENABLE_STD_STREAM 111 | template 112 | inline std::ostream &operator<<(std::ostream &os, const JsonPrintable &v) { 113 | return v.printTo(os); 114 | } 115 | #endif 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Serialization/JsonSerializer.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "JsonWriter.hpp" 8 | 9 | namespace ArduinoJson { 10 | 11 | class JsonArray; 12 | class JsonObject; 13 | class JsonVariant; 14 | 15 | namespace Internals { 16 | 17 | class JsonArraySubscript; 18 | template 19 | class JsonObjectSubscript; 20 | 21 | template 22 | class JsonSerializer { 23 | public: 24 | static void serialize(const JsonArray &, Writer &); 25 | static void serialize(const JsonArraySubscript &, Writer &); 26 | static void serialize(const JsonObject &, Writer &); 27 | template 28 | static void serialize(const JsonObjectSubscript &, Writer &); 29 | static void serialize(const JsonVariant &, Writer &); 30 | }; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Serialization/JsonSerializerImpl.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../JsonArray.hpp" 8 | #include "../JsonArraySubscript.hpp" 9 | #include "../JsonObject.hpp" 10 | #include "../JsonObjectSubscript.hpp" 11 | #include "../JsonVariant.hpp" 12 | #include "JsonSerializer.hpp" 13 | 14 | template 15 | inline void ArduinoJson::Internals::JsonSerializer::serialize( 16 | const JsonArray& array, Writer& writer) { 17 | writer.beginArray(); 18 | 19 | JsonArray::const_iterator it = array.begin(); 20 | while (it != array.end()) { 21 | serialize(*it, writer); 22 | 23 | ++it; 24 | if (it == array.end()) break; 25 | 26 | writer.writeComma(); 27 | } 28 | 29 | writer.endArray(); 30 | } 31 | 32 | template 33 | inline void ArduinoJson::Internals::JsonSerializer::serialize( 34 | const JsonArraySubscript& arraySubscript, Writer& writer) { 35 | serialize(arraySubscript.as(), writer); 36 | } 37 | 38 | template 39 | inline void ArduinoJson::Internals::JsonSerializer::serialize( 40 | const JsonObject& object, Writer& writer) { 41 | writer.beginObject(); 42 | 43 | JsonObject::const_iterator it = object.begin(); 44 | while (it != object.end()) { 45 | writer.writeString(it->key); 46 | writer.writeColon(); 47 | serialize(it->value, writer); 48 | 49 | ++it; 50 | if (it == object.end()) break; 51 | 52 | writer.writeComma(); 53 | } 54 | 55 | writer.endObject(); 56 | } 57 | 58 | template 59 | template 60 | inline void ArduinoJson::Internals::JsonSerializer::serialize( 61 | const JsonObjectSubscript& objectSubscript, Writer& writer) { 62 | serialize(objectSubscript.template as(), writer); 63 | } 64 | 65 | template 66 | inline void ArduinoJson::Internals::JsonSerializer::serialize( 67 | const JsonVariant& variant, Writer& writer) { 68 | switch (variant._type) { 69 | case JSON_FLOAT: 70 | writer.writeFloat(variant._content.asFloat); 71 | return; 72 | 73 | case JSON_ARRAY: 74 | serialize(*variant._content.asArray, writer); 75 | return; 76 | 77 | case JSON_OBJECT: 78 | serialize(*variant._content.asObject, writer); 79 | return; 80 | 81 | case JSON_STRING: 82 | writer.writeString(variant._content.asString); 83 | return; 84 | 85 | case JSON_UNPARSED: 86 | writer.writeRaw(variant._content.asString); 87 | return; 88 | 89 | case JSON_NEGATIVE_INTEGER: 90 | writer.writeRaw('-'); // Falls through. 91 | 92 | case JSON_POSITIVE_INTEGER: 93 | writer.writeInteger(variant._content.asInteger); 94 | return; 95 | 96 | case JSON_BOOLEAN: 97 | writer.writeBoolean(variant._content.asInteger != 0); 98 | return; 99 | 100 | default: // JSON_UNDEFINED 101 | return; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Serialization/JsonWriter.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include 8 | #include "../Data/Encoding.hpp" 9 | #include "../Data/JsonInteger.hpp" 10 | #include "../Polyfills/attributes.hpp" 11 | #include "../Serialization/FloatParts.hpp" 12 | 13 | namespace ArduinoJson { 14 | namespace Internals { 15 | 16 | // Writes the JSON tokens to a Print implementation 17 | // This class is used by: 18 | // - JsonArray::writeTo() 19 | // - JsonObject::writeTo() 20 | // - JsonVariant::writeTo() 21 | // Its derived by PrettyJsonWriter that overrides some members to add 22 | // indentation. 23 | template 24 | class JsonWriter { 25 | public: 26 | explicit JsonWriter(Print &sink) : _sink(sink), _length(0) {} 27 | 28 | // Returns the number of bytes sent to the Print implementation. 29 | // This is very handy for implementations of printTo() that must return the 30 | // number of bytes written. 31 | size_t bytesWritten() const { 32 | return _length; 33 | } 34 | 35 | void beginArray() { 36 | writeRaw('['); 37 | } 38 | void endArray() { 39 | writeRaw(']'); 40 | } 41 | 42 | void beginObject() { 43 | writeRaw('{'); 44 | } 45 | void endObject() { 46 | writeRaw('}'); 47 | } 48 | 49 | void writeColon() { 50 | writeRaw(':'); 51 | } 52 | void writeComma() { 53 | writeRaw(','); 54 | } 55 | 56 | void writeBoolean(bool value) { 57 | writeRaw(value ? "true" : "false"); 58 | } 59 | 60 | void writeString(const char *value) { 61 | if (!value) { 62 | writeRaw("null"); 63 | } else { 64 | writeRaw('\"'); 65 | while (*value) writeChar(*value++); 66 | writeRaw('\"'); 67 | } 68 | } 69 | 70 | void writeChar(char c) { 71 | char specialChar = Encoding::escapeChar(c); 72 | if (specialChar) { 73 | writeRaw('\\'); 74 | writeRaw(specialChar); 75 | } else { 76 | writeRaw(c); 77 | } 78 | } 79 | 80 | template 81 | void writeFloat(TFloat value) { 82 | if (isNaN(value)) return writeRaw("NaN"); 83 | 84 | if (value < 0.0) { 85 | writeRaw('-'); 86 | value = -value; 87 | } 88 | 89 | if (isInfinity(value)) return writeRaw("Infinity"); 90 | 91 | FloatParts parts(value); 92 | 93 | writeInteger(parts.integral); 94 | if (parts.decimalPlaces) writeDecimals(parts.decimal, parts.decimalPlaces); 95 | 96 | if (parts.exponent < 0) { 97 | writeRaw("e-"); 98 | writeInteger(-parts.exponent); 99 | } 100 | 101 | if (parts.exponent > 0) { 102 | writeRaw('e'); 103 | writeInteger(parts.exponent); 104 | } 105 | } 106 | 107 | template 108 | void writeInteger(UInt value) { 109 | char buffer[22]; 110 | char *end = buffer + sizeof(buffer) - 1; 111 | char *ptr = end; 112 | 113 | *ptr = 0; 114 | do { 115 | *--ptr = char(value % 10 + '0'); 116 | value = UInt(value / 10); 117 | } while (value); 118 | 119 | writeRaw(ptr); 120 | } 121 | 122 | void writeDecimals(uint32_t value, int8_t width) { 123 | // buffer should be big enough for all digits, the dot and the null 124 | // terminator 125 | char buffer[16]; 126 | char *ptr = buffer + sizeof(buffer) - 1; 127 | 128 | // write the string in reverse order 129 | *ptr = 0; 130 | while (width--) { 131 | *--ptr = char(value % 10 + '0'); 132 | value /= 10; 133 | } 134 | *--ptr = '.'; 135 | 136 | // and dump it in the right order 137 | writeRaw(ptr); 138 | } 139 | 140 | void writeRaw(const char *s) { 141 | _length += _sink.print(s); 142 | } 143 | void writeRaw(char c) { 144 | _length += _sink.print(c); 145 | } 146 | 147 | protected: 148 | Print &_sink; 149 | size_t _length; 150 | 151 | private: 152 | JsonWriter &operator=(const JsonWriter &); // cannot be assigned 153 | }; 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Serialization/Prettyfier.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "IndentedPrint.hpp" 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | 12 | // Converts a compact JSON string into an indented one. 13 | template 14 | class Prettyfier { 15 | public: 16 | explicit Prettyfier(IndentedPrint& p) : _sink(p) { 17 | _previousChar = 0; 18 | _inString = false; 19 | } 20 | 21 | size_t print(char c) { 22 | size_t n = _inString ? handleStringChar(c) : handleMarkupChar(c); 23 | _previousChar = c; 24 | return n; 25 | } 26 | 27 | size_t print(const char* s) { 28 | // TODO: optimize 29 | size_t n = 0; 30 | while (*s) n += print(*s++); 31 | return n; 32 | } 33 | 34 | private: 35 | Prettyfier& operator=(const Prettyfier&); // cannot be assigned 36 | 37 | bool inEmptyBlock() { 38 | return _previousChar == '{' || _previousChar == '['; 39 | } 40 | 41 | size_t handleStringChar(char c) { 42 | bool isQuote = c == '"' && _previousChar != '\\'; 43 | 44 | if (isQuote) _inString = false; 45 | 46 | return _sink.print(c); 47 | } 48 | 49 | size_t handleMarkupChar(char c) { 50 | switch (c) { 51 | case '{': 52 | case '[': 53 | return writeBlockOpen(c); 54 | 55 | case '}': 56 | case ']': 57 | return writeBlockClose(c); 58 | 59 | case ':': 60 | return writeColon(); 61 | 62 | case ',': 63 | return writeComma(); 64 | 65 | case '"': 66 | return writeQuoteOpen(); 67 | 68 | default: 69 | return writeNormalChar(c); 70 | } 71 | } 72 | 73 | size_t writeBlockClose(char c) { 74 | size_t n = 0; 75 | n += unindentIfNeeded(); 76 | n += _sink.print(c); 77 | return n; 78 | } 79 | 80 | size_t writeBlockOpen(char c) { 81 | size_t n = 0; 82 | n += indentIfNeeded(); 83 | n += _sink.print(c); 84 | return n; 85 | } 86 | 87 | size_t writeColon() { 88 | size_t n = 0; 89 | n += _sink.print(": "); 90 | return n; 91 | } 92 | 93 | size_t writeComma() { 94 | size_t n = 0; 95 | n += _sink.print(",\r\n"); 96 | return n; 97 | } 98 | 99 | size_t writeQuoteOpen() { 100 | _inString = true; 101 | size_t n = 0; 102 | n += indentIfNeeded(); 103 | n += _sink.print('"'); 104 | return n; 105 | } 106 | 107 | size_t writeNormalChar(char c) { 108 | size_t n = 0; 109 | n += indentIfNeeded(); 110 | n += _sink.print(c); 111 | return n; 112 | } 113 | 114 | size_t indentIfNeeded() { 115 | if (!inEmptyBlock()) return 0; 116 | 117 | _sink.indent(); 118 | return _sink.print("\r\n"); 119 | } 120 | 121 | size_t unindentIfNeeded() { 122 | if (inEmptyBlock()) return 0; 123 | 124 | _sink.unindent(); 125 | return _sink.print("\r\n"); 126 | } 127 | 128 | char _previousChar; 129 | IndentedPrint& _sink; 130 | bool _inString; 131 | }; 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Serialization/StaticStringBuilder.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // A Print implementation that allows to write in a char[] 11 | class StaticStringBuilder { 12 | public: 13 | StaticStringBuilder(char *buf, size_t size) : end(buf + size - 1), p(buf) { 14 | *p = '\0'; 15 | } 16 | 17 | size_t print(char c) { 18 | if (p >= end) return 0; 19 | *p++ = c; 20 | *p = '\0'; 21 | return 1; 22 | } 23 | 24 | size_t print(const char *s) { 25 | char *begin = p; 26 | while (p < end && *s) *p++ = *s++; 27 | *p = '\0'; 28 | return size_t(p - begin); 29 | } 30 | 31 | private: 32 | char *end; 33 | char *p; 34 | }; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/Serialization/StreamPrintAdapter.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../Configuration.hpp" 8 | 9 | #if ARDUINOJSON_ENABLE_STD_STREAM 10 | 11 | #include 12 | 13 | namespace ArduinoJson { 14 | namespace Internals { 15 | 16 | class StreamPrintAdapter { 17 | public: 18 | explicit StreamPrintAdapter(std::ostream& os) : _os(os) {} 19 | 20 | size_t print(char c) { 21 | _os << c; 22 | return 1; 23 | } 24 | 25 | size_t print(const char* s) { 26 | _os << s; 27 | return strlen(s); 28 | } 29 | 30 | private: 31 | // cannot be assigned 32 | StreamPrintAdapter& operator=(const StreamPrintAdapter&); 33 | 34 | std::ostream& _os; 35 | }; 36 | } 37 | } 38 | 39 | #endif // ARDUINOJSON_ENABLE_STD_STREAM 40 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/StaticJsonBuffer.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "JsonBufferBase.hpp" 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | 12 | class StaticJsonBufferBase : public JsonBufferBase { 13 | public: 14 | class String { 15 | public: 16 | String(StaticJsonBufferBase* parent) : _parent(parent) { 17 | _start = parent->_buffer + parent->_size; 18 | } 19 | 20 | void append(char c) { 21 | if (_parent->canAlloc(1)) { 22 | char* last = static_cast(_parent->doAlloc(1)); 23 | *last = c; 24 | } 25 | } 26 | 27 | const char* c_str() const { 28 | if (_parent->canAlloc(1)) { 29 | char* last = static_cast(_parent->doAlloc(1)); 30 | *last = '\0'; 31 | return _start; 32 | } else { 33 | return NULL; 34 | } 35 | } 36 | 37 | private: 38 | StaticJsonBufferBase* _parent; 39 | char* _start; 40 | }; 41 | 42 | StaticJsonBufferBase(char* buffer, size_t capa) 43 | : _buffer(buffer), _capacity(capa), _size(0) {} 44 | 45 | // Gets the capacity of the buffer in bytes 46 | size_t capacity() const { 47 | return _capacity; 48 | } 49 | 50 | // Gets the current usage of the buffer in bytes 51 | size_t size() const { 52 | return _size; 53 | } 54 | 55 | // Allocates the specified amount of bytes in the buffer 56 | virtual void* alloc(size_t bytes) { 57 | alignNextAlloc(); 58 | if (!canAlloc(bytes)) return NULL; 59 | return doAlloc(bytes); 60 | } 61 | 62 | // Resets the buffer. 63 | // USE WITH CAUTION: this invalidates all previously allocated data 64 | void clear() { 65 | _size = 0; 66 | } 67 | 68 | String startString() { 69 | return String(this); 70 | } 71 | 72 | protected: 73 | ~StaticJsonBufferBase() {} 74 | 75 | private: 76 | void alignNextAlloc() { 77 | _size = round_size_up(_size); 78 | } 79 | 80 | bool canAlloc(size_t bytes) const { 81 | return _size + bytes <= _capacity; 82 | } 83 | 84 | void* doAlloc(size_t bytes) { 85 | void* p = &_buffer[_size]; 86 | _size += bytes; 87 | return p; 88 | } 89 | 90 | char* _buffer; 91 | size_t _capacity; 92 | size_t _size; 93 | }; 94 | } 95 | 96 | #if defined(__clang__) 97 | #pragma clang diagnostic push 98 | #pragma clang diagnostic ignored "-Wnon-virtual-dtor" 99 | #elif defined(__GNUC__) 100 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) 101 | #pragma GCC diagnostic push 102 | #endif 103 | #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" 104 | #endif 105 | 106 | // Implements a JsonBuffer with fixed memory allocation. 107 | // The template paramenter CAPACITY specifies the capacity of the buffer in 108 | // bytes. 109 | template 110 | class StaticJsonBuffer : public Internals::StaticJsonBufferBase { 111 | public: 112 | explicit StaticJsonBuffer() 113 | : Internals::StaticJsonBufferBase(_buffer, CAPACITY) {} 114 | 115 | private: 116 | char _buffer[CAPACITY]; 117 | }; 118 | } 119 | 120 | #if defined(__clang__) 121 | #pragma clang diagnostic pop 122 | #elif defined(__GNUC__) 123 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) 124 | #pragma GCC diagnostic pop 125 | #endif 126 | #endif 127 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/StringTraits/ArduinoStream.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #if ARDUINOJSON_ENABLE_ARDUINO_STREAM 8 | 9 | #include 10 | 11 | namespace ArduinoJson { 12 | namespace Internals { 13 | 14 | struct ArduinoStreamTraits { 15 | class Reader { 16 | Stream& _stream; 17 | char _current, _next; 18 | 19 | public: 20 | Reader(Stream& stream) : _stream(stream), _current(0), _next(0) {} 21 | 22 | void move() { 23 | _current = _next; 24 | _next = 0; 25 | } 26 | 27 | char current() { 28 | if (!_current) _current = read(); 29 | return _current; 30 | } 31 | 32 | char next() { 33 | // assumes that current() has been called 34 | if (!_next) _next = read(); 35 | return _next; 36 | } 37 | 38 | private: 39 | char read() { 40 | // don't use _stream.read() as it ignores the timeout 41 | char c = 0; 42 | _stream.readBytes(&c, 1); 43 | return c; 44 | } 45 | }; 46 | 47 | static const bool has_append = false; 48 | static const bool has_equals = false; 49 | }; 50 | 51 | template 52 | struct StringTraits< 53 | TStream, 54 | // match any type that is derived from Stream: 55 | typename EnableIf< 56 | IsBaseOf::type>::value>::type> 57 | : ArduinoStreamTraits {}; 58 | } 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/StringTraits/CharPointer.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | template 11 | struct CharPointerTraits { 12 | class Reader { 13 | const TChar* _ptr; 14 | 15 | public: 16 | Reader(const TChar* ptr) 17 | : _ptr(ptr ? ptr : reinterpret_cast("")) {} 18 | 19 | void move() { 20 | ++_ptr; 21 | } 22 | 23 | char current() const { 24 | return char(_ptr[0]); 25 | } 26 | 27 | char next() const { 28 | return char(_ptr[1]); 29 | } 30 | }; 31 | 32 | static bool equals(const TChar* str, const char* expected) { 33 | const char* actual = reinterpret_cast(str); 34 | if (!actual || !expected) return actual == expected; 35 | return strcmp(actual, expected) == 0; 36 | } 37 | 38 | static bool is_null(const TChar* str) { 39 | return !str; 40 | } 41 | 42 | typedef const char* duplicate_t; 43 | 44 | template 45 | static duplicate_t duplicate(const TChar* str, Buffer* buffer) { 46 | if (!str) return NULL; 47 | size_t size = strlen(reinterpret_cast(str)) + 1; 48 | void* dup = buffer->alloc(size); 49 | if (dup != NULL) memcpy(dup, str, size); 50 | return static_cast(dup); 51 | } 52 | 53 | static const bool has_append = false; 54 | static const bool has_equals = true; 55 | static const bool should_duplicate = !IsConst::value; 56 | }; 57 | 58 | // char*, unsigned char*, signed char* 59 | // const char*, const unsigned char*, const signed char* 60 | template 61 | struct StringTraits::value>::type> 62 | : CharPointerTraits {}; 63 | } // namespace Internals 64 | } // namespace ArduinoJson 65 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/StringTraits/FlashString.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #if ARDUINOJSON_ENABLE_PROGMEM 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | template <> 12 | struct StringTraits { 13 | class Reader { 14 | const char* _ptr; 15 | 16 | public: 17 | Reader(const __FlashStringHelper* ptr) 18 | : _ptr(reinterpret_cast(ptr)) {} 19 | 20 | void move() { 21 | _ptr++; 22 | } 23 | 24 | char current() const { 25 | return pgm_read_byte_near(_ptr); 26 | } 27 | 28 | char next() const { 29 | return pgm_read_byte_near(_ptr + 1); 30 | } 31 | }; 32 | 33 | static bool equals(const __FlashStringHelper* str, const char* expected) { 34 | const char* actual = reinterpret_cast(str); 35 | if (!actual || !expected) return actual == expected; 36 | return strcmp_P(expected, actual) == 0; 37 | } 38 | 39 | static bool is_null(const __FlashStringHelper* str) { 40 | return !str; 41 | } 42 | 43 | typedef const char* duplicate_t; 44 | 45 | template 46 | static duplicate_t duplicate(const __FlashStringHelper* str, Buffer* buffer) { 47 | if (!str) return NULL; 48 | size_t size = strlen_P((const char*)str) + 1; 49 | void* dup = buffer->alloc(size); 50 | if (dup != NULL) memcpy_P(dup, (const char*)str, size); 51 | return static_cast(dup); 52 | } 53 | 54 | static const bool has_append = false; 55 | static const bool has_equals = true; 56 | static const bool should_duplicate = true; 57 | }; 58 | } // namespace Internals 59 | } // namespace ArduinoJson 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/StringTraits/StdStream.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #if ARDUINOJSON_ENABLE_STD_STREAM 8 | 9 | #include 10 | 11 | namespace ArduinoJson { 12 | namespace Internals { 13 | 14 | struct StdStreamTraits { 15 | class Reader { 16 | std::istream& _stream; 17 | char _current, _next; 18 | 19 | public: 20 | Reader(std::istream& stream) : _stream(stream), _current(0), _next(0) {} 21 | 22 | void move() { 23 | _current = _next; 24 | _next = 0; 25 | } 26 | 27 | char current() { 28 | if (!_current) _current = read(); 29 | return _current; 30 | } 31 | 32 | char next() { 33 | // assumes that current() has been called 34 | if (!_next) _next = read(); 35 | return _next; 36 | } 37 | 38 | private: 39 | Reader& operator=(const Reader&); // Visual Studio C4512 40 | 41 | char read() { 42 | return _stream.eof() ? '\0' : static_cast(_stream.get()); 43 | } 44 | }; 45 | 46 | static const bool has_append = false; 47 | static const bool has_equals = false; 48 | }; 49 | 50 | template 51 | struct StringTraits< 52 | TStream, 53 | // match any type that is derived from std::istream: 54 | typename EnableIf::type>::value>::type> 56 | : StdStreamTraits {}; 57 | } 58 | } 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/StringTraits/StdString.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #if ARDUINOJSON_ENABLE_STD_STRING || ARDUINOJSON_ENABLE_ARDUINO_STRING 8 | 9 | #if ARDUINOJSON_ENABLE_ARDUINO_STRING 10 | #include 11 | #endif 12 | 13 | #if ARDUINOJSON_ENABLE_STD_STRING 14 | #include 15 | #endif 16 | 17 | namespace ArduinoJson { 18 | namespace Internals { 19 | 20 | template 21 | struct StdStringTraits { 22 | typedef const char* duplicate_t; 23 | 24 | template 25 | static duplicate_t duplicate(const TString& str, Buffer* buffer) { 26 | if (!str.c_str()) return NULL; // <- Arduino string can return NULL 27 | size_t size = str.length() + 1; 28 | void* dup = buffer->alloc(size); 29 | if (dup != NULL) memcpy(dup, str.c_str(), size); 30 | return static_cast(dup); 31 | } 32 | 33 | static bool is_null(const TString& str) { 34 | // Arduino's String::c_str() can return NULL 35 | return !str.c_str(); 36 | } 37 | 38 | struct Reader : CharPointerTraits::Reader { 39 | Reader(const TString& str) : CharPointerTraits::Reader(str.c_str()) {} 40 | }; 41 | 42 | static bool equals(const TString& str, const char* expected) { 43 | // Arduino's String::c_str() can return NULL 44 | const char* actual = str.c_str(); 45 | if (!actual || !expected) return actual == expected; 46 | return 0 == strcmp(actual, expected); 47 | } 48 | 49 | static void append(TString& str, char c) { 50 | str += c; 51 | } 52 | 53 | static void append(TString& str, const char* s) { 54 | str += s; 55 | } 56 | 57 | static const bool has_append = true; 58 | static const bool has_equals = true; 59 | static const bool should_duplicate = true; 60 | }; 61 | 62 | #if ARDUINOJSON_ENABLE_ARDUINO_STRING 63 | template <> 64 | struct StringTraits : StdStringTraits {}; 65 | template <> 66 | struct StringTraits : StdStringTraits { 67 | }; 68 | #endif 69 | 70 | #if ARDUINOJSON_ENABLE_STD_STRING 71 | template <> 72 | struct StringTraits : StdStringTraits {}; 73 | #endif 74 | } // namespace Internals 75 | } // namespace ArduinoJson 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/StringTraits/StringTraits.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include 8 | #include "../Configuration.hpp" 9 | #include "../TypeTraits/EnableIf.hpp" 10 | #include "../TypeTraits/IsBaseOf.hpp" 11 | #include "../TypeTraits/IsChar.hpp" 12 | #include "../TypeTraits/IsConst.hpp" 13 | #include "../TypeTraits/RemoveReference.hpp" 14 | 15 | namespace ArduinoJson { 16 | namespace Internals { 17 | 18 | template 19 | struct StringTraits { 20 | static const bool has_append = false; 21 | static const bool has_equals = false; 22 | }; 23 | 24 | template 25 | struct StringTraits : StringTraits {}; 26 | 27 | template 28 | struct StringTraits : StringTraits {}; 29 | } 30 | } 31 | 32 | #include "ArduinoStream.hpp" 33 | #include "CharPointer.hpp" 34 | #include "FlashString.hpp" 35 | #include "StdStream.hpp" 36 | #include "StdString.hpp" 37 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/TypeTraits/EnableIf.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // A meta-function that return the type T if Condition is true. 11 | template 12 | struct EnableIf {}; 13 | 14 | template 15 | struct EnableIf { 16 | typedef T type; 17 | }; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/TypeTraits/FloatTraits.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include 8 | #include // for size_t 9 | #include "../Configuration.hpp" 10 | #include "../Polyfills/math.hpp" 11 | 12 | namespace ArduinoJson { 13 | namespace Internals { 14 | 15 | template 16 | struct FloatTraits {}; 17 | 18 | template 19 | struct FloatTraits { 20 | typedef int64_t mantissa_type; 21 | static const short mantissa_bits = 52; 22 | static const mantissa_type mantissa_max = 23 | (static_cast(1) << mantissa_bits) - 1; 24 | 25 | typedef int16_t exponent_type; 26 | static const exponent_type exponent_max = 308; 27 | 28 | template 29 | static T make_float(T m, TExponent e) { 30 | if (e > 0) { 31 | for (uint8_t index = 0; e != 0; index++) { 32 | if (e & 1) m *= positiveBinaryPowerOfTen(index); 33 | e >>= 1; 34 | } 35 | } else { 36 | e = TExponent(-e); 37 | for (uint8_t index = 0; e != 0; index++) { 38 | if (e & 1) m *= negativeBinaryPowerOfTen(index); 39 | e >>= 1; 40 | } 41 | } 42 | return m; 43 | } 44 | 45 | static T positiveBinaryPowerOfTen(int index) { 46 | static T factors[] = { 47 | 1e1, 1e2, 1e4, 1e8, 1e16, 1e32, 48 | // workaround to support platforms with single precision literals 49 | forge(0x4D384F03, 0xE93FF9F5), forge(0x5A827748, 0xF9301D32), 50 | forge(0x75154FDD, 0x7F73BF3C)}; 51 | return factors[index]; 52 | } 53 | 54 | static T negativeBinaryPowerOfTen(int index) { 55 | static T factors[] = { 56 | 1e-1, 1e-2, 1e-4, 1e-8, 1e-16, 1e-32, 57 | // workaround to support platforms with single precision literals 58 | forge(0x32A50FFD, 0x44F4A73D), forge(0x255BBA08, 0xCF8C979D), 59 | forge(0x0AC80628, 0x64AC6F43)}; 60 | return factors[index]; 61 | } 62 | 63 | static T negativeBinaryPowerOfTenPlusOne(int index) { 64 | static T factors[] = { 65 | 1e0, 1e-1, 1e-3, 1e-7, 1e-15, 1e-31, 66 | // workaround to support platforms with single precision literals 67 | forge(0x32DA53FC, 0x9631D10D), forge(0x25915445, 0x81B7DEC2), 68 | forge(0x0AFE07B2, 0x7DD78B14)}; 69 | return factors[index]; 70 | } 71 | 72 | static T nan() { 73 | return forge(0x7ff80000, 0x00000000); 74 | } 75 | 76 | static T inf() { 77 | return forge(0x7ff00000, 0x00000000); 78 | } 79 | 80 | static T forge(uint32_t msb, uint32_t lsb) { 81 | union { 82 | uint64_t integerBits; 83 | T floatBits; 84 | }; 85 | integerBits = (uint64_t(msb) << 32) | lsb; 86 | return floatBits; 87 | } 88 | }; 89 | 90 | template 91 | struct FloatTraits { 92 | typedef int32_t mantissa_type; 93 | static const short mantissa_bits = 23; 94 | static const mantissa_type mantissa_max = 95 | (static_cast(1) << mantissa_bits) - 1; 96 | 97 | typedef int8_t exponent_type; 98 | static const exponent_type exponent_max = 38; 99 | 100 | template 101 | static T make_float(T m, TExponent e) { 102 | if (e > 0) { 103 | for (uint8_t index = 0; e != 0; index++) { 104 | if (e & 1) m *= positiveBinaryPowerOfTen(index); 105 | e >>= 1; 106 | } 107 | } else { 108 | e = -e; 109 | for (uint8_t index = 0; e != 0; index++) { 110 | if (e & 1) m *= negativeBinaryPowerOfTen(index); 111 | e >>= 1; 112 | } 113 | } 114 | return m; 115 | } 116 | 117 | static T positiveBinaryPowerOfTen(int index) { 118 | static T factors[] = {1e1f, 1e2f, 1e4f, 1e8f, 1e16f, 1e32f}; 119 | return factors[index]; 120 | } 121 | 122 | static T negativeBinaryPowerOfTen(int index) { 123 | static T factors[] = {1e-1f, 1e-2f, 1e-4f, 1e-8f, 1e-16f, 1e-32f}; 124 | return factors[index]; 125 | } 126 | 127 | static T negativeBinaryPowerOfTenPlusOne(int index) { 128 | static T factors[] = {1e0f, 1e-1f, 1e-3f, 1e-7f, 1e-15f, 1e-31f}; 129 | return factors[index]; 130 | } 131 | 132 | static T forge(uint32_t bits) { 133 | union { 134 | uint32_t integerBits; 135 | T floatBits; 136 | }; 137 | integerBits = bits; 138 | return floatBits; 139 | } 140 | 141 | static T nan() { 142 | return forge(0x7fc00000); 143 | } 144 | 145 | static T inf() { 146 | return forge(0x7f800000); 147 | } 148 | }; 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/TypeTraits/IsArray.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // A meta-function that return the type T without the const modifier 11 | template 12 | struct IsArray { 13 | static const bool value = false; 14 | }; 15 | template 16 | struct IsArray { 17 | static const bool value = true; 18 | }; 19 | template 20 | struct IsArray { 21 | static const bool value = true; 22 | }; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/TypeTraits/IsBaseOf.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // A meta-function that returns true if Derived inherits from TBase is an 11 | // integral type. 12 | template 13 | class IsBaseOf { 14 | protected: // <- to avoid GCC's "all member functions in class are private" 15 | typedef char Yes[1]; 16 | typedef char No[2]; 17 | 18 | static Yes &probe(const TBase *); 19 | static No &probe(...); 20 | 21 | public: 22 | enum { 23 | value = sizeof(probe(reinterpret_cast(0))) == sizeof(Yes) 24 | }; 25 | }; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/TypeTraits/IsChar.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "IsSame.hpp" 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | 12 | // A meta-function that returns true if T is a charater 13 | template 14 | struct IsChar { 15 | static const bool value = IsSame::value || 16 | IsSame::value || 17 | IsSame::value; 18 | }; 19 | 20 | template 21 | struct IsChar : IsChar {}; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/TypeTraits/IsConst.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // A meta-function that return the type T without the const modifier 11 | template 12 | struct IsConst { 13 | static const bool value = false; 14 | }; 15 | 16 | template 17 | struct IsConst { 18 | static const bool value = true; 19 | }; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/TypeTraits/IsFloatingPoint.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "IsSame.hpp" 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | 12 | // A meta-function that returns true if T is a floating point type 13 | template 14 | struct IsFloatingPoint { 15 | static const bool value = IsSame::value || IsSame::value; 16 | }; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/TypeTraits/IsIntegral.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "IsSame.hpp" 8 | #include "IsSignedIntegral.hpp" 9 | #include "IsUnsignedIntegral.hpp" 10 | 11 | namespace ArduinoJson { 12 | namespace Internals { 13 | 14 | // A meta-function that returns true if T is an integral type. 15 | template 16 | struct IsIntegral { 17 | static const bool value = IsSignedIntegral::value || 18 | IsUnsignedIntegral::value || 19 | IsSame::value; 20 | // CAUTION: differs from std::is_integral as it doesn't include bool 21 | }; 22 | 23 | template 24 | struct IsIntegral : IsIntegral {}; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/TypeTraits/IsSame.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // A meta-function that returns true if types T and U are the same. 11 | template 12 | struct IsSame { 13 | static const bool value = false; 14 | }; 15 | 16 | template 17 | struct IsSame { 18 | static const bool value = true; 19 | }; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/TypeTraits/IsSignedIntegral.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../Configuration.hpp" 8 | #include "IsSame.hpp" 9 | 10 | namespace ArduinoJson { 11 | namespace Internals { 12 | 13 | // A meta-function that returns true if T is an integral type. 14 | template 15 | struct IsSignedIntegral { 16 | static const bool value = 17 | IsSame::value || IsSame::value || 18 | IsSame::value || IsSame::value || 19 | #if ARDUINOJSON_USE_LONG_LONG 20 | IsSame::value || 21 | #endif 22 | #if ARDUINOJSON_USE_INT64 23 | IsSame::value || 24 | #endif 25 | false; 26 | }; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/TypeTraits/IsUnsignedIntegral.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../Configuration.hpp" 8 | #include "IsSame.hpp" 9 | 10 | namespace ArduinoJson { 11 | namespace Internals { 12 | 13 | // A meta-function that returns true if T is an integral type. 14 | template 15 | struct IsUnsignedIntegral { 16 | static const bool value = 17 | IsSame::value || IsSame::value || 18 | IsSame::value || IsSame::value || 19 | #if ARDUINOJSON_USE_LONG_LONG 20 | IsSame::value || 21 | #endif 22 | #if ARDUINOJSON_USE_INT64 23 | IsSame::value || 24 | #endif 25 | false; 26 | }; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/TypeTraits/IsVariant.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "IsBaseOf.hpp" 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | 12 | class JsonVariantTag {}; 13 | 14 | template 15 | struct IsVariant : IsBaseOf {}; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/TypeTraits/RemoveConst.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // A meta-function that return the type T without the const modifier 11 | template 12 | struct RemoveConst { 13 | typedef T type; 14 | }; 15 | template 16 | struct RemoveConst { 17 | typedef T type; 18 | }; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/TypeTraits/RemoveReference.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // A meta-function that return the type T without the reference modifier. 11 | template 12 | struct RemoveReference { 13 | typedef T type; 14 | }; 15 | template 16 | struct RemoveReference { 17 | typedef T type; 18 | }; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/modules/ArduinoJson/ArduinoJson/version.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #define ARDUINOJSON_VERSION "5.13.2" 8 | #define ARDUINOJSON_VERSION_MAJOR 5 9 | #define ARDUINOJSON_VERSION_MINOR 13 10 | #define ARDUINOJSON_VERSION_REVISION 2 11 | -------------------------------------------------------------------------------- /src/modules/OneButton/OneButton.h: -------------------------------------------------------------------------------- 1 | // ----- 2 | // OneButton.h - Library for detecting button clicks, doubleclicks and long press pattern on a single button. 3 | // This class is implemented for use with the Arduino environment. 4 | // Copyright (c) by Matthias Hertel, http://www.mathertel.de 5 | // This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx 6 | // More information on: http://www.mathertel.de/Arduino 7 | // ----- 8 | // 02.10.2010 created by Matthias Hertel 9 | // 21.04.2011 transformed into a library 10 | // 01.12.2011 include file changed to work with the Arduino 1.0 environment 11 | // 23.03.2014 Enhanced long press functionalities by adding longPressStart and longPressStop callbacks 12 | // 21.09.2015 A simple way for debounce detection added. 13 | // 14.05.2017 Debouncing improvements. 14 | // ----- 15 | 16 | #ifndef OneButton_h 17 | #define OneButton_h 18 | 19 | #include "Arduino.h" 20 | 21 | // ----- Callback function types ----- 22 | 23 | extern "C" { 24 | typedef void (*callbackFunction)(void); 25 | } 26 | 27 | 28 | class OneButton 29 | { 30 | public: 31 | // ----- Constructor ----- 32 | OneButton(int pin, int active); 33 | 34 | OneButton() 35 | : _pin(0) 36 | {} 37 | 38 | void setButton(int pin, int active); 39 | // ----- Set runtime parameters ----- 40 | 41 | // set # millisec after safe click is assumed. 42 | void setDebounceTicks(int ticks); 43 | 44 | // set # millisec after single click is assumed. 45 | void setClickTicks(int ticks); 46 | 47 | // set # millisec after press is assumed. 48 | void setPressTicks(int ticks); 49 | 50 | // attach functions that will be called when button was pressed in the specified way. 51 | void attachClick(callbackFunction newFunction); 52 | void attachDoubleClick(callbackFunction newFunction); 53 | void attachPress(callbackFunction newFunction); // DEPRECATED, replaced by longPressStart, longPressStop and duringLongPress 54 | void attachLongPressStart(callbackFunction newFunction); 55 | void attachLongPressStop(callbackFunction newFunction); 56 | void attachDuringLongPress(callbackFunction newFunction); 57 | 58 | // ----- State machine functions ----- 59 | 60 | // call this function every some milliseconds for handling button events. 61 | void tick(void); 62 | bool isLongPressed(); 63 | 64 | private: 65 | int _pin; // hardware pin number. 66 | int _debounceTicks; // number of ticks for debounce times. 67 | int _clickTicks; // number of ticks that have to pass by before a click is detected 68 | int _pressTicks; // number of ticks that have to pass by before a long button press is detected 69 | 70 | int _buttonReleased; 71 | int _buttonPressed; 72 | 73 | bool _isLongPressed; 74 | 75 | // These variables will hold functions acting as event source. 76 | callbackFunction _clickFunc; 77 | callbackFunction _doubleClickFunc; 78 | callbackFunction _pressFunc; 79 | callbackFunction _longPressStartFunc; 80 | callbackFunction _longPressStopFunc; 81 | callbackFunction _duringLongPressFunc; 82 | 83 | // These variables that hold information across the upcoming tick calls. 84 | // They are initialized once on program start and are updated every time the tick function is called. 85 | int _state; 86 | unsigned long _startTime; // will be set in state 1 87 | unsigned long _stopTime; // will be set in state 2 88 | }; 89 | 90 | #endif 91 | 92 | 93 | -------------------------------------------------------------------------------- /src/modules/Ultrasonic.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i3water/blinker-library/b5aea5a58dc8f13a126190c9211ff70f447dbb28/src/modules/Ultrasonic.cpp -------------------------------------------------------------------------------- /src/modules/Ultrasonic.h: -------------------------------------------------------------------------------- 1 | #ifndef Ultrasonic_h 2 | #define Ultrasonic_h 3 | 4 | #if ARDUINO >= 100 5 | #include "Arduino.h" 6 | #else 7 | #include "WProgram.h" 8 | #endif 9 | 10 | class Ultrasonic 11 | { 12 | public: 13 | Ultrasonic(uint8_t TP, uint8_t EP, uint32_t TO = 30000); 14 | uint32_t cm(); 15 | uint32_t inch(); 16 | 17 | private: 18 | uint8_t Trig_pin; 19 | uint8_t Echo_pin; 20 | uint32_t Time_out; 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/modules/WebSockets/libb64/AUTHORS: -------------------------------------------------------------------------------- 1 | libb64: Base64 Encoding/Decoding Routines 2 | ====================================== 3 | 4 | Authors: 5 | ------- 6 | 7 | Chris Venter chris.venter@gmail.com http://rocketpod.blogspot.com 8 | -------------------------------------------------------------------------------- /src/modules/WebSockets/libb64/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright-Only Dedication (based on United States law) 2 | or Public Domain Certification 3 | 4 | The person or persons who have associated work with this document (the 5 | "Dedicator" or "Certifier") hereby either (a) certifies that, to the best of 6 | his knowledge, the work of authorship identified is in the public domain of the 7 | country from which the work is published, or (b) hereby dedicates whatever 8 | copyright the dedicators holds in the work of authorship identified below (the 9 | "Work") to the public domain. A certifier, moreover, dedicates any copyright 10 | interest he may have in the associated work, and for these purposes, is 11 | described as a "dedicator" below. 12 | 13 | A certifier has taken reasonable steps to verify the copyright status of this 14 | work. Certifier recognizes that his good faith efforts may not shield him from 15 | liability if in fact the work certified is not in the public domain. 16 | 17 | Dedicator makes this dedication for the benefit of the public at large and to 18 | the detriment of the Dedicator's heirs and successors. Dedicator intends this 19 | dedication to be an overt act of relinquishment in perpetuity of all present 20 | and future rights under copyright law, whether vested or contingent, in the 21 | Work. Dedicator understands that such relinquishment of all rights includes 22 | the relinquishment of all rights to enforce (by lawsuit or otherwise) those 23 | copyrights in the Work. 24 | 25 | Dedicator recognizes that, once placed in the public domain, the Work may be 26 | freely reproduced, distributed, transmitted, used, modified, built upon, or 27 | otherwise exploited by anyone for any purpose, commercial or non-commercial, 28 | and in any way, including by methods that have not yet been invented or 29 | conceived. -------------------------------------------------------------------------------- /src/modules/WebSockets/libb64/cdecode.c: -------------------------------------------------------------------------------- 1 | /* 2 | cdecoder.c - c source to a base64 decoding algorithm implementation 3 | 4 | This is part of the libb64 project, and has been placed in the public domain. 5 | For details, see http://sourceforge.net/projects/libb64 6 | */ 7 | 8 | #ifdef ESP8266 9 | #include 10 | #endif 11 | 12 | #if defined(ESP32) 13 | #define CORE_HAS_LIBB64 14 | #endif 15 | 16 | #ifndef CORE_HAS_LIBB64 17 | #include "cdecode_inc.h" 18 | 19 | int base64_decode_value(char value_in) 20 | { 21 | static const char decoding[] = {62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-2,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51}; 22 | static const char decoding_size = sizeof(decoding); 23 | value_in -= 43; 24 | if (value_in < 0 || value_in > decoding_size) return -1; 25 | return decoding[(int)value_in]; 26 | } 27 | 28 | void base64_init_decodestate(base64_decodestate* state_in) 29 | { 30 | state_in->step = step_a; 31 | state_in->plainchar = 0; 32 | } 33 | 34 | int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in) 35 | { 36 | const char* codechar = code_in; 37 | char* plainchar = plaintext_out; 38 | char fragment; 39 | 40 | *plainchar = state_in->plainchar; 41 | 42 | switch (state_in->step) 43 | { 44 | while (1) 45 | { 46 | case step_a: 47 | do { 48 | if (codechar == code_in+length_in) 49 | { 50 | state_in->step = step_a; 51 | state_in->plainchar = *plainchar; 52 | return plainchar - plaintext_out; 53 | } 54 | fragment = (char)base64_decode_value(*codechar++); 55 | } while (fragment < 0); 56 | *plainchar = (fragment & 0x03f) << 2; 57 | case step_b: 58 | do { 59 | if (codechar == code_in+length_in) 60 | { 61 | state_in->step = step_b; 62 | state_in->plainchar = *plainchar; 63 | return plainchar - plaintext_out; 64 | } 65 | fragment = (char)base64_decode_value(*codechar++); 66 | } while (fragment < 0); 67 | *plainchar++ |= (fragment & 0x030) >> 4; 68 | *plainchar = (fragment & 0x00f) << 4; 69 | case step_c: 70 | do { 71 | if (codechar == code_in+length_in) 72 | { 73 | state_in->step = step_c; 74 | state_in->plainchar = *plainchar; 75 | return plainchar - plaintext_out; 76 | } 77 | fragment = (char)base64_decode_value(*codechar++); 78 | } while (fragment < 0); 79 | *plainchar++ |= (fragment & 0x03c) >> 2; 80 | *plainchar = (fragment & 0x003) << 6; 81 | case step_d: 82 | do { 83 | if (codechar == code_in+length_in) 84 | { 85 | state_in->step = step_d; 86 | state_in->plainchar = *plainchar; 87 | return plainchar - plaintext_out; 88 | } 89 | fragment = (char)base64_decode_value(*codechar++); 90 | } while (fragment < 0); 91 | *plainchar++ |= (fragment & 0x03f); 92 | } 93 | } 94 | /* control should not reach here */ 95 | return plainchar - plaintext_out; 96 | } 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /src/modules/WebSockets/libb64/cdecode_inc.h: -------------------------------------------------------------------------------- 1 | /* 2 | cdecode.h - c header for a base64 decoding algorithm 3 | 4 | This is part of the libb64 project, and has been placed in the public domain. 5 | For details, see http://sourceforge.net/projects/libb64 6 | */ 7 | 8 | #ifndef BASE64_CDECODE_H 9 | #define BASE64_CDECODE_H 10 | 11 | typedef enum 12 | { 13 | step_a, step_b, step_c, step_d 14 | } base64_decodestep; 15 | 16 | typedef struct 17 | { 18 | base64_decodestep step; 19 | char plainchar; 20 | } base64_decodestate; 21 | 22 | void base64_init_decodestate(base64_decodestate* state_in); 23 | 24 | int base64_decode_value(char value_in); 25 | 26 | int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in); 27 | 28 | #endif /* BASE64_CDECODE_H */ 29 | -------------------------------------------------------------------------------- /src/modules/WebSockets/libb64/cencode.c: -------------------------------------------------------------------------------- 1 | /* 2 | cencoder.c - c source to a base64 encoding algorithm implementation 3 | 4 | This is part of the libb64 project, and has been placed in the public domain. 5 | For details, see http://sourceforge.net/projects/libb64 6 | */ 7 | 8 | #ifdef ESP8266 9 | #include 10 | #endif 11 | 12 | #if defined(ESP32) 13 | #define CORE_HAS_LIBB64 14 | #endif 15 | 16 | #ifndef CORE_HAS_LIBB64 17 | #include "cencode_inc.h" 18 | 19 | const int CHARS_PER_LINE = 72; 20 | 21 | void base64_init_encodestate(base64_encodestate* state_in) 22 | { 23 | state_in->step = step_A; 24 | state_in->result = 0; 25 | state_in->stepcount = 0; 26 | } 27 | 28 | char base64_encode_value(char value_in) 29 | { 30 | static const char* encoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 31 | if (value_in > 63) return '='; 32 | return encoding[(int)value_in]; 33 | } 34 | 35 | int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in) 36 | { 37 | const char* plainchar = plaintext_in; 38 | const char* const plaintextend = plaintext_in + length_in; 39 | char* codechar = code_out; 40 | char result; 41 | char fragment; 42 | 43 | result = state_in->result; 44 | 45 | switch (state_in->step) 46 | { 47 | while (1) 48 | { 49 | case step_A: 50 | if (plainchar == plaintextend) 51 | { 52 | state_in->result = result; 53 | state_in->step = step_A; 54 | return codechar - code_out; 55 | } 56 | fragment = *plainchar++; 57 | result = (fragment & 0x0fc) >> 2; 58 | *codechar++ = base64_encode_value(result); 59 | result = (fragment & 0x003) << 4; 60 | case step_B: 61 | if (plainchar == plaintextend) 62 | { 63 | state_in->result = result; 64 | state_in->step = step_B; 65 | return codechar - code_out; 66 | } 67 | fragment = *plainchar++; 68 | result |= (fragment & 0x0f0) >> 4; 69 | *codechar++ = base64_encode_value(result); 70 | result = (fragment & 0x00f) << 2; 71 | case step_C: 72 | if (plainchar == plaintextend) 73 | { 74 | state_in->result = result; 75 | state_in->step = step_C; 76 | return codechar - code_out; 77 | } 78 | fragment = *plainchar++; 79 | result |= (fragment & 0x0c0) >> 6; 80 | *codechar++ = base64_encode_value(result); 81 | result = (fragment & 0x03f) >> 0; 82 | *codechar++ = base64_encode_value(result); 83 | 84 | ++(state_in->stepcount); 85 | if (state_in->stepcount == CHARS_PER_LINE/4) 86 | { 87 | *codechar++ = '\n'; 88 | state_in->stepcount = 0; 89 | } 90 | } 91 | } 92 | /* control should not reach here */ 93 | return codechar - code_out; 94 | } 95 | 96 | int base64_encode_blockend(char* code_out, base64_encodestate* state_in) 97 | { 98 | char* codechar = code_out; 99 | 100 | switch (state_in->step) 101 | { 102 | case step_B: 103 | *codechar++ = base64_encode_value(state_in->result); 104 | *codechar++ = '='; 105 | *codechar++ = '='; 106 | break; 107 | case step_C: 108 | *codechar++ = base64_encode_value(state_in->result); 109 | *codechar++ = '='; 110 | break; 111 | case step_A: 112 | break; 113 | } 114 | *codechar++ = 0x00; 115 | 116 | return codechar - code_out; 117 | } 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /src/modules/WebSockets/libb64/cencode_inc.h: -------------------------------------------------------------------------------- 1 | /* 2 | cencode.h - c header for a base64 encoding algorithm 3 | 4 | This is part of the libb64 project, and has been placed in the public domain. 5 | For details, see http://sourceforge.net/projects/libb64 6 | */ 7 | 8 | #ifndef BASE64_CENCODE_H 9 | #define BASE64_CENCODE_H 10 | 11 | typedef enum 12 | { 13 | step_A, step_B, step_C 14 | } base64_encodestep; 15 | 16 | typedef struct 17 | { 18 | base64_encodestep step; 19 | char result; 20 | int stepcount; 21 | } base64_encodestate; 22 | 23 | void base64_init_encodestate(base64_encodestate* state_in); 24 | 25 | char base64_encode_value(char value_in); 26 | 27 | int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in); 28 | 29 | int base64_encode_blockend(char* code_out, base64_encodestate* state_in); 30 | 31 | #endif /* BASE64_CENCODE_H */ 32 | -------------------------------------------------------------------------------- /src/modules/WebSockets/libsha1/libsha1.h: -------------------------------------------------------------------------------- 1 | /* ================ sha1.h ================ */ 2 | /* 3 | SHA-1 in C 4 | By Steve Reid 5 | 100% Public Domain 6 | */ 7 | 8 | #if !defined(ESP8266) && !defined(ESP32) 9 | 10 | typedef struct { 11 | uint32_t state[5]; 12 | uint32_t count[2]; 13 | unsigned char buffer[64]; 14 | } SHA1_CTX; 15 | 16 | void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]); 17 | void SHA1Init(SHA1_CTX* context); 18 | void SHA1Update(SHA1_CTX* context, const unsigned char* data, uint32_t len); 19 | void SHA1Final(unsigned char digest[20], SHA1_CTX* context); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/modules/dht/DHT.h: -------------------------------------------------------------------------------- 1 | /* DHT library 2 | 3 | MIT license 4 | written by Adafruit Industries 5 | */ 6 | #ifndef DHT_H 7 | #define DHT_H 8 | 9 | #if ARDUINO >= 100 10 | #include "Arduino.h" 11 | #else 12 | #include "WProgram.h" 13 | #endif 14 | 15 | 16 | // Uncomment to enable printing out nice debug messages. 17 | //#define DHT_DEBUG 18 | 19 | // Define where debug output will be printed. 20 | #define DEBUG_PRINTER Serial 21 | 22 | // Setup debug printing macros. 23 | #ifdef DHT_DEBUG 24 | #define DEBUG_PRINT(...) { DEBUG_PRINTER.print(__VA_ARGS__); } 25 | #define DEBUG_PRINTLN(...) { DEBUG_PRINTER.println(__VA_ARGS__); } 26 | #else 27 | #define DEBUG_PRINT(...) {} 28 | #define DEBUG_PRINTLN(...) {} 29 | #endif 30 | 31 | // Define types of sensors. 32 | #define DHT11 11 33 | #define DHT22 22 34 | #define DHT21 21 35 | #define AM2301 21 36 | 37 | 38 | class DHT { 39 | public: 40 | DHT(uint8_t pin, uint8_t type, uint8_t count=6); 41 | void begin(void); 42 | float readTemperature(bool S=false, bool force=false); 43 | float convertCtoF(float); 44 | float convertFtoC(float); 45 | float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=true); 46 | float readHumidity(bool force=false); 47 | boolean read(bool force=false); 48 | 49 | private: 50 | uint8_t data[5]; 51 | uint8_t _pin, _type; 52 | #ifdef __AVR 53 | // Use direct GPIO access on an 8-bit AVR so keep track of the port and bitmask 54 | // for the digital pin connected to the DHT. Other platforms will use digitalRead. 55 | uint8_t _bit, _port; 56 | #endif 57 | uint32_t _lastreadtime, _maxcycles; 58 | bool _lastresult; 59 | 60 | uint32_t expectPulse(bool level); 61 | 62 | }; 63 | 64 | class InterruptLock { 65 | public: 66 | InterruptLock() { 67 | noInterrupts(); 68 | } 69 | ~InterruptLock() { 70 | interrupts(); 71 | } 72 | 73 | }; 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /src/modules/mqtt/Adafruit_MQTT_Client.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Adafruit Industries 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 | #include "Adafruit_MQTT_Client.h" 23 | 24 | 25 | bool Adafruit_MQTT_Client::connectServer() { 26 | // Grab server name from flash and copy to buffer for name resolution. 27 | memset(buffer, 0, sizeof(buffer)); 28 | strcpy((char *)buffer, servername); 29 | DEBUG_PRINT(F("Connecting to: ")); DEBUG_PRINTLN((char *)buffer); 30 | // Connect and check for success (0 result). 31 | int r = client->connect((char *)buffer, portnum); 32 | DEBUG_PRINT(F("Connect result: ")); DEBUG_PRINTLN(r); 33 | return r != 0; 34 | } 35 | 36 | bool Adafruit_MQTT_Client::disconnectServer() { 37 | // Stop connection if connected and return success (stop has no indication of 38 | // failure). 39 | if (client->connected()) { 40 | client->stop(); 41 | } 42 | return true; 43 | } 44 | 45 | bool Adafruit_MQTT_Client::connected() { 46 | // Return true if connected, false if not connected. 47 | return client->connected(); 48 | } 49 | 50 | uint16_t Adafruit_MQTT_Client::readPacket(uint8_t *buffer, uint16_t maxlen, 51 | int16_t timeout) { 52 | /* Read data until either the connection is closed, or the idle timeout is reached. */ 53 | uint16_t len = 0; 54 | int16_t t = timeout; 55 | 56 | while (client->connected() && (timeout >= 0)) { 57 | //DEBUG_PRINT('.'); 58 | while (client->available()) { 59 | //DEBUG_PRINT('!'); 60 | char c = client->read(); 61 | timeout = t; // reset the timeout 62 | buffer[len] = c; 63 | //DEBUG_PRINTLN((uint8_t)c, HEX); 64 | len++; 65 | if (len == maxlen) { // we read all we want, bail 66 | DEBUG_PRINT(F("Read data:\t")); 67 | DEBUG_PRINTBUFFER(buffer, len); 68 | return len; 69 | } 70 | } 71 | timeout -= MQTT_CLIENT_READINTERVAL_MS; 72 | delay(MQTT_CLIENT_READINTERVAL_MS); 73 | } 74 | return len; 75 | } 76 | 77 | bool Adafruit_MQTT_Client::sendPacket(uint8_t *buffer, uint16_t len) { 78 | uint16_t ret = 0; 79 | 80 | while (len > 0) { 81 | if (client->connected()) { 82 | // send 250 bytes at most at a time, can adjust this later based on Client 83 | 84 | uint16_t sendlen = min(len, (uint16_t)2500); 85 | 86 | ret = client->write(buffer, sendlen); 87 | DEBUG_PRINT(F("Client sendPacket returned: ")); DEBUG_PRINTLN(ret); 88 | DEBUG_PRINT(F("Client sendPacket sendlen: ")); DEBUG_PRINTLN(sendlen); 89 | DEBUG_PRINT(F("Client sendPacket len: ")); DEBUG_PRINTLN(len); 90 | len -= ret; 91 | 92 | if (ret != sendlen) { 93 | DEBUG_PRINTLN("Failed to send packet."); 94 | return false; 95 | } 96 | } else { 97 | DEBUG_PRINTLN(F("Connection failed!")); 98 | return false; 99 | } 100 | } 101 | return true; 102 | } 103 | -------------------------------------------------------------------------------- /src/modules/mqtt/Adafruit_MQTT_Client.h: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Adafruit Industries 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 | #ifndef _ADAFRUIT_MQTT_CLIENT_H_ 23 | #define _ADAFRUIT_MQTT_CLIENT_H_ 24 | 25 | #include "Client.h" 26 | #include "Adafruit_MQTT.h" 27 | 28 | 29 | // How long to delay waiting for new data to be available in readPacket. 30 | #define MQTT_CLIENT_READINTERVAL_MS 10 31 | 32 | 33 | // MQTT client implementation for a generic Arduino Client interface. Can work 34 | // with almost all Arduino network hardware like ethernet shield, wifi shield, 35 | // and even other platforms like ESP8266. 36 | class Adafruit_MQTT_Client : public Adafruit_MQTT { 37 | public: 38 | Adafruit_MQTT_Client(Client *client, const char *server, uint16_t port, 39 | const char *cid, const char *user, const char *pass): 40 | Adafruit_MQTT(server, port, cid, user, pass), 41 | client(client) 42 | {} 43 | 44 | Adafruit_MQTT_Client(Client *client, const char *server, uint16_t port, 45 | const char *user="", const char *pass=""): 46 | Adafruit_MQTT(server, port, user, pass), 47 | client(client) 48 | {} 49 | 50 | bool connectServer(); 51 | bool disconnectServer(); 52 | bool connected(); 53 | uint16_t readPacket(uint8_t *buffer, uint16_t maxlen, int16_t timeout); 54 | bool sendPacket(uint8_t *buffer, uint16_t len); 55 | 56 | private: 57 | Client* client; 58 | }; 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /src/modules/mqtt/Adafruit_MQTT_FONA.h: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Adafruit Industries 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 | #ifndef _ADAFRUIT_MQTT_FONA_H_ 23 | #define _ADAFRUIT_MQTT_FONA_H_ 24 | 25 | #include 26 | #include "Adafruit_MQTT.h" 27 | 28 | #define MQTT_FONA_INTERAVAILDELAY 100 29 | #define MQTT_FONA_QUERYDELAY 500 30 | 31 | 32 | // FONA-specific version of the Adafruit_MQTT class. 33 | // Note that this is defined as a header-only class to prevent issues with using 34 | // the library on non-FONA platforms (since Arduino will include all .cpp files 35 | // in the compilation of the library). 36 | class Adafruit_MQTT_FONA : public Adafruit_MQTT { 37 | public: 38 | Adafruit_MQTT_FONA(Adafruit_FONA *f, const char *server, uint16_t port, 39 | const char *cid, const char *user, const char *pass): 40 | Adafruit_MQTT(server, port, cid, user, pass), 41 | fona(f) 42 | {} 43 | 44 | Adafruit_MQTT_FONA(Adafruit_FONA *f, const char *server, uint16_t port, 45 | const char *user="", const char *pass=""): 46 | Adafruit_MQTT(server, port, user, pass), 47 | fona(f) 48 | {} 49 | 50 | bool connectServer() { 51 | char server[40]; 52 | strncpy(server, servername, 40); 53 | #ifdef ADAFRUIT_SLEEPYDOG_H 54 | Watchdog.reset(); 55 | #endif 56 | 57 | // connect to server 58 | DEBUG_PRINTLN(F("Connecting to TCP")); 59 | return fona->TCPconnect(server, portnum); 60 | } 61 | 62 | bool disconnectServer() { 63 | return fona->TCPclose(); 64 | } 65 | 66 | bool connected() { 67 | // Return true if connected, false if not connected. 68 | return fona->TCPconnected(); 69 | } 70 | 71 | uint16_t readPacket(uint8_t *buffer, uint16_t maxlen, int16_t timeout) { 72 | uint8_t *buffp = buffer; 73 | DEBUG_PRINTLN(F("Reading data..")); 74 | 75 | if (!fona->TCPconnected()) return 0; 76 | 77 | 78 | /* Read data until either the connection is closed, or the idle timeout is reached. */ 79 | uint16_t len = 0; 80 | int16_t t = timeout; 81 | uint16_t avail; 82 | 83 | while (fona->TCPconnected() && (timeout >= 0)) { 84 | //DEBUG_PRINT('.'); 85 | while (avail = fona->TCPavailable()) { 86 | //DEBUG_PRINT('!'); 87 | 88 | if (len + avail > maxlen) { 89 | avail = maxlen - len; 90 | if (avail == 0) return len; 91 | } 92 | 93 | // try to read the data into the end of the pointer 94 | if (! fona->TCPread(buffp, avail)) return len; 95 | 96 | // read it! advance pointer 97 | buffp += avail; 98 | len += avail; 99 | timeout = t; // reset the timeout 100 | 101 | //DEBUG_PRINTLN((uint8_t)c, HEX); 102 | 103 | if (len == maxlen) { // we read all we want, bail 104 | DEBUG_PRINT(F("Read:\t")); 105 | DEBUG_PRINTBUFFER(buffer, len); 106 | return len; 107 | } 108 | } 109 | #ifdef ADAFRUIT_SLEEPYDOG_H 110 | Watchdog.reset(); 111 | #endif 112 | timeout -= MQTT_FONA_INTERAVAILDELAY; 113 | timeout -= MQTT_FONA_QUERYDELAY; // this is how long it takes to query the FONA for avail() 114 | delay(MQTT_FONA_INTERAVAILDELAY); 115 | } 116 | 117 | return len; 118 | } 119 | 120 | bool sendPacket(uint8_t *buffer, uint16_t len) { 121 | DEBUG_PRINTLN(F("Writing packet")); 122 | if (fona->TCPconnected()) { 123 | bool ret = fona->TCPsend((char *)buffer, len); 124 | //DEBUG_PRINT(F("sendPacket returned: ")); DEBUG_PRINTLN(ret); 125 | if (!ret) { 126 | DEBUG_PRINTLN("Failed to send packet."); 127 | return false; 128 | } 129 | } else { 130 | DEBUG_PRINTLN(F("Connection failed!")); 131 | return false; 132 | } 133 | return true; 134 | } 135 | 136 | private: 137 | uint32_t serverip; 138 | Adafruit_FONA *fona; 139 | }; 140 | 141 | 142 | #endif 143 | -------------------------------------------------------------------------------- /src/utility/BlinkerDebug.h: -------------------------------------------------------------------------------- 1 | #ifndef BlinkerDebug_H 2 | #define BlinkerDebug_H 3 | 4 | #include 5 | #ifdef ESP8266 6 | extern "C" { 7 | #include "ets_sys.h" 8 | #include "os_type.h" 9 | #include "mem.h" 10 | } 11 | #include 12 | #else 13 | #include 14 | #endif 15 | 16 | #if defined(ARDUINO) 17 | #if ARDUINO >= 100 18 | #include 19 | #else 20 | #include 21 | #endif 22 | 23 | #if (defined(__AVR__)) 24 | #include 25 | #elif defined(ESP8266) || defined(ESP32) 26 | #include 27 | #endif 28 | 29 | #define BLINKER_F(s) F(s) 30 | #define BLINKER_PSTR(s) PSTR(s) 31 | #else 32 | #define BLINKER_F(s) s 33 | #define BLINKER_PSTR(s) s 34 | #endif 35 | 36 | #if defined(ARDUINO) && defined(ESP8266) 37 | static uint32_t BLINKER_FreeHeap() 38 | { 39 | return ESP.getFreeHeap(); 40 | } 41 | #elif defined(ARDUINO) && defined(ESP32) 42 | static uint32_t BLINKER_FreeHeap() 43 | { 44 | return ESP.getFreeHeap(); 45 | } 46 | #elif defined(ARDUINO) && defined(__AVR__) 47 | static uint32_t BLINKER_FreeHeap() 48 | { 49 | extern int __heap_start, *__brkval; 50 | int v; 51 | return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 52 | } 53 | #else 54 | static uint32_t BLINKER_FreeHeap() 55 | { 56 | return 0; 57 | } 58 | #endif 59 | 60 | #ifndef BLINKER_PRINT 61 | #undef BLINKER_DEBUG 62 | #undef BLINKER_DEBUG_ALL 63 | #endif 64 | 65 | #if defined(BLINKER_PRINT) 66 | #define BLINKER_LOG_FreeHeap() { BLINKER_LOG_TIME(); BLINKER_PRINT.print(("Freeheap: ")); BLINKER_PRINT.println(BLINKER_FreeHeap());} 67 | #define BLINKER_LOG1(p1) { BLINKER_LOG_TIME(); BLINKER_PRINT.println(p1); } 68 | #define BLINKER_LOG2(p1, p2) { BLINKER_LOG_TIME(); BLINKER_PRINT.print(p1); BLINKER_PRINT.println(p2); } 69 | #define BLINKER_LOG3(p1, p2, p3) { BLINKER_LOG_TIME(); BLINKER_PRINT.print(p1); BLINKER_PRINT.print(p2); BLINKER_PRINT.println(p3); } 70 | #define BLINKER_LOG4(p1, p2, p3, p4) { BLINKER_LOG_TIME(); BLINKER_PRINT.print(p1); BLINKER_PRINT.print(p2); BLINKER_PRINT.print(p3); BLINKER_PRINT.println(p4); } 71 | #define BLINKER_LOG5(p1, p2, p3, p4, p5) { BLINKER_LOG_TIME(); BLINKER_PRINT.print(p1); BLINKER_PRINT.print(p2); BLINKER_PRINT.print(p3); BLINKER_PRINT.print(p4); BLINKER_PRINT.println(p5); } 72 | #define BLINKER_LOG6(p1, p2, p3, p4, p5, p6) { BLINKER_LOG_TIME(); BLINKER_PRINT.print(p1); BLINKER_PRINT.print(p2); BLINKER_PRINT.print(p3); BLINKER_PRINT.print(p4); BLINKER_PRINT.print(p5); BLINKER_PRINT.println(p6); } 73 | #define BLINKER_ERR_LOG1(p1) { BLINKER_LOG_TIME(); BLINKER_PRINT.print(("ERROR: ")); BLINKER_PRINT.println(p1); } 74 | #define BLINKER_ERR_LOG2(p1, p2) { BLINKER_LOG_TIME(); BLINKER_PRINT.print(("ERROR: ")); BLINKER_PRINT.print(p1); BLINKER_PRINT.println(p2); } 75 | #define BLINKER_ERR_LOG3(p1, p2, p3) { BLINKER_LOG_TIME(); BLINKER_PRINT.print(("ERROR: ")); BLINKER_PRINT.print(p1); BLINKER_PRINT.print(p2); BLINKER_PRINT.println(p3); } 76 | #define BLINKER_ERR_LOG4(p1, p2, p3, p4) { BLINKER_LOG_TIME(); BLINKER_PRINT.print(("ERROR: ")); BLINKER_PRINT.print(p1); BLINKER_PRINT.print(p2); BLINKER_PRINT.print(p3); BLINKER_PRINT.println(p4); } 77 | #define BLINKER_ERR_LOG5(p1, p2, p3, p4, p5) { BLINKER_LOG_TIME(); BLINKER_PRINT.print(("ERROR: ")); BLINKER_PRINT.print(p1); BLINKER_PRINT.print(p2); BLINKER_PRINT.print(p3); BLINKER_PRINT.print(p4); BLINKER_PRINT.println(p5); } 78 | #define BLINKER_ERR_LOG6(p1, p2, p3, p4, p5, p6){ BLINKER_LOG_TIME(); BLINKER_PRINT.print(("ERROR: ")); BLINKER_PRINT.print(p1); BLINKER_PRINT.print(p2); BLINKER_PRINT.print(p3); BLINKER_PRINT.print(p4); BLINKER_PRINT.print(p5); BLINKER_PRINT.println(p6); } 79 | 80 | static void BLINKER_LOG_TIME() { 81 | BLINKER_PRINT.print("["); 82 | BLINKER_PRINT.print(millis()); 83 | BLINKER_PRINT.print("] "); 84 | } 85 | #else 86 | #define BLINKER_LOG_FreeHeap() 87 | #define BLINKER_LOG1(p1) 88 | #define BLINKER_LOG2(p1, p2) 89 | #define BLINKER_LOG3(p1, p2, p3) 90 | #define BLINKER_LOG4(p1, p2, p3, p4) 91 | #define BLINKER_LOG5(p1, p2, p3, p4, p5) 92 | #define BLINKER_LOG6(p1, p2, p3, p4, p5, p6) 93 | #define BLINKER_ERR_LOG1(p1) 94 | #define BLINKER_ERR_LOG2(p1, p2) 95 | #define BLINKER_ERR_LOG3(p1, p2, p3) 96 | #define BLINKER_ERR_LOG4(p1, p2, p3, p4) 97 | #define BLINKER_ERR_LOG5(p1, p2, p3, p4, p5) 98 | #define BLINKER_ERR_LOG6(p1, p2, p3, p4, p5, p6) 99 | #endif 100 | 101 | #endif --------------------------------------------------------------------------------