├── RadioHead.zip ├── examples ├── WEMOS │ └── Garage │ │ └── thing │ │ ├── cpu.jpg │ │ ├── dht.jpg │ │ ├── relay.jpg │ │ ├── triple.jpg │ │ ├── view1.JPG │ │ ├── view2.JPG │ │ ├── view3.JPG │ │ ├── esp8266-wemos-d1-mini-pinout.png │ │ ├── thing_led.h │ │ ├── thing_relay_door.h │ │ ├── README.md │ │ ├── thing_dht.h │ │ ├── iot_get_send.html │ │ ├── thing_relay_fan.h │ │ └── thing.ino ├── ESP8266-01 │ ├── 1CH_RELAY │ │ └── thing │ │ │ ├── TYWE2S_1.jpg │ │ │ ├── TYWE2S_2.jpg │ │ │ ├── TYWE2S_3.jpg │ │ │ ├── TYWE2S_4.jpg │ │ │ ├── TYWE2S_5.jpg │ │ │ ├── How_To_Siri.pdf │ │ │ ├── Sonoff_ESP8266.jpg │ │ │ ├── Sonoff_ESP8266_PCB.jpg │ │ │ ├── Sonoff_Dual_ESP8266.jpg │ │ │ ├── Sonoff_ESP8266_S26_1.jpg │ │ │ ├── Sonoff_ESP8266_S26_2.jpg │ │ │ ├── Sonoff_ESP8266_S26_3.jpg │ │ │ ├── Sonoff_ESP8266_S26_4.jpg │ │ │ ├── Sonoff_ESP8266_S26_5.jpg │ │ │ ├── Sonoff_ESP8266_S26_6.jpg │ │ │ ├── Sonoff_ESP8266_S26_7.jpg │ │ │ ├── Sonoff_ESP8266_S26_8.jpg │ │ │ ├── Sonoff_ESP8266_S26_9.jpg │ │ │ ├── Sonoff_ESP8266_CH340G_1.jpg │ │ │ ├── Sonoff_ESP8266_CH340G_2.jpg │ │ │ ├── Sonoff_ESP8266_S26_10.jpg │ │ │ ├── Sonoff_ESP8266_S26_11.jpg │ │ │ ├── Sonoff_ESP8266_S26_12.jpg │ │ │ ├── Sonoff_ESP8266_S26_13.jpg │ │ │ ├── Sonoff_Socket_ESP8266.jpg │ │ │ ├── Sonoff_ESP8266_Slampher_1.jpg │ │ │ ├── iot_get_send.html │ │ │ ├── thing.ino │ │ │ ├── iot_get.html │ │ │ └── README.md │ └── 1CH_RELAY_RESTART │ │ └── thing │ │ ├── README.md │ │ ├── iot_get.html │ │ └── thing.ino ├── Feather32u4 │ ├── SmartRoom │ │ └── thing │ │ │ ├── favicon_so.png │ │ │ ├── i_120_120_so.png │ │ │ ├── i_152_152_so.png │ │ │ ├── i_167_167_so.png │ │ │ ├── i_180_180_so.png │ │ │ ├── thing_light.h │ │ │ ├── thing_timestamp.h │ │ │ ├── thing_door.h │ │ │ ├── thing_door_lock.h │ │ │ ├── thing_dht.h │ │ │ ├── thing_door_sensor.h │ │ │ └── thing.ino │ ├── DHT22 │ │ └── thing │ │ │ ├── thing_dht.h │ │ │ ├── thing.ino │ │ │ └── read_temp_hum.html │ ├── Simple │ │ └── thing │ │ │ ├── thing.ino │ │ │ └── iot_get.html │ ├── SendAndReceive │ │ └── thing │ │ │ ├── thing.ino │ │ │ └── iot_get_send.html │ └── Tester │ │ └── thing │ │ ├── iot_get.html │ │ └── thing.ino ├── ESP32 │ ├── TTGO │ │ ├── Simple │ │ │ └── thing │ │ │ │ ├── thing.ino │ │ │ │ └── iot_get.html │ │ └── SendAndReceive │ │ │ └── thing │ │ │ ├── thing.ino │ │ │ └── iot_get_send.html │ ├── HELTEC │ │ ├── Simple │ │ │ └── thing │ │ │ │ ├── thing.ino │ │ │ │ └── iot_get.html │ │ └── SendAndReceive │ │ │ └── thing │ │ │ ├── thing.ino │ │ │ └── iot_get_send.html │ └── ULP │ │ ├── LoRA │ │ └── thing │ │ │ └── iot_get.html │ │ └── WiFi │ │ └── thing │ │ └── iot_get.html └── README.md ├── wifi_api └── thing │ ├── thing.ino │ └── iot_get_send.html └── gprs_api └── thing ├── thing.ino ├── iot_send.html ├── iot_get_send.html └── IoTSim800l.h /RadioHead.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/RadioHead.zip -------------------------------------------------------------------------------- /examples/WEMOS/Garage/thing/cpu.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/WEMOS/Garage/thing/cpu.jpg -------------------------------------------------------------------------------- /examples/WEMOS/Garage/thing/dht.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/WEMOS/Garage/thing/dht.jpg -------------------------------------------------------------------------------- /examples/WEMOS/Garage/thing/relay.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/WEMOS/Garage/thing/relay.jpg -------------------------------------------------------------------------------- /examples/WEMOS/Garage/thing/triple.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/WEMOS/Garage/thing/triple.jpg -------------------------------------------------------------------------------- /examples/WEMOS/Garage/thing/view1.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/WEMOS/Garage/thing/view1.JPG -------------------------------------------------------------------------------- /examples/WEMOS/Garage/thing/view2.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/WEMOS/Garage/thing/view2.JPG -------------------------------------------------------------------------------- /examples/WEMOS/Garage/thing/view3.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/WEMOS/Garage/thing/view3.JPG -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/TYWE2S_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/TYWE2S_1.jpg -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/TYWE2S_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/TYWE2S_2.jpg -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/TYWE2S_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/TYWE2S_3.jpg -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/TYWE2S_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/TYWE2S_4.jpg -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/TYWE2S_5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/TYWE2S_5.jpg -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/How_To_Siri.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/How_To_Siri.pdf -------------------------------------------------------------------------------- /examples/Feather32u4/SmartRoom/thing/favicon_so.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/Feather32u4/SmartRoom/thing/favicon_so.png -------------------------------------------------------------------------------- /examples/Feather32u4/SmartRoom/thing/i_120_120_so.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/Feather32u4/SmartRoom/thing/i_120_120_so.png -------------------------------------------------------------------------------- /examples/Feather32u4/SmartRoom/thing/i_152_152_so.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/Feather32u4/SmartRoom/thing/i_152_152_so.png -------------------------------------------------------------------------------- /examples/Feather32u4/SmartRoom/thing/i_167_167_so.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/Feather32u4/SmartRoom/thing/i_167_167_so.png -------------------------------------------------------------------------------- /examples/Feather32u4/SmartRoom/thing/i_180_180_so.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/Feather32u4/SmartRoom/thing/i_180_180_so.png -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266.jpg -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_PCB.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_PCB.jpg -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/Sonoff_Dual_ESP8266.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_Dual_ESP8266.jpg -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_1.jpg -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_2.jpg -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_3.jpg -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_4.jpg -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_5.jpg -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_6.jpg -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_7.jpg -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_8.jpg -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_9.jpg -------------------------------------------------------------------------------- /examples/WEMOS/Garage/thing/esp8266-wemos-d1-mini-pinout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/WEMOS/Garage/thing/esp8266-wemos-d1-mini-pinout.png -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_CH340G_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_CH340G_1.jpg -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_CH340G_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_CH340G_2.jpg -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_10.jpg -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_11.jpg -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_12.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_12.jpg -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_13.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_13.jpg -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/Sonoff_Socket_ESP8266.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_Socket_ESP8266.jpg -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_Slampher_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i4things/NodeAPI/HEAD/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_Slampher_1.jpg -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY_RESTART/thing/README.md: -------------------------------------------------------------------------------- 1 | The RESTARTER 2 | 3 | (the idea is to check internet connectivity and if not available to restart the modem) 4 | 5 | 6 | Heartbeat is send every 4 minutes and if not received acknowledge in 10 min ( from one of the two heart beats ) 7 | e.g. two heartbeats has been missed the relay is switched OFF for 10 sec and after that ON 8 | The button, if available e.g. in case of Sonoff or TYWE2S is used to toggle from ON to OFF and vise verse 9 | If the relay is off for 10 sec then it will be automatically switched ON 10 | 11 | 12 | *FOR HOWTO UPLOAD/INSTALL - PLEASE READ : https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/README.md 13 | -------------------------------------------------------------------------------- /examples/Feather32u4/SmartRoom/thing/thing_light.h: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 16 | // Door Lock 17 | 18 | 19 | #define LIGHT_PIN 10 20 | 21 | bool light_on = false; 22 | 23 | void LIGHT_INIT() 24 | { 25 | pinMode(LIGHT_PIN, OUTPUT); 26 | } 27 | 28 | void LIGHT_ON() 29 | { 30 | digitalWrite(LIGHT_PIN, HIGH); 31 | 32 | light_on = true; 33 | } 34 | 35 | 36 | void LIGHT_OFF() 37 | { 38 | digitalWrite(LIGHT_PIN, LOW); 39 | 40 | light_on = false; 41 | } 42 | 43 | 44 | void LIGHT_WORK() 45 | { 46 | 47 | } 48 | 49 | bool IS_LIGHT_ON() 50 | { 51 | return light_on; 52 | } 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /examples/Feather32u4/SmartRoom/thing/thing_timestamp.h: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 16 | // Door Lock 17 | 18 | //10sec 19 | #define TIMESTAMP_TIMEOUT 1000 20 | uint32_t TIMESTAMP_LAST_EXECUTE; 21 | uint32_t TIMESTAMP_DIFF; 22 | uint32_t TIMESTAMP_NOW = 0; 23 | 24 | void TIMESTAMP_INIT() 25 | { 26 | TIMESTAMP_NOW = millis(); 27 | } 28 | 29 | void TIMESTAMP_WORK() 30 | { 31 | TIMESTAMP_DIFF = ((uint32_t)(((uint32_t)millis()) - TIMESTAMP_LAST_EXECUTE)); 32 | 33 | if (TIMESTAMP_DIFF >= TIMESTAMP_TIMEOUT) 34 | { 35 | TIMESTAMP_NOW = TIMESTAMP_NOW + TIMESTAMP_DIFF; 36 | TIMESTAMP_LAST_EXECUTE = (uint32_t)millis(); 37 | } 38 | } 39 | 40 | long GET_TIMESTAMP_NOW() 41 | { 42 | return TIMESTAMP_NOW; 43 | } 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /examples/Feather32u4/SmartRoom/thing/thing_door.h: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 16 | // Door Lock 17 | 18 | 19 | #define DOOR_LOCK_PIN 9 20 | 21 | //10sec 22 | #define DOOR_LOCK_TIMEOUT 1000 23 | uint32_t DOOR_LOCK_EXECUTE; 24 | bool DOOR_LOCK_IS_OPEN; 25 | 26 | void DOOR_LOCK_INIT() 27 | { 28 | DOOR_LOCK_IS_OPEN = false; 29 | pinMode(DOOR_LOCK_PIN, OUTPUT); 30 | } 31 | 32 | void DOOR_LOCK_OPEN() 33 | { 34 | DOOR_LOCK_EXECUTE = millis(); 35 | DOOR_LOCK_IS_OPEN = true; 36 | digitalWrite(DOOR_LOCK_PIN, HIGH); 37 | } 38 | 39 | void DOOR_LOCK_WORK() 40 | { 41 | if (DOOR_LOCK_IS_OPEN && (((uint32_t)(((uint32_t)millis()) - DOOR_LOCK_EXECUTE)) >= DOOR_LOCK_TIMEOUT)) 42 | { 43 | DOOR_LOCK_IS_OPEN = false; 44 | digitalWrite(DOOR_LOCK_PIN, LOW); 45 | } 46 | } 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /examples/Feather32u4/SmartRoom/thing/thing_door_lock.h: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 16 | // Door Lock 17 | 18 | 19 | #define DOOR_LOCK_PIN 9 20 | 21 | //10sec 22 | #define DOOR_LOCK_TIMEOUT 1000 23 | uint32_t DOOR_LOCK_EXECUTE; 24 | bool DOOR_LOCK_IS_OPEN; 25 | 26 | void DOOR_LOCK_INIT() 27 | { 28 | DOOR_LOCK_IS_OPEN = false; 29 | pinMode(DOOR_LOCK_PIN, OUTPUT); 30 | } 31 | 32 | void DOOR_LOCK_OPEN() 33 | { 34 | DOOR_LOCK_EXECUTE = millis(); 35 | DOOR_LOCK_IS_OPEN = true; 36 | digitalWrite(DOOR_LOCK_PIN, HIGH); 37 | } 38 | 39 | void DOOR_LOCK_WORK() 40 | { 41 | if (DOOR_LOCK_IS_OPEN && (((uint32_t)(((uint32_t)millis()) - DOOR_LOCK_EXECUTE)) >= DOOR_LOCK_TIMEOUT)) 42 | { 43 | DOOR_LOCK_IS_OPEN = false; 44 | digitalWrite(DOOR_LOCK_PIN, LOW); 45 | } 46 | } 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /examples/WEMOS/Garage/thing/thing_led.h: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | // LED blinking 16 | // 17 | 18 | #define LED_TIMEOUT_NOT_CONNECTED 100 19 | #define LED_TIMEOUT_CONNECTED 2000 20 | uint32_t LED_TIMEOUT; 21 | uint32_t LED_LAST_EXECUTE; 22 | // 0 OFF, 1- ON 23 | uint8_t LED_STATE; 24 | 25 | inline void LED_init() 26 | { 27 | pinMode(BUILTIN_LED, OUTPUT); 28 | LED_LAST_EXECUTE = millis(); 29 | LED_STATE = 0; 30 | LED_TIMEOUT = LED_TIMEOUT_NOT_CONNECTED; 31 | } 32 | 33 | // keep boolean return to keep pattern( not used in reality) 34 | inline bool LED_work() 35 | { 36 | if (((uint32_t)(((uint32_t)millis()) - LED_LAST_EXECUTE)) >= LED_TIMEOUT) 37 | { 38 | 39 | LED_LAST_EXECUTE = millis(); 40 | 41 | if (thing.signal_strength() > 0) 42 | { 43 | LED_TIMEOUT = LED_TIMEOUT_CONNECTED; 44 | } 45 | else 46 | { 47 | LED_TIMEOUT = LED_TIMEOUT_NOT_CONNECTED; 48 | } 49 | 50 | if (LED_STATE == 1) 51 | { 52 | LED_STATE = 0; 53 | digitalWrite(BUILTIN_LED, LOW); 54 | } 55 | else 56 | { 57 | LED_STATE = 1; 58 | digitalWrite(BUILTIN_LED, HIGH); 59 | } 60 | } 61 | 62 | return false; 63 | } 64 | -------------------------------------------------------------------------------- /examples/WEMOS/Garage/thing/thing_relay_door.h: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | // Relay door modulle managment 16 | // 17 | 18 | // 1 sec in millis 19 | #define RELAY_DOOR_OPEN_TIMEOUT 2000 20 | uint32_t RELAY_DOOR_OPEN_START; 21 | 22 | inline void RELAY_DOOR_init() 23 | { 24 | RELAY_DOOR_STATE = 0; 25 | 26 | pinMode(RELAY_DOOR_PIN, OUTPUT); 27 | digitalWrite(RELAY_DOOR_PIN, LOW); 28 | } 29 | 30 | inline bool RELAY_DOOR_click() 31 | { 32 | bool ret = false; 33 | if (RELAY_DOOR_STATE == 0) 34 | { 35 | RELAY_DOOR_STATE = 1; 36 | RELAY_DOOR_OPEN_START = millis(); 37 | digitalWrite(RELAY_DOOR_PIN, HIGH); 38 | 39 | Serial.println("DOON : ON"); 40 | 41 | ret = true; 42 | } 43 | else 44 | { 45 | Serial.println("DOON : ALREADY ON"); 46 | } 47 | return ret; 48 | } 49 | 50 | inline bool RELAY_DOOR_work() 51 | { 52 | bool ret = false; 53 | if (RELAY_DOOR_STATE == 1 ) 54 | { 55 | if (((uint32_t)(((uint32_t)millis()) - RELAY_DOOR_OPEN_START)) >= RELAY_DOOR_OPEN_TIMEOUT) 56 | { 57 | RELAY_DOOR_STATE = 0; 58 | digitalWrite(RELAY_DOOR_PIN, LOW); 59 | 60 | Serial.println("DOON : OFF"); 61 | ret = true;; 62 | } 63 | } 64 | return ret; 65 | } 66 | -------------------------------------------------------------------------------- /examples/Feather32u4/DHT22/thing/thing_dht.h: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 16 | // DHT ( Humidity/Temp) 17 | 18 | #include "DHT.h" 19 | 20 | #define DHT_PIN 6 21 | #define DHT_TYPE DHT22 22 | 23 | DHT dht(DHT_PIN, DHT_TYPE); 24 | 25 | //60sec 60 * 1000 (60000) 26 | #define DHT_TIMEOUT 10000 27 | uint32_t DHT_LAST_EXECUTE; 28 | 29 | float DHT_TEMP_VALUE; 30 | float DHT_HUM_VALUE; 31 | 32 | void DHT_INIT() 33 | { 34 | //important make sure DHT is initialized 35 | 36 | DHT_TEMP_VALUE = -20; 37 | DHT_HUM_VALUE = 50; 38 | dht.begin(); 39 | float h = dht.readHumidity(); 40 | float t = dht.readTemperature(); 41 | 42 | if (isnan(h) || isnan(t)) 43 | { 44 | // log error 45 | } 46 | else 47 | { 48 | DHT_TEMP_VALUE = t; 49 | DHT_HUM_VALUE = (uint8_t) h; 50 | } 51 | } 52 | 53 | void DHT_WORK() 54 | { 55 | if (((uint32_t)(((uint32_t)millis()) - DHT_LAST_EXECUTE)) >= DHT_TIMEOUT) 56 | { 57 | DHT_LAST_EXECUTE = millis(); 58 | 59 | float h = dht.readHumidity(); 60 | float t = dht.readTemperature(); 61 | if ((isnan(h)) || (isnan(t))) 62 | { 63 | // log read error 64 | } 65 | else 66 | { 67 | 68 | DHT_HUM_VALUE = (uint8_t) h; 69 | DHT_TEMP_VALUE = t; 70 | 71 | } 72 | } 73 | } 74 | 75 | uint8_t DHT_HUM_GET() 76 | { 77 | return DHT_HUM_VALUE; 78 | } 79 | 80 | float DHT_TEMP_GET() 81 | { 82 | return DHT_TEMP_VALUE; 83 | } 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /examples/Feather32u4/SmartRoom/thing/thing_dht.h: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 16 | // DHT ( Humidity/Temp) 17 | 18 | #include "DHT.h" 19 | 20 | #define DHT_PIN 6 21 | #define DHT_TYPE DHT22 22 | 23 | DHT dht(DHT_PIN, DHT_TYPE); 24 | 25 | //60sec 60 * 1000 (60000) 26 | #define DHT_TIMEOUT 10000 27 | uint32_t DHT_LAST_EXECUTE; 28 | 29 | float DHT_TEMP_VALUE; 30 | float DHT_HUM_VALUE; 31 | 32 | void DHT_INIT() 33 | { 34 | //important make sure DHT is initialized 35 | 36 | DHT_TEMP_VALUE = -20; 37 | DHT_HUM_VALUE = 50; 38 | dht.begin(); 39 | float h = dht.readHumidity(); 40 | float t = dht.readTemperature(); 41 | 42 | if (isnan(h) || isnan(t)) 43 | { 44 | // log error 45 | } 46 | else 47 | { 48 | DHT_TEMP_VALUE = t; 49 | DHT_HUM_VALUE = (uint8_t) h; 50 | } 51 | } 52 | 53 | void DHT_WORK() 54 | { 55 | if (((uint32_t)(((uint32_t)millis()) - DHT_LAST_EXECUTE)) >= DHT_TIMEOUT) 56 | { 57 | DHT_LAST_EXECUTE = millis(); 58 | 59 | float h = dht.readHumidity(); 60 | float t = dht.readTemperature(); 61 | if ((isnan(h)) || (isnan(t))) 62 | { 63 | Serial.println("DHT read failed"); 64 | } 65 | else 66 | { 67 | 68 | DHT_HUM_VALUE = h; 69 | DHT_TEMP_VALUE = t; 70 | 71 | } 72 | } 73 | } 74 | 75 | uint8_t DHT_HUM_GET() 76 | { 77 | return DHT_HUM_VALUE; 78 | } 79 | 80 | float DHT_TEMP_GET() 81 | { 82 | return DHT_TEMP_VALUE; 83 | } 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /examples/Feather32u4/SmartRoom/thing/thing_door_sensor.h: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 16 | // Door Lock 17 | 18 | 19 | #define DOOR_SENSOR_PIN 5 20 | 21 | int DOOR_SENSOR_STATE; 22 | 23 | uint32_t DOOR_SENSOR_LAST_OPEN; 24 | uint32_t DOOR_SENSOR_LAST_CLOSE; 25 | 26 | void DOOR_SENSOR_INIT() 27 | { 28 | pinMode(DOOR_SENSOR_PIN, INPUT); 29 | DOOR_SENSOR_LAST_OPEN = GET_TIMESTAMP_NOW(); 30 | DOOR_SENSOR_LAST_CLOSE = GET_TIMESTAMP_NOW(); 31 | } 32 | 33 | void DOOR_SENSOR_WORK() 34 | { 35 | int OLD_STATE = DOOR_SENSOR_STATE; 36 | DOOR_SENSOR_STATE = digitalRead(DOOR_SENSOR_PIN); 37 | if(OLD_STATE == HIGH && DOOR_SENSOR_STATE == LOW) 38 | { 39 | //the door just got opened 40 | DOOR_SENSOR_LAST_OPEN = GET_TIMESTAMP_NOW(); 41 | Serial.println("Door Open Detected"); 42 | } 43 | else if (OLD_STATE == LOW && DOOR_SENSOR_STATE == HIGH) 44 | { 45 | //the door just got closed 46 | DOOR_SENSOR_LAST_CLOSE = GET_TIMESTAMP_NOW(); 47 | Serial.println("Door Close Detected"); 48 | } 49 | } 50 | 51 | bool IS_DOOR_OPEN() 52 | { 53 | return DOOR_SENSOR_STATE==LOW?true:false; 54 | } 55 | 56 | uint32_t GET_DOOR_SENSOR_LAST_OPEN() 57 | { 58 | uint32_t last_open = ((uint32_t)(GET_TIMESTAMP_NOW()/1000)) - ((uint32_t)(DOOR_SENSOR_LAST_OPEN/1000)); //in sec 59 | return last_open; 60 | } 61 | 62 | uint32_t GET_DOOR_SENSOR_LAST_CLOSE() 63 | { 64 | uint32_t last_close = ((uint32_t)(GET_TIMESTAMP_NOW()/1000)) - ((uint32_t)(DOOR_SENSOR_LAST_CLOSE/1000)); //in sec 65 | return last_close; 66 | } 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /examples/Feather32u4/Simple/thing/thing.ino: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | 16 | /////////////////////////////////////////////////////////////////////////////////// 17 | // THING LIB 18 | 19 | #include "IoTThing.h" 20 | 21 | //Feather32u2 Lora PINS 22 | #define CS_PIN 8 23 | #define RST_PIN 4 24 | #define INT_PIN 7 25 | 26 | // make sure you register in www.i4things.com and get your own device ID - 27 | // the key(private key) - is random bytes choose by you - they need to be the same here and in the iot_get_send.html file) 28 | // you also need to set the network key in the iot_get_send.html - which can be obtained when creating new node in the www.i4things.com client area 29 | // in node details 30 | 31 | #define thing_id 1 32 | uint8_t key[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 33 | IoTThing thing(CS_PIN, INT_PIN, RST_PIN, key, thing_id); 34 | 35 | 36 | // 2 minutes 37 | #define MESSAGE_INTERVAL 120000 38 | uint32_t MESSAGE_LAST_SEND; 39 | 40 | void setup() { 41 | // make sure we send a messae imediatly after start 42 | MESSAGE_LAST_SEND = millis() + MESSAGE_INTERVAL * 2; 43 | 44 | // init serial 45 | Serial.begin(115200); 46 | // Initial delay to give chance to the com port to cennect 47 | delay(2000); 48 | // thing init 49 | thing.init(); 50 | } 51 | 52 | 53 | /////////////////////////////////////////////////////////////////////////////////// 54 | // MAIN LOOP 55 | 56 | void loop() { 57 | thing.work(); 58 | 59 | // try send message every 2 min 60 | if (((uint32_t)(((uint32_t)millis()) - MESSAGE_LAST_SEND)) >= MESSAGE_INTERVAL) { 61 | MESSAGE_LAST_SEND = millis(); 62 | 63 | uint8_t msg[IoTThing_MAX_MESSAGE_LEN]; 64 | 65 | msg[0] = random(30); // e.g. temp 66 | msg[1] = random(50, 90); // e.g. humidity 67 | 68 | // log what we send 69 | Serial.println("Sending data : "); 70 | for (int i = 0; i < 2; i++) { 71 | Serial.println(msg[i]); 72 | } 73 | 74 | // check if IoT layer is ready to accept new message 75 | if (thing.is_ready()) { 76 | thing.send(msg, 2); 77 | } 78 | else { 79 | // cancel previouse work and send new message 80 | thing.cancel(); 81 | thing.send(msg, 2); 82 | } 83 | } 84 | 85 | yield(); 86 | } 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /examples/ESP32/TTGO/Simple/thing/thing.ino: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | 16 | /////////////////////////////////////////////////////////////////////////////////// 17 | // THING LIB 18 | 19 | #include "IoTThing.h" 20 | 21 | 22 | //TTGO Lora PINS 23 | #define CS_PIN 18 24 | #define RST_PIN 14 25 | #define INT_PIN 26 26 | 27 | // make sure you register in www.i4things.com and get your own device ID - 28 | // the key(private key) - is random bytes choose by you - they need to be the same here and in the iot_get_send.html file) 29 | // you also need to set the network key in the iot_get_send.html - which can be obtained when creating new node in the www.i4things.com client area 30 | // in node details 31 | 32 | #define thing_id 1 33 | uint8_t key[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 34 | IoTThing thing(CS_PIN, INT_PIN, RST_PIN, key, thing_id); 35 | 36 | 37 | // 2 minutes 38 | #define MESSAGE_INTERVAL 120000 39 | uint32_t MESSAGE_LAST_SEND; 40 | 41 | void setup() { 42 | // make sure we send a messae imediatly after start 43 | MESSAGE_LAST_SEND = millis() + MESSAGE_INTERVAL * 2; 44 | 45 | // init serial 46 | Serial.begin(115200); 47 | // Initial delay to give chance to the com port to cennect 48 | delay(2000); 49 | // thing init 50 | thing.init(); 51 | 52 | } 53 | 54 | 55 | /////////////////////////////////////////////////////////////////////////////////// 56 | // MAIN LOOP 57 | 58 | void loop() { 59 | thing.work(); 60 | 61 | // try send message every 2 min 62 | if (((uint32_t)(((uint32_t)millis()) - MESSAGE_LAST_SEND)) >= MESSAGE_INTERVAL) { 63 | MESSAGE_LAST_SEND = millis(); 64 | 65 | uint8_t msg[IoTThing_MAX_MESSAGE_LEN]; 66 | 67 | msg[0] = random(30); // e.g. temp 68 | msg[1] = random(50, 90); // e.g. humidity 69 | 70 | // log what we send 71 | Serial.println("Sending data : "); 72 | for (int i = 0; i < 2; i++) { 73 | Serial.println(msg[i]); 74 | } 75 | 76 | // check if IoT layer is ready to accept new message 77 | if (thing.is_ready()) { 78 | thing.send(msg, 2); 79 | } 80 | else { 81 | // cancel previouse work and send new message 82 | thing.cancel(); 83 | thing.send(msg, 2); 84 | } 85 | } 86 | 87 | yield(); 88 | } 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /examples/ESP32/HELTEC/Simple/thing/thing.ino: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | 16 | /////////////////////////////////////////////////////////////////////////////////// 17 | // THING LIB 18 | 19 | #include "IoTThing.h" 20 | 21 | //Heltec LoRa 32 PINS 22 | #define CS_PIN 18 23 | #define RST_PIN 14 24 | #define INT_PIN 26 25 | 26 | // make sure you register in www.i4things.com and get your own device ID - 27 | // the key(private key) - is random bytes choose by you - they need to be the same here and in the iot_get_send.html file) 28 | // you also need to set the network key in the iot_get_send.html - which can be obtained when creating new node in the www.i4things.com client area 29 | // in node details 30 | 31 | #define thing_id 1 32 | uint8_t key[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 33 | IoTThing thing(CS_PIN, INT_PIN, RST_PIN, key, thing_id); 34 | 35 | 36 | // 2 minutes 37 | #define MESSAGE_INTERVAL 120000 38 | uint32_t MESSAGE_LAST_SEND; 39 | 40 | void setup() { 41 | // make sure we send a messae imediatly after start 42 | MESSAGE_LAST_SEND = millis() + MESSAGE_INTERVAL * 2; 43 | 44 | // init serial 45 | Serial.begin(115200); 46 | // Initial delay to give chance to the com port to cennect 47 | delay(2000); 48 | // thing init 49 | thing.init(); 50 | 51 | } 52 | 53 | 54 | /////////////////////////////////////////////////////////////////////////////////// 55 | // MAIN LOOP 56 | 57 | void loop() { 58 | thing.work(); 59 | 60 | // try send message every 2 min 61 | if (((uint32_t)(((uint32_t)millis()) - MESSAGE_LAST_SEND)) >= MESSAGE_INTERVAL) { 62 | MESSAGE_LAST_SEND = millis(); 63 | 64 | uint8_t msg[IoTThing_MAX_MESSAGE_LEN]; 65 | 66 | msg[0] = random(30); // e.g. temp 67 | msg[1] = random(50, 90); // e.g. humidity 68 | 69 | // log what we send 70 | Serial.println("Sending data : "); 71 | for (int i = 0; i < 2; i++) { 72 | Serial.println(msg[i]); 73 | } 74 | 75 | // check if IoT layer is ready to accept new message 76 | if (thing.is_ready()) { 77 | thing.send(msg, 2); 78 | } 79 | else { 80 | // cancel previouse work and send new message 81 | thing.cancel(); 82 | thing.send(msg, 2); 83 | } 84 | } 85 | 86 | yield(); 87 | } 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /examples/WEMOS/Garage/thing/README.md: -------------------------------------------------------------------------------- 1 | Download Arduino IDE: 2 | Download Arduino IDE from https://www.arduino.cc/en/Main/Software 3 | 4 | Install ESP8266 board software: 5 | Open Arduino IDE and select File ? Preferences (Arduino ? Preferences on Mac) and add the following text for field Additional Boards Manager URLs: http://arduino.esp8266.com/stable/package_esp8266com_index.json and select OK. 6 | Open Tools ? Boards... ? Boards Manager... and scroll down and click on esp8266 by ESP8266 Community. Click the Install button to download and install the latest ESP8266 board software. Select Close. 7 | 8 | Dependacy on ( the following lib need to be isntalled) : https://github.com/i4things/Gateway/blob/master/src/arduino-esp32/DHTesp.zip 9 | 10 | Use Board: "WeMos D1 R1" 11 | 12 | Garage example 13 | 14 | Scenario : Wemos, DHT22 sensor measuring temperature and humidity and 2 relays 15 | 16 | 1. Relay 1 is for Automatic Garage door - when Open/Close button on web page is clicked Relay 1 is ON for 2 sec 17 | 18 | 2. DTH22 measures temp and humidity and send it every 10 min to the server ( if different) 19 | 20 | 3. Relay 2 is connected to a fan 21 | 22 | 4. When humidity over 70% relay 2 is automatically switched ON for 2 hours cycle 23 | 24 | 5. When clicked on web page - "Relay 2 ON" button Relay 2 is switched ON. 25 | 26 | 6. When clicked on web page - "Relay 2 OFF" button Relay 2 is switched OFF. ( if humidity is > 70% it will be switched ON automatically after 10 minutes again) 27 | 28 | 7. Relay 2 cannot stay ON for more then 2 hours every 2.5 hours 29 | 30 | 8. If Relay 2 is switched OFF because max ON ( 2 hours) is reached it cannot be switched ON for the next 1/2h 31 | 32 | * The default pins on D1 Relay Shield and DHT Shiled cannot be used as they clash with serial interface for logging and built-in led. Please make sure they are not connected and you have actually bridged them as described below 33 | 34 | DOOR Relay controling pin to D7 35 | 36 | FAN Relay controling pin to D6 37 | 38 | DHT data pin to D5 39 | 40 | Build : 41 | 42 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/WEMOS/Garage/thing/view1.JPG) 43 | 44 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/WEMOS/Garage/thing/view2.JPG) 45 | 46 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/WEMOS/Garage/thing/view3.JPG) 47 | 48 | Pinout: 49 | 50 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/WEMOS/Garage/thing/esp8266-wemos-d1-mini-pinout.png) 51 | 52 | Parts: 53 | 54 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/WEMOS/Garage/thing/cpu.jpg) 55 | 56 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/WEMOS/Garage/thing/dht.jpg) 57 | 58 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/WEMOS/Garage/thing/triple.jpg) 59 | 60 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/WEMOS/Garage/thing/relay.jpg) 61 | -------------------------------------------------------------------------------- /examples/Feather32u4/DHT22/thing/thing.ino: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | 16 | 17 | /////////////////////////////////////////////////////////////////////////////////// 18 | // THING LIB 19 | 20 | #include "IoTThing.h" 21 | 22 | 23 | //Feather32u2 Lora PINS 24 | #define CS_PIN 8 25 | #define RST_PIN 4 26 | #define INT_PIN 7 27 | 28 | // make sure you register in www.i4things.com and get your own device ID - 29 | // the key(private key) - is random bytes choose by you - they need to be the same here and in the iot_get_send.html file) 30 | // you also need to set the network key in the iot_get_send.html - which can be obtained when creating new node in the www.i4things.com client area 31 | // in node details 32 | 33 | #define thing_id 1 34 | uint8_t key[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 35 | IoTThing thing(CS_PIN, INT_PIN, RST_PIN, key, thing_id); 36 | 37 | 38 | // 2 minutes 39 | #define MESSAGE_INTERVAL 120000 40 | uint32_t MESSAGE_LAST_SEND; 41 | 42 | #include "thing_dht.h" 43 | 44 | void setup() 45 | { 46 | Serial.begin(115200); 47 | 48 | MESSAGE_LAST_SEND = millis() + MESSAGE_INTERVAL * 2; 49 | 50 | // Initial delay to give chance to the com port to cennect 51 | delay(2000); 52 | 53 | // Radio 54 | thing.init(); 55 | 56 | //DHT (temp/Moist) 57 | DHT_INIT(); 58 | 59 | } 60 | 61 | 62 | /////////////////////////////////////////////////////////////////////////////////// 63 | // MAIN LOOP 64 | 65 | void loop() 66 | { 67 | DHT_WORK(); 68 | 69 | thing.work(); 70 | 71 | // try send message every 2 min 72 | if (((uint32_t)(((uint32_t)millis()) - MESSAGE_LAST_SEND)) >= MESSAGE_INTERVAL) 73 | { 74 | MESSAGE_LAST_SEND = millis(); 75 | 76 | uint8_t msg[IoTThing_MAX_MESSAGE_LEN]; 77 | uint8_t msg_size = 0; 78 | 79 | msg[msg_size++] = (int8_t)DHT_TEMP_GET(); 80 | msg[msg_size++] = DHT_HUM_GET(); 81 | 82 | for (int i = 0; i < msg_size; i++) 83 | { 84 | Serial.println(msg[i]); 85 | } 86 | 87 | // check if IoT layer is ready to accept new message 88 | if (thing.is_ready()) 89 | { 90 | thing.send(msg, msg_size); 91 | } 92 | else 93 | { 94 | // cancel previouse work and send new message 95 | thing.cancel(); 96 | thing.send(msg, msg_size); 97 | } 98 | 99 | } 100 | 101 | yield(); 102 | } 103 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Steps to run the examples: 2 | 3 | 1. Navigate to www.i4things.com 4 | 5 | 1.1. Sign-in ( free ) 6 | 7 | 1.2. Check your email and activate your registration 8 | 9 | 1.3. Navigate to USER AREA 10 | 11 | 1.4. Create a NODE ( choose name for it ) 12 | 13 | 1.5. Click on the node in the Nodes List to get to Node Info and make notes of ID and Key ( Network Key) 14 | 15 | 16 | ``` 17 | optional: ( if you do not have a local coverage and you need to have your own gateway) 18 | 1.6. Create Gateway in the USER AREA ( set name, coordinates and is it open or private - please choose open to make easy the initial example process) 19 | / in case you DO decide to use private gateway then you will need to pass the gateway id when constructing the IoTThing object/ 20 | 1.7. Click on the gateway in the Gateway List and get to Gateway Info and make notes about gateway ID and Key (Network Key) 21 | 1.8. Download GatewayUI.zip and install from it the Gateway Configurator Application ( Windows ) from here : https://github.com/i4things/Gateway 22 | 1.9. Run the application and follow the next instructions to configure your new gateway: 23 | 24 | - Download and install USB driver for your gateway from: https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers 25 | - Download and unzip the gateway software : gateway_heltec.zip or gateway_ttgo.zip ( depending on the hardware that you choose for your gateway ) 26 | - Connect the device using USB to micro USB cable. 27 | - Edit the file upload.cmd - to have teh correct COMport on which teh gateways is attached 28 | - Execute upload.cmd 29 | - Download and install the configurator from from this repository ( GatewayUI) 30 | - Start The configurator 31 | - Click “Refresh” 32 | - Click “Connect” 33 | - Click “Get Configuration” 34 | - IF all is OK the SSID, PASS, GATEWAY ID, GATEWAY KEY, FREQUENCY should be filled with values. - if not check the connection. 35 | - Setup the WiFi configuration: fill SSID and PASS and click “Send to Gateway”. 36 | - Setup Gateway Details: fill GATEWAY ID and GATEWAY KEY ( provided from the user area of www.i4things.com) and click "Send to Gateway”. 37 | - Setup Frequency : fill the FREQUENCY with one of the following : 868.1 , 868.3 or 868.5 ( only this frequencies are supported for private gateway) and click "Send to Gateway”. 10 Finally Click “Get Configuration” and if all is OK the SSID, PASS, GATEWAY ID, GATEWAY KEY, FREQUENCY should have the values you have configured. 38 | - Restart The Gateway (non mandatory) 39 | ``` 40 | 41 | 2. Download the example for the breadboard that you have - we have examples for Adafruit32u4 Lora, Heltec Lora 32 and TTGO Lora 42 | / The library and examples will work with almost all board with LoRa - you just need to pass the appropriate PINS/ 43 | 44 | 3. Compile and upload teh exmaple 45 | 46 | 4. Open the .html page that in is the example folder in a browser and you will be able to see data from and send data to the node 47 | 48 | IMPORTANT: Download and make available the RadioHead library from : https://www.airspayce.com/mikem/arduino/RadioHead/index.html 49 | -------------------------------------------------------------------------------- /examples/ESP32/TTGO/SendAndReceive/thing/thing.ino: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | 16 | // called when packet received from node 17 | // IMPORTANT! 18 | // Waight for 1 minute to get the data after opening the iot_get_send.html - as data is dispatched every minute from server to gateways 19 | void received(uint8_t buf[], uint8_t size, int16_t rssi) { 20 | Serial.println("Data Received :"); 21 | for (int i = 0; i < size; i++) { 22 | Serial.println(buf[i]); 23 | } 24 | }; 25 | 26 | /////////////////////////////////////////////////////////////////////////////////// 27 | // THING LIB 28 | #include "IoTThing.h" 29 | 30 | //TTGO Lora PINS 31 | #define CS_PIN 18 32 | #define RST_PIN 14 33 | #define INT_PIN 26 34 | 35 | // make sure you register in www.i4things.com and get your own device ID - 36 | // the key(private key) - is random bytes choose by you - they need to be the same here and in the iot_get_send.html file) 37 | // you also need to set the network key in the iot_get_send.html - which can be obtained when creating new node in the www.i4things.com client area 38 | // in node details 39 | 40 | #define thing_id 1 41 | uint8_t key[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 42 | IoTThing thing(CS_PIN, INT_PIN, RST_PIN, key, thing_id, received); 43 | 44 | 45 | // 2 minutes 46 | #define MESSAGE_INTERVAL 120000 47 | uint32_t MESSAGE_LAST_SEND; 48 | 49 | void setup() { 50 | // make sure we send a messae imediatly after start 51 | MESSAGE_LAST_SEND = millis() + MESSAGE_INTERVAL * 2; 52 | 53 | // init serial 54 | Serial.begin(115200); 55 | // Initial delay to give chance to the com port to cennect 56 | delay(2000); 57 | // thing init 58 | thing.init(); 59 | 60 | } 61 | 62 | 63 | /////////////////////////////////////////////////////////////////////////////////// 64 | // MAIN LOOP 65 | 66 | void loop() { 67 | thing.work(); 68 | 69 | // try send message every 2 min 70 | if (((uint32_t)(((uint32_t)millis()) - MESSAGE_LAST_SEND)) >= MESSAGE_INTERVAL) { 71 | MESSAGE_LAST_SEND = millis(); 72 | 73 | uint8_t msg[IoTThing_MAX_MESSAGE_LEN]; 74 | 75 | msg[0] = random(30); // e.g. temp 76 | msg[1] = random(50, 90); // e.g. humidity 77 | 78 | // log what we send 79 | Serial.println("Sending data : "); 80 | for (int i = 0; i < 2; i++) { 81 | Serial.println(msg[i]); 82 | } 83 | 84 | // check if IoT layer is ready to accept new message 85 | if (thing.is_ready()) { 86 | thing.send(msg, 2); 87 | } 88 | else { 89 | // cancel previouse work and send new message 90 | thing.cancel(); 91 | thing.send(msg, 2); 92 | } 93 | } 94 | 95 | yield(); 96 | } 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /examples/Feather32u4/SendAndReceive/thing/thing.ino: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | 16 | // called when packet received from node 17 | // IMPORTANT! 18 | // Waight for 1 minute to get the data after opening the iot_get_send.html - as data is dispatched every minute from server to gateways 19 | void received(uint8_t buf[], uint8_t size, int16_t rssi) { 20 | Serial.println("Data Received :"); 21 | for (int i = 0; i < size; i++) { 22 | Serial.println(buf[i]); 23 | } 24 | }; 25 | 26 | /////////////////////////////////////////////////////////////////////////////////// 27 | // THING LIB 28 | #include "IoTThing.h" 29 | 30 | //Feather32u2 Lora PINS 31 | #define CS_PIN 8 32 | #define RST_PIN 4 33 | #define INT_PIN 7 34 | 35 | // make sure you register in www.i4things.com and get your own device ID - 36 | // the key(private key) - is random bytes choose by you - they need to be the same here and in the iot_get_send.html file) 37 | // you also need to set the network key in the iot_get_send.html - which can be obtained when creating new node in the www.i4things.com client area 38 | // in node details 39 | 40 | #define thing_id 1 41 | uint8_t key[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 42 | IoTThing thing(CS_PIN, INT_PIN, RST_PIN, key, thing_id, received); 43 | 44 | 45 | // 2 minutes 46 | #define MESSAGE_INTERVAL 120000 47 | uint32_t MESSAGE_LAST_SEND; 48 | 49 | void setup() { 50 | // make sure we send a messae imediatly after start 51 | MESSAGE_LAST_SEND = millis() + MESSAGE_INTERVAL * 2; 52 | 53 | // init serial 54 | Serial.begin(115200); 55 | // Initial delay to give chance to the com port to cennect 56 | delay(2000); 57 | // thing init 58 | thing.init(); 59 | 60 | } 61 | 62 | 63 | /////////////////////////////////////////////////////////////////////////////////// 64 | // MAIN LOOP 65 | 66 | void loop() { 67 | thing.work(); 68 | 69 | // try send message every 2 min 70 | if (((uint32_t)(((uint32_t)millis()) - MESSAGE_LAST_SEND)) >= MESSAGE_INTERVAL) { 71 | MESSAGE_LAST_SEND = millis(); 72 | 73 | uint8_t msg[IoTThing_MAX_MESSAGE_LEN]; 74 | 75 | msg[0] = random(30); // e.g. temp 76 | msg[1] = random(50, 90); // e.g. humidity 77 | 78 | // log what we send 79 | Serial.println("Sending data : "); 80 | for (int i = 0; i < 2; i++) { 81 | Serial.println(msg[i]); 82 | } 83 | 84 | // check if IoT layer is ready to accept new message 85 | if (thing.is_ready()) { 86 | thing.send(msg, 2); 87 | } 88 | else { 89 | // cancel previouse work and send new message 90 | thing.cancel(); 91 | thing.send(msg, 2); 92 | } 93 | } 94 | 95 | yield(); 96 | } 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /examples/ESP32/HELTEC/SendAndReceive/thing/thing.ino: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | 16 | // called when packet received from node 17 | // IMPORTANT! 18 | // Waight for 1 minute to get the data after opening the iot_get_send.html - as data is dispatched every minute from server to gateways 19 | void received(uint8_t buf[], uint8_t size, int16_t rssi) { 20 | Serial.println("Data Received :"); 21 | for (int i = 0; i < size; i++) { 22 | Serial.println(buf[i]); 23 | } 24 | }; 25 | 26 | /////////////////////////////////////////////////////////////////////////////////// 27 | // THING LIB 28 | #include "IoTThing.h" 29 | 30 | //Heltec LoRa 32 PINS 31 | #define CS_PIN 18 32 | #define RST_PIN 14 33 | #define INT_PIN 26 34 | 35 | // make sure you register in www.i4things.com and get your own device ID - 36 | // the key(private key) - is random bytes choose by you - they need to be the same here and in the iot_get_send.html file) 37 | // you also need to set the network key in the iot_get_send.html - which can be obtained when creating new node in the www.i4things.com client area 38 | // in node details 39 | 40 | #define thing_id 1 41 | uint8_t key[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 42 | IoTThing thing(CS_PIN, INT_PIN, RST_PIN, key, thing_id, received); 43 | 44 | 45 | // 2 minutes 46 | #define MESSAGE_INTERVAL 120000 47 | uint32_t MESSAGE_LAST_SEND; 48 | 49 | void setup() { 50 | // make sure we send a messae imediatly after start 51 | MESSAGE_LAST_SEND = millis() + MESSAGE_INTERVAL * 2; 52 | 53 | // init serial 54 | Serial.begin(115200); 55 | // Initial delay to give chance to the com port to cennect 56 | delay(2000); 57 | // thing init 58 | thing.init(); 59 | 60 | } 61 | 62 | 63 | /////////////////////////////////////////////////////////////////////////////////// 64 | // MAIN LOOP 65 | 66 | void loop() { 67 | thing.work(); 68 | 69 | // try send message every 2 min 70 | if (((uint32_t)(((uint32_t)millis()) - MESSAGE_LAST_SEND)) >= MESSAGE_INTERVAL) { 71 | MESSAGE_LAST_SEND = millis(); 72 | 73 | uint8_t msg[IoTThing_MAX_MESSAGE_LEN]; 74 | 75 | msg[0] = random(30); // e.g. temp 76 | msg[1] = random(50, 90); // e.g. humidity 77 | 78 | // log what we send 79 | Serial.println("Sending data : "); 80 | for (int i = 0; i < 2; i++) { 81 | Serial.println(msg[i]); 82 | } 83 | 84 | // check if IoT layer is ready to accept new message 85 | if (thing.is_ready()) { 86 | thing.send(msg, 2); 87 | } 88 | else { 89 | // cancel previouse work and send new message 90 | thing.cancel(); 91 | thing.send(msg, 2); 92 | } 93 | } 94 | 95 | yield(); 96 | } 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /wifi_api/thing/thing.ino: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | 16 | // called when packet received from node 17 | void received(uint8_t buf[], uint8_t size, int16_t rssi) { 18 | Serial.println("Data Received :"); 19 | for (int i = 0; i < size; i++) { 20 | Serial.println(buf[i]); 21 | } 22 | }; 23 | 24 | /////////////////////////////////////////////////////////////////////////////////// 25 | // THING LIB 26 | #include "IoTThing.h" 27 | 28 | // make sure you register in www.i4things.com and get your own device ID - 29 | // the key(private key) - is random bytes choose by you - they need to be the same here and in the iot_get_send.html file) 30 | // also for the wifi API you need to register a gateway for every node and fil gateway ID and gateway KEY 31 | // you also need to set the network key in the iot_get_send.html - which can be obtained when creating new node in the www.i4things.com client area 32 | // in node details 33 | 34 | //please create a gateway for every per node and set it here 35 | #define gateway_id 4172 36 | #define gateway_key "6869376AF0D54449C1C22ED5BBA2A18F" 37 | 38 | #define ssid "PLUSNET-7F63NX" 39 | #define pass "4e3acd6a4f" 40 | 41 | #define thing_id 37 42 | uint8_t thing_key[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 43 | IoTThing thing(ssid, pass, thing_id, thing_key, gateway_id, gateway_key, received); 44 | 45 | 46 | // 2 minutes 47 | #define MESSAGE_INTERVAL 120000 48 | uint32_t MESSAGE_LAST_SEND; 49 | 50 | void setup() { 51 | // make sure we send a messae imediatly after start 52 | MESSAGE_LAST_SEND = millis() + MESSAGE_INTERVAL * 2; 53 | 54 | // init serial 55 | Serial.begin(115200); 56 | // Initial delay to give chance to the com port to cennect 57 | delay(2000); 58 | // thing init 59 | thing.init(); 60 | 61 | } 62 | 63 | 64 | /////////////////////////////////////////////////////////////////////////////////// 65 | // MAIN LOOP 66 | 67 | void loop() { 68 | thing.work(); 69 | 70 | // try send message every 2 min 71 | if (((uint32_t)(((uint32_t)millis()) - MESSAGE_LAST_SEND)) >= MESSAGE_INTERVAL) { 72 | MESSAGE_LAST_SEND = millis(); 73 | 74 | uint8_t msg[IoTThing_MAX_MESSAGE_LEN]; 75 | 76 | msg[0] = random(30); // e.g. temp 77 | msg[1] = random(50, 90); // e.g. humidity 78 | 79 | // log what we send 80 | Serial.println("Sending data : "); 81 | for (int i = 0; i < 2; i++) { 82 | Serial.println(msg[i]); 83 | } 84 | 85 | // check if IoT layer is ready to accept new message 86 | if (thing.is_ready()) { 87 | thing.send(msg, 2); 88 | } 89 | else { 90 | // cancel previouse work and send new message 91 | thing.cancel(); 92 | thing.send(msg, 2); 93 | } 94 | } 95 | 96 | yield(); 97 | } 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /examples/WEMOS/Garage/thing/thing_dht.h: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | // DHT modulle managment 16 | // 17 | 18 | #include "DHTesp.h" 19 | 20 | DHTesp sensor; 21 | 22 | #define DHT_BUF_SIZE 10 23 | uint8_t DHT_BUF_TEMP[DHT_BUF_SIZE]; 24 | uint8_t DHT_BUF_HUM[DHT_BUF_SIZE]; 25 | uint8_t DHT_BUF_CNT; 26 | 27 | //60sec 60 * 1000 (60000) 28 | #define DHT_TIMEOUT 60000 29 | uint32_t DHT_LAST_EXECUTE; 30 | 31 | #define DHT_TIMEOUT_CALC (DHT_TIMEOUT * DHT_BUF_SIZE) 32 | uint32_t DHT_LAST_EXECUTE_CALC; 33 | 34 | inline void DHT_init() 35 | { 36 | DHT_TEMP = 120; // TEMP IN C = DHT_TEMP - 100 37 | DHT_HUM = 50; 38 | 39 | sensor.setup(DHT_PIN, DHTesp::DHT22); 40 | delay(2000); 41 | float h = sensor.getHumidity(); 42 | float t = sensor.getTemperature(); 43 | if (isnan(h) || isnan(t)) 44 | { 45 | // issue ? 46 | } 47 | else 48 | { 49 | DHT_TEMP = (uint8_t)(t + 100); 50 | DHT_HUM = (uint8_t)h; 51 | } 52 | 53 | DHT_LAST_EXECUTE = millis(); 54 | DHT_LAST_EXECUTE_CALC = millis(); 55 | 56 | DHT_BUF_CNT = 0; 57 | } 58 | 59 | inline void DHT_insert_sort(uint8_t arr[], uint8_t val, uint8_t count) 60 | { 61 | int8_t i = count - 1; // needs to be with sign for the logic to work 62 | for (; (i >= 0) && (arr[i] > val); i--) 63 | { 64 | arr[i + 1] = arr[i]; 65 | } 66 | arr[i + 1] = val; 67 | } 68 | 69 | inline bool DHT_work() 70 | { 71 | bool ret = false; 72 | 73 | if (((uint32_t)(((uint32_t)millis()) - DHT_LAST_EXECUTE)) >= DHT_TIMEOUT) 74 | { 75 | DHT_LAST_EXECUTE = millis(); 76 | 77 | float h = sensor.getHumidity(); 78 | float t = sensor.getTemperature(); 79 | if (isnan(h) || isnan(t)) 80 | { 81 | // issue ? 82 | } 83 | else if (DHT_BUF_CNT < DHT_BUF_SIZE) 84 | { 85 | DHT_insert_sort(DHT_BUF_TEMP, (uint8_t)(t + 100), DHT_BUF_CNT); 86 | DHT_insert_sort(DHT_BUF_HUM, (uint8_t)h, DHT_BUF_CNT); 87 | DHT_BUF_CNT++; 88 | } 89 | } 90 | 91 | if (((uint32_t)(((uint32_t)millis()) - DHT_LAST_EXECUTE_CALC)) >= DHT_TIMEOUT_CALC) 92 | { 93 | DHT_LAST_EXECUTE_CALC = millis(); 94 | 95 | if (DHT_BUF_CNT > 0) 96 | { 97 | if ( DHT_TEMP != DHT_BUF_TEMP[DHT_BUF_CNT / 2]) 98 | { 99 | DHT_TEMP = DHT_BUF_TEMP[DHT_BUF_CNT / 2]; 100 | ret = true; 101 | } 102 | 103 | if (DHT_HUM != DHT_BUF_HUM[DHT_BUF_CNT / 2]) 104 | { 105 | DHT_HUM = DHT_BUF_HUM[DHT_BUF_CNT / 2]; 106 | ret = true; 107 | } 108 | DHT_BUF_CNT = 0; 109 | 110 | Serial.print("DHT : "); Serial.print((uint16_t)(DHT_TEMP - 100)); Serial.print(" ");Serial.println(DHT_HUM); 111 | } 112 | } 113 | 114 | return ret; 115 | } 116 | -------------------------------------------------------------------------------- /gprs_api/thing/thing.ino: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | 16 | /////////////////////////////////////////////////////////////////////////////////// 17 | // LOG constants 18 | #define LOG64_ENABLED 19 | 20 | #include 21 | 22 | 23 | // called when packet received from node 24 | void received(uint8_t buf[], uint8_t size, int16_t rssi) { 25 | Serial.println("Data Received :"); 26 | for (int i = 0; i < size; i++) { 27 | Serial.println(buf[i]); 28 | } 29 | }; 30 | 31 | /////////////////////////////////////////////////////////////////////////////////// 32 | // THING LIB 33 | #include "IoTThing.h" 34 | 35 | // make sure you register in www.i4things.com and get your own device ID - 36 | // the key(private key) - is random bytes choose by you - they need to be the same here and in the iot_get_send.html file) 37 | // also for the wifi API you need to register a gateway for every node and fil gateway ID and gateway KEY 38 | // you also need to set the network key in the iot_get_send.html - which can be obtained when creating new node in the www.i4things.com client area 39 | // in node details 40 | 41 | //please create a gateway for every per node and set it here 42 | #define gateway_id 4172 43 | #define gateway_key "6869376AF0D54449C1C22ED5BBA2A18F" 44 | 45 | #define apn "iot.1nce.net" 46 | #define user " " 47 | #define pass " " 48 | #define hardware_serial_num 1 49 | #define pin_rx 12 50 | #define pin_tx 13 51 | #define pin_reset 2 52 | 53 | #define thing_id 37 54 | uint8_t thing_key[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 55 | IoTThing thing(apn, user, pass, hardware_serial_num, pin_rx, pin_tx, pin_reset, true, thing_id, thing_key, gateway_id, gateway_key, received); 56 | 57 | 58 | // 2 minutes 59 | #define MESSAGE_INTERVAL 120000 60 | uint32_t MESSAGE_LAST_SEND; 61 | 62 | void setup() { 63 | // make sure we send a messae imediatly after start 64 | MESSAGE_LAST_SEND = millis() + MESSAGE_INTERVAL * 2; 65 | 66 | // init serial 67 | //Serial.begin(115200); 68 | // Serial Log 69 | LOG64_INIT(); 70 | // Initial delay to give chance to the com port to cennect 71 | delay(2000); 72 | // thing init 73 | thing.init(); 74 | 75 | } 76 | 77 | 78 | /////////////////////////////////////////////////////////////////////////////////// 79 | // MAIN LOOP 80 | 81 | void loop() { 82 | thing.work(); 83 | 84 | // try send message every 2 min 85 | if (((uint32_t)(((uint32_t)millis()) - MESSAGE_LAST_SEND)) >= MESSAGE_INTERVAL) { 86 | MESSAGE_LAST_SEND = millis(); 87 | 88 | uint8_t msg[IoTThing_MAX_MESSAGE_LEN]; 89 | 90 | msg[0] = random(30); // e.g. temp 91 | msg[1] = random(50, 90); // e.g. humidity 92 | 93 | // log what we send 94 | Serial.println("Sending data : "); 95 | for (int i = 0; i < 2; i++) { 96 | Serial.println(msg[i]); 97 | } 98 | 99 | // check if IoT layer is ready to accept new message 100 | if (thing.is_ready()) { 101 | thing.send(msg, 2); 102 | } 103 | else { 104 | // cancel previouse work and send new message 105 | thing.cancel(); 106 | thing.send(msg, 2); 107 | } 108 | } 109 | 110 | yield(); 111 | } 112 | -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/iot_get_send.html: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 36 | 37 | 38 |
Relay ChannelOnOffStateReload State
Relay Channel #1
39 | 40 | 41 | 42 | 43 | 44 | 76 | 77 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /examples/ESP32/TTGO/Simple/thing/iot_get.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

5 | 6 |

7 | 8 |

9 | 10 | 11 | 12 | 13 | 14 | 83 | 84 | 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /examples/Feather32u4/Simple/thing/iot_get.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

5 | 6 |

7 | 8 |

9 | 10 | 11 | 12 | 13 | 14 | 83 | 84 | 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /examples/Feather32u4/Tester/thing/iot_get.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

5 | 6 |

7 | 8 |

9 | 10 | 11 | 12 | 13 | 14 | 83 | 84 | 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /examples/ESP32/HELTEC/Simple/thing/iot_get.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

5 | 6 |

7 | 8 |

9 | 10 | 11 | 12 | 13 | 14 | 83 | 84 | 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /examples/Feather32u4/SmartRoom/thing/thing.ino: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | /////////////////////////////////////////////////////////////////////////////////// 16 | // LOG constants 17 | #define LOG64_ENABLED 18 | 19 | #include 20 | 21 | /////////////////////////////////////////////////////////////////////////////////// 22 | // THING LIB 23 | 24 | #include "IoTThing.h" 25 | #include "thing_timestamp.h" 26 | #include "thing_door_lock.h" 27 | #include "thing_door_sensor.h" 28 | #include "thing_light.h" 29 | #include "thing_dht.h" 30 | 31 | 32 | //Feather32u2 Lora PINS 33 | #define CS_PIN 8 34 | #define RST_PIN 4 35 | #define INT_PIN 7 36 | 37 | boolean forceDataMessage = false; 38 | 39 | // called when packet received from node 40 | // IMPORTANT! 41 | // Waight for 1 minute to get the data after opening the iot_get_send.html - as data is dispatched every minute from server to gateways 42 | void received(uint8_t buf[], uint8_t size, int16_t rssi) 43 | { 44 | 45 | // is there enough data 46 | if (size >= 1) 47 | { 48 | switch (buf[0]) 49 | { 50 | case 1 : 51 | { 52 | Serial.println("Open Door"); 53 | DOOR_LOCK_OPEN(); 54 | break; 55 | }; 56 | case 2 : 57 | { 58 | Serial.println("Light ON"); 59 | LIGHT_ON(); 60 | forceDataMessage = true; 61 | break; 62 | }; 63 | case 3 : 64 | { 65 | Serial.println("Light OFF"); 66 | forceDataMessage = true; 67 | LIGHT_OFF(); 68 | break; 69 | }; 70 | 71 | } 72 | 73 | } 74 | } 75 | 76 | 77 | // make sure you register in www.i4things.com and get your own device ID - 78 | // the key(private key) - is random bytes choose by you - they need to be the same here and in the iot_get_send.html file) 79 | // you also need to set the network key in the iot_get_send.html - which can be obtained when creating new node in the www.i4things.com client area 80 | // in node details 81 | 82 | #define thing_id 18 83 | uint8_t key[16] = {77, 2, 3, 3, 41, 5, 6, 7, 88, 9, 10, 11, 12, 13, 114, 15}; 84 | IoTThing thing(CS_PIN, INT_PIN, RST_PIN, key, thing_id, received); 85 | 86 | 87 | // 2 minutes 88 | #define MESSAGE_INTERVAL 20000 89 | uint32_t MESSAGE_LAST_SEND; 90 | 91 | 92 | 93 | void setup() 94 | { 95 | Serial.begin(115200); 96 | 97 | MESSAGE_LAST_SEND = millis() + MESSAGE_INTERVAL * 2; 98 | 99 | // Initial delay to give chance to the com port to cennect 100 | delay(2000); 101 | 102 | // Radio 103 | thing.init(); 104 | 105 | //Timestamp 106 | TIMESTAMP_INIT(); 107 | 108 | //DHT (temp/Moist) 109 | DHT_INIT(); 110 | 111 | //Door Lock 112 | DOOR_LOCK_INIT(); 113 | 114 | //Light 115 | LIGHT_INIT(); 116 | 117 | //Door Sensor 118 | DOOR_SENSOR_INIT(); 119 | 120 | } 121 | 122 | 123 | /////////////////////////////////////////////////////////////////////////////////// 124 | // MAIN LOOP 125 | 126 | void loop() 127 | { 128 | TIMESTAMP_WORK(); 129 | 130 | DHT_WORK(); 131 | 132 | DOOR_LOCK_WORK(); 133 | 134 | DOOR_SENSOR_WORK(); 135 | 136 | LIGHT_WORK(); 137 | 138 | thing.work(); 139 | 140 | // try send message every 2 min 141 | if ((((uint32_t)(((uint32_t)millis()) - MESSAGE_LAST_SEND)) >= MESSAGE_INTERVAL ) || forceDataMessage) 142 | { 143 | MESSAGE_LAST_SEND = millis(); 144 | 145 | uint8_t msg[IoTThing_MAX_MESSAGE_LEN]; 146 | uint8_t msg_size = 0; 147 | 148 | msg[msg_size++] = (int8_t)DHT_TEMP_GET(); 149 | msg[msg_size++] = DHT_HUM_GET(); 150 | msg[msg_size++] = IS_LIGHT_ON() ? 1 : 0; 151 | msg[msg_size++] = IS_DOOR_OPEN() ? 1 : 0; 152 | 153 | 154 | thing.add_uint(msg, msg_size, GET_DOOR_SENSOR_LAST_OPEN()); 155 | 156 | thing.add_uint(msg, msg_size, GET_DOOR_SENSOR_LAST_CLOSE()); 157 | 158 | 159 | for (int i = 0; i < msg_size; i++) 160 | { 161 | Serial.println(msg[i]); 162 | } 163 | 164 | // check if IoT layer is ready to accept new message 165 | if (thing.is_ready()) 166 | { 167 | thing.send(msg, msg_size); 168 | } 169 | else 170 | { 171 | // cancel previouse work and send new message 172 | thing.cancel(); 173 | thing.send(msg, msg_size); 174 | } 175 | 176 | forceDataMessage = false; 177 | 178 | } 179 | 180 | yield(); 181 | } 182 | 183 | 184 | 185 | 186 | -------------------------------------------------------------------------------- /examples/Feather32u4/Tester/thing/thing.ino: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | 16 | /////////////////////////////////////////////////////////////////////////////////// 17 | // THING LIB 18 | 19 | #include "IoTThing.h" 20 | 21 | //Feather32u2 Lora PINS 22 | #define CS_PIN 8 23 | #define RST_PIN 4 24 | #define INT_PIN 7 25 | #define LED_PIN LED_BUILTIN 26 | 27 | // make sure you register in www.i4things.com and get your own device ID - 28 | // the key(private key) - is random bytes choose by you - they need to be the same here and in the iot_get_send.html file) 29 | // you also need to set the network key in the iot_get_send.html - which can be obtained when creating new node in the www.i4things.com client area 30 | // in node details 31 | 32 | #define thing_id 14 33 | uint8_t key[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 34 | IoTThing thing(CS_PIN, INT_PIN, RST_PIN, key, thing_id); 35 | 36 | 37 | /////////////////////////////////////////////////////////////////////////////////// 38 | // LED FLASH 39 | 40 | #define LED_FLASH_INTERVAL 1000 41 | 42 | #define LED_OFF 0 43 | #define LED_ON 1 44 | #define LED_FLASHING 2 45 | 46 | uint8_t LED_STATE; 47 | uint8_t LED_LAST; 48 | uint32_t LED_LAST_WORK; 49 | 50 | 51 | void led_work() { 52 | if (((uint32_t)(((uint32_t)millis()) - LED_LAST_WORK)) >= LED_FLASH_INTERVAL) { 53 | LED_LAST_WORK = millis(); 54 | switch (LED_STATE) { 55 | case 0 : { 56 | if (LED_LAST != 0) { 57 | digitalWrite(LED_PIN, LOW); 58 | LED_LAST = 0; 59 | Serial.println("OFF"); 60 | } 61 | }; break; 62 | case 1 : { 63 | if (LED_LAST != 1) { 64 | digitalWrite(LED_PIN, HIGH); 65 | LED_LAST = 1; 66 | Serial.println("ON"); 67 | } 68 | }; break; 69 | case 2 : { 70 | if (LED_LAST == 0) { 71 | digitalWrite(LED_PIN, HIGH); 72 | LED_LAST = 1; 73 | Serial.println("ON"); 74 | } 75 | else { 76 | digitalWrite(LED_PIN, LOW); 77 | LED_LAST = 0; 78 | Serial.println("OFF"); 79 | } 80 | }; break; 81 | } 82 | } 83 | } 84 | 85 | /////////////////////////////////////////////////////////////////////////////////// 86 | // CALLBACKS 87 | 88 | void ack_callback(int16_t rssi) { 89 | LED_STATE = LED_ON; 90 | Serial.println("ACK"); 91 | } 92 | 93 | void timeout_callback(uint16_t timeout) { 94 | LED_STATE = LED_FLASHING; 95 | Serial.println("TOMEOUT"); 96 | } 97 | 98 | // 2 minutes 99 | #define MESSAGE_INTERVAL 120000 100 | uint32_t MESSAGE_LAST_SEND; 101 | 102 | void setup() { 103 | // make sure we send a messae imediatly after start 104 | MESSAGE_LAST_SEND = millis() + MESSAGE_INTERVAL * 2; 105 | 106 | // init serial 107 | Serial.begin(115200); 108 | // Initial delay to give chance to the com port to cennect 109 | delay(2000); 110 | 111 | // thing init 112 | thing.init(); 113 | 114 | //LED flashing 115 | pinMode(LED_PIN, OUTPUT); 116 | digitalWrite(LED_PIN, HIGH); 117 | LED_STATE = LED_ON; 118 | LED_LAST = 1; 119 | Serial.println("ON"); 120 | LED_LAST_WORK = millis(); 121 | thing.register_timeout(timeout_callback); 122 | thing.register_ack(ack_callback); 123 | } 124 | 125 | 126 | /////////////////////////////////////////////////////////////////////////////////// 127 | // MAIN LOOP 128 | 129 | void loop() { 130 | led_work(); 131 | thing.work(); 132 | 133 | // try send message every 2 min 134 | if (((uint32_t)(((uint32_t)millis()) - MESSAGE_LAST_SEND)) >= MESSAGE_INTERVAL) { 135 | MESSAGE_LAST_SEND = millis(); 136 | 137 | uint8_t msg[IoTThing_MAX_MESSAGE_LEN]; 138 | 139 | msg[0] = random(30); // e.g. temp 140 | msg[1] = random(50, 90); // e.g. humidity 141 | 142 | // log what we send 143 | Serial.println("Sending data : "); 144 | for (int i = 0; i < 2; i++) { 145 | Serial.println(msg[i]); 146 | } 147 | 148 | LED_STATE = LED_OFF; 149 | // check if IoT layer is ready to accept new message 150 | if (thing.is_ready()) { 151 | thing.send(msg, 2); 152 | } 153 | else { 154 | // cancel previouse work and send new message 155 | thing.cancel(); 156 | thing.send(msg, 2); 157 | } 158 | } 159 | 160 | 161 | 162 | yield(); 163 | } 164 | 165 | 166 | 167 | 168 | -------------------------------------------------------------------------------- /examples/Feather32u4/DHT22/thing/read_temp_hum.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

6 | 7 |

8 | 9 | 10 | 11 | 12 | 13 | 104 | 105 | 139 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /examples/WEMOS/Garage/thing/iot_get_send.html: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 52 | 53 | 54 |
Relay ChannelOnOffStateReload State
Open/Close Door 35 |
Fan
Data
55 | 56 | 57 | 58 | 59 | 60 | 100 | 101 | 175 | 176 | 177 | 178 | -------------------------------------------------------------------------------- /examples/ESP32/HELTEC/SendAndReceive/thing/iot_get_send.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

5 | 6 |

7 | 8 |

9 | 10 | 11 | 12 | 13 | 14 | 83 | 84 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /examples/ESP32/TTGO/SendAndReceive/thing/iot_get_send.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

5 | 6 |

7 | 8 |

9 | 10 | 11 | 12 | 13 | 14 | 83 | 84 | 142 | 143 | 144 | 145 | -------------------------------------------------------------------------------- /examples/Feather32u4/SendAndReceive/thing/iot_get_send.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

5 | 6 |

7 | 8 |

9 | 10 | 11 | 12 | 13 | 14 | 83 | 84 | 142 | 143 | 144 | 145 | -------------------------------------------------------------------------------- /examples/WEMOS/Garage/thing/thing_relay_fan.h: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | // Relay fan modulle managment 16 | // 17 | 18 | // last 2.5h = 150min 19 | #define RELAY_FAN_LAST_SIZE 150 20 | // how many minutes is required to be off from the 150 min 21 | #define RELAY_FAN_REQUIRED_OFF 30 22 | uint8_t RELAY_FAN_LAST[RELAY_FAN_LAST_SIZE]; 23 | 24 | // 1 minute in millis 25 | #define RELAY_FAN_1_MIN (1000 * 60) 26 | uint32_t RELAY_FAN_LAST_CALC; 27 | 28 | uint32_t RELAY_FAN_TIMEOUT; 29 | uint32_t RELAY_FAN_ON_START; 30 | 31 | //RELAY_FAN_REQUIRED_OFF minuutes in millis 32 | #define RELAY_FAN_FORCED_OFF_TIMEOUT (1000 * 60 * RELAY_FAN_REQUIRED_OFF) 33 | 34 | // o - not forced - 1 forced off 35 | uint8_t RELAY_FAN_FORCED_OFF; 36 | uint32_t RELAY_FAN_FORCED_OFF_START; 37 | 38 | 39 | // one minute in millis 40 | #define RELAY_FAN_MIN_ON_TIME (1000 * 60) 41 | 42 | // 2h in millis 43 | #define RELAY_FAN_MAX_ON_TIME (1000 * 60 * 120) 44 | 45 | inline void RELAY_FAN_init() 46 | { 47 | RELAY_FAN_STATE = 0; 48 | RELAY_FAN_FORCED_OFF = 0; 49 | 50 | pinMode(RELAY_FAN_PIN, OUTPUT); 51 | digitalWrite(RELAY_FAN_PIN, LOW); 52 | 53 | memset(RELAY_FAN_LAST, 0, RELAY_FAN_LAST_SIZE); 54 | RELAY_FAN_LAST_CALC = millis(); 55 | } 56 | 57 | // true if the requreed time been off is achieved - e.g. 30 min off every 2 hours 58 | inline bool RELAY_FAN_ON_check() 59 | { 60 | bool ret = false; 61 | uint16_t on_minutes = 0; 62 | for (uint16_t i = 0; i < RELAY_FAN_LAST_SIZE; i++ ) 63 | { 64 | on_minutes += RELAY_FAN_LAST[i]; 65 | } 66 | if ((RELAY_FAN_LAST_SIZE - on_minutes) >= RELAY_FAN_REQUIRED_OFF) 67 | { 68 | ret = true; 69 | } 70 | return ret; 71 | } 72 | 73 | inline bool RELAY_FAN_off() 74 | { 75 | bool ret = false; 76 | if (RELAY_FAN_STATE == 1) 77 | { 78 | RELAY_FAN_STATE = 0; 79 | digitalWrite(RELAY_FAN_PIN, LOW); 80 | 81 | Serial.println("FAN : OFF"); 82 | 83 | ret = true; 84 | } 85 | else 86 | { 87 | Serial.println("FAN : ALREADY OFF"); 88 | } 89 | return ret; 90 | } 91 | 92 | // switch releay ON for timeout in millis 93 | inline bool RELAY_FAN_on(uint32_t timeout = RELAY_FAN_MAX_ON_TIME) 94 | { 95 | bool ret = false; 96 | if (RELAY_FAN_STATE == 0) 97 | { // we are not allowed to get on if in forced off state 98 | if (RELAY_FAN_FORCED_OFF == 0) 99 | { 100 | if (RELAY_FAN_ON_check()) 101 | { 102 | // make sure the timeout is between min and max on time 103 | if (timeout < RELAY_FAN_MIN_ON_TIME) 104 | { 105 | timeout = RELAY_FAN_MIN_ON_TIME; 106 | } 107 | else if (timeout > RELAY_FAN_MAX_ON_TIME) 108 | { 109 | timeout = RELAY_FAN_MAX_ON_TIME; 110 | } 111 | 112 | RELAY_FAN_STATE = 1; 113 | 114 | RELAY_FAN_TIMEOUT = timeout; 115 | RELAY_FAN_ON_START = millis(); 116 | 117 | digitalWrite(RELAY_FAN_PIN, HIGH); 118 | 119 | Serial.print("FAN : ON ["); Serial.print(timeout); Serial.println("]"); 120 | 121 | ret = true; 122 | } 123 | else 124 | { 125 | Serial.println("FAN : CANNOT BE SWITCHED ON - TOO MUCH RINUNG"); 126 | } 127 | } 128 | else 129 | { 130 | Serial.println("FAN : CANNOT BE SWITCHED ON - IN FORCE OFF"); 131 | } 132 | } 133 | else 134 | { 135 | Serial.println("FAN : ALREADY OFF"); 136 | } 137 | return ret; 138 | } 139 | 140 | inline bool RELAY_FAN_work() 141 | { 142 | bool ret = false; 143 | 144 | if (((uint32_t)(((uint32_t)millis()) - RELAY_FAN_LAST_CALC)) >= RELAY_FAN_1_MIN) 145 | { 146 | RELAY_FAN_LAST_CALC = millis(); 147 | // update on/off history 148 | memmove(RELAY_FAN_LAST, &RELAY_FAN_LAST[1], RELAY_FAN_LAST_SIZE - 1); 149 | RELAY_FAN_LAST[RELAY_FAN_LAST_SIZE - 1] = RELAY_FAN_STATE; 150 | Serial.println("FAN : ADD LAST MINUTE TO HISTORY"); 151 | 152 | // chek if we have run for too much for last period and need to switch of for a while 153 | if (RELAY_FAN_STATE == 1) 154 | { 155 | if (!RELAY_FAN_ON_check()) 156 | { 157 | // yes we need to switch off - make sure we switch off for at least the required period 158 | RELAY_FAN_off(); 159 | RELAY_FAN_FORCED_OFF = 1; 160 | RELAY_FAN_FORCED_OFF_START = millis(); 161 | 162 | Serial.println("FAN : TOO MUCH RINUNG - SWITCHED OFF"); 163 | 164 | ret = true; 165 | } 166 | } 167 | } 168 | 169 | if (RELAY_FAN_STATE == 1) 170 | { 171 | // check when to switch it off 172 | if (((uint32_t)(((uint32_t)millis()) - RELAY_FAN_ON_START)) >= RELAY_FAN_TIMEOUT) 173 | { 174 | // yep gone switch off 175 | RELAY_FAN_off(); 176 | 177 | Serial.println("FAN : REQUIRED RINUNG PERIOD PASSED - SWITCHED OFF"); 178 | 179 | ret = true; 180 | } 181 | } 182 | 183 | if (RELAY_FAN_FORCED_OFF == 1) 184 | { 185 | // check is forced off time passed 186 | if (((uint32_t)(((uint32_t)millis()) - RELAY_FAN_FORCED_OFF_START)) >= RELAY_FAN_FORCED_OFF_TIMEOUT) 187 | { 188 | // yep - get out of forced off and enable on again 189 | RELAY_FAN_FORCED_OFF = 0; 190 | 191 | Serial.println("FAN : REQUIRED FORCED OFF PERIOD PASSED - SWITCH ON ALLOWED"); 192 | } 193 | } 194 | 195 | return ret; 196 | } 197 | -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/thing.ino: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | // FOR LCH RELAY MODULE 16 | //#define LCH 17 | 18 | // FOR SONOFF 19 | //#define SONOFF 20 | 21 | // FOR TYWE2S 22 | #define TYWE2S 23 | 24 | uint8_t RELAY1_STATE; // 0-OFF 1-ON 25 | 26 | #if defined(LCH) 27 | //ESP8266-01 1 CHANNEL RELAYY 28 | // relay,0,1 = A0 01 01 A2 29 | // relay,0,0 = A0 01 00 A1 30 | #define RELEAY_COMMAND_SIZE 4 31 | 32 | uint8_t RELAY1_ON[RELEAY_COMMAND_SIZE] = { 0xA0, 0x01, 0x01, 0xA2}; 33 | uint8_t RELAY1_OFF[RELEAY_COMMAND_SIZE] = { 0xA0, 0x01, 0x00, 0xA1}; 34 | #endif 35 | 36 | #if defined(SONOFF) 37 | #define RELAY_PIN 12 38 | #define LED_PIN 13 39 | #define BUTTON_PIN 0 40 | uint8_t BUTTON_DOWN; // 0 - UP , 1 - DOWN 41 | #define BUTTON_TIMEOUT 100 42 | uint32_t BUTTON_LAST_EXECUTE; 43 | #endif 44 | 45 | #if defined(TYWE2S) 46 | #define RELAY_PIN 12 47 | #define LED_PIN 4 48 | #define BUTTON_PIN 13 49 | uint8_t BUTTON_DOWN; // 0 - UP , 1 - DOWN 50 | #define BUTTON_TIMEOUT 100 51 | uint32_t BUTTON_LAST_EXECUTE; 52 | // define sonoff as everything else is the same 53 | #define SONOFF 54 | #endif 55 | 56 | /////////////////////////////////////////////////////////////////////////////////// 57 | // THING LIB 58 | #include "IoTThing.h" 59 | 60 | // make sure you register in www.i4things.com and get your own device ID - 61 | // the key(private key) - is random bytes choose by you - they need to be the same here and in the iot_get_send.html file) 62 | // also for the wifi API you need to register a gateway for every node and fill gateway ID and gateway KEY 63 | // you also need to set the network key in the iot_get_send.html - which can be obtained when creating new node in the www.i4things.com client area 64 | // in node details 65 | 66 | 67 | bool FORCE_DATA_MESSAGE; 68 | 69 | // called when packet received from node 70 | void received(uint8_t buf[], uint8_t size, int16_t rssi) 71 | { 72 | // is there enough data 73 | if (size >= 1) 74 | { 75 | switch (buf[0]) 76 | { 77 | case 0 : 78 | { 79 | // OFF 80 | RELAY1_STATE = 0; 81 | #if defined(LCH) 82 | for (uint8_t i = 0; i < RELEAY_COMMAND_SIZE; i++) 83 | { 84 | Serial.write(RELAY1_OFF[i]); 85 | } 86 | #endif 87 | #if defined(SONOFF) 88 | digitalWrite(RELAY_PIN, LOW); 89 | digitalWrite(LED_PIN, HIGH); 90 | #endif 91 | FORCE_DATA_MESSAGE = true; 92 | break; 93 | } 94 | case 1 : 95 | { 96 | // ON 97 | RELAY1_STATE = 1; 98 | #if defined(LCH) 99 | for (uint8_t i = 0; i < RELEAY_COMMAND_SIZE; i++) 100 | { 101 | Serial.write(RELAY1_ON[i]); 102 | } 103 | #endif 104 | #if defined(SONOFF) 105 | digitalWrite(RELAY_PIN, HIGH); 106 | digitalWrite(LED_PIN, LOW); 107 | #endif 108 | FORCE_DATA_MESSAGE = true; 109 | break; 110 | } 111 | 112 | } 113 | 114 | } 115 | } 116 | 117 | #define gateway_id 4172 118 | #define gateway_key "6869376AF0D54449C1C22ED5BBA2A18F" 119 | 120 | #define ssid "PLUSNET-7F63NX" 121 | #define pass "4e3acd6a4f" 122 | 123 | #define thing_id 37 124 | 125 | uint8_t thing_key[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 126 | IoTThing thing(ssid, pass, thing_id, thing_key, gateway_id, gateway_key, received); 127 | 128 | 129 | void setup() 130 | { 131 | #if defined(LCH) 132 | // init serial 133 | Serial.begin(9600); 134 | // Initial delay to give chance to the com port to connect 135 | delay(2000); 136 | #endif 137 | 138 | #if defined(SONOFF) 139 | pinMode(RELAY_PIN, OUTPUT); 140 | digitalWrite(RELAY_PIN, LOW); 141 | 142 | pinMode(LED_PIN, OUTPUT); 143 | digitalWrite(LED_PIN, HIGH); 144 | 145 | pinMode(BUTTON_PIN, INPUT); 146 | BUTTON_LAST_EXECUTE = millis(); 147 | BUTTON_DOWN = 0; 148 | #endif 149 | // init request to send data messsage 150 | FORCE_DATA_MESSAGE = true; 151 | // initt state 152 | RELAY1_STATE = 0; 153 | // thing init 154 | thing.init(); 155 | } 156 | 157 | 158 | /////////////////////////////////////////////////////////////////////////////////// 159 | // MAIN LOOP 160 | 161 | void loop() 162 | { 163 | #if defined(SONOFF) 164 | //deal with the button ( as a manual switch) 165 | if (((uint32_t)(((uint32_t)millis()) - BUTTON_LAST_EXECUTE)) >= BUTTON_TIMEOUT) 166 | { 167 | BUTTON_LAST_EXECUTE = millis(); 168 | if (digitalRead(BUTTON_PIN) == LOW) 169 | { 170 | BUTTON_DOWN = 1; 171 | } 172 | else 173 | { 174 | if (BUTTON_DOWN == 1) 175 | { 176 | // button released toggle relay 177 | if (RELAY1_STATE == 1) 178 | { 179 | RELAY1_STATE = 0; 180 | digitalWrite(RELAY_PIN, LOW); 181 | digitalWrite(LED_PIN, HIGH); 182 | } 183 | else 184 | { 185 | RELAY1_STATE = 1; 186 | digitalWrite(RELAY_PIN, HIGH); 187 | digitalWrite(LED_PIN, LOW); 188 | } 189 | FORCE_DATA_MESSAGE = true; 190 | } 191 | BUTTON_DOWN = 0; 192 | } 193 | } 194 | #endif 195 | 196 | // check if send message is required 197 | if (FORCE_DATA_MESSAGE) 198 | { 199 | FORCE_DATA_MESSAGE = false; 200 | 201 | uint8_t msg[IoTThing_MAX_MESSAGE_LEN]; 202 | uint8_t msg_size = 0; 203 | 204 | msg[msg_size++] = RELAY1_STATE; 205 | 206 | // check if IoT layer is ready to accept new message 207 | if (thing.is_ready()) 208 | { 209 | thing.send(msg, msg_size); 210 | } 211 | else 212 | { 213 | // cancel previouse work and send new message 214 | thing.cancel(); 215 | thing.send(msg, msg_size); 216 | } 217 | 218 | } 219 | 220 | thing.work(); 221 | 222 | yield(); 223 | } 224 | -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/iot_get.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

6 | 7 | 8 |

9 | 10 | 11 |

12 | 13 | 14 | 15 | 16 | 17 | 115 | 116 | 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY_RESTART/thing/iot_get.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

6 | 7 | 8 |

9 | 10 | 11 |

12 | 13 | 14 | 15 | 16 | 17 | 115 | 116 | 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /examples/ESP32/ULP/LoRA/thing/iot_get.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

6 | 7 | 8 |

9 | 10 | 11 |

12 | 13 | 14 | 15 | 16 | 17 | 115 | 116 | 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /examples/ESP32/ULP/WiFi/thing/iot_get.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

6 | 7 | 8 |

9 | 10 | 11 |

12 | 13 | 14 | 15 | 16 | 17 | 115 | 116 | 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /gprs_api/thing/iot_send.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

6 | 7 |

8 | 9 | 10 |

11 | 12 | 13 |

14 | 15 | 16 | 17 | 18 | 19 | 117 | 118 | 186 | 187 | 188 | 189 | -------------------------------------------------------------------------------- /gprs_api/thing/iot_get_send.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

6 | 7 |

8 | 9 | 10 |

11 | 12 | 13 |

14 | 15 | 16 | 17 | 18 | 19 | 117 | 118 | 186 | 187 | 188 | 189 | -------------------------------------------------------------------------------- /wifi_api/thing/iot_get_send.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

6 | 7 |

8 | 9 | 10 |

11 | 12 | 13 |

14 | 15 | 16 | 17 | 18 | 19 | 117 | 118 | 186 | 187 | 188 | 189 | -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY/thing/README.md: -------------------------------------------------------------------------------- 1 | 2 | * IF YOU WANT TO USE VOICE CONTROL - Please read : How_To_Siri.pdf 3 | 4 | Download Arduino IDE: 5 | Download Arduino IDE from https://www.arduino.cc/en/Main/Software 6 | 7 | Install ESP8266 board software: 8 | Open Arduino IDE and select File ? Preferences (Arduino ? Preferences on Mac) and add the following text for field Additional Boards Manager URLs: http://arduino.esp8266.com/stable/package_esp8266com_index.json and select OK. 9 | Open Tools ? Boards... ? Boards Manager... and scroll down and click on esp8266 by ESP8266 Community. Click the Install button to download and install the latest ESP8266 board software. Select Close. 10 | 11 | Upload Sketch: 12 | Easiest way is to use "CH340 USB to ESP8266 Serial ESP-01" adapter with on-board toggle switch between UART side for serial TTL debugging and PROG for firmware programming / you can also can use any USB to TTL adapter - plenty of instructions online how to upload from Arduino IDE to ESP8266-01 board/ 13 | 14 | USB Driver : 15 | Most of the USB adapters will rrequire to installl theh following driver : https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers 16 | 17 | Arduinoo IDE Bor Settings: 18 | 19 | Board: "Generic ESP8266 Module" 20 | 21 | Upload Speed: "115200" 22 | 23 | Upload Using: "Serial" 24 | 25 | CPU Frequency: "80 MHz" 26 | 27 | Crystal Frequency: @26 MHz" 28 | 29 | Flash Size: "IM (no SPIFFS)" 30 | 31 | Flash Mode: "DOUT" 32 | 33 | Flash Frequency: "40MHz" 34 | 35 | Reset Method: "ck" 36 | 37 | Debug port: "Disabled" 38 | 39 | Debug Level: "None" 40 | 41 | IwIP Variant: "v2 Lower Memoyy" 42 | 43 | VTables: "Flash" 44 | 45 | Exceptions: "Disabled" 46 | 47 | Builtin Led: "2" 48 | 49 | Erase Flash: "Only Sketch" 50 | 51 | Port: "COM9" 52 | 53 | Get Board Info 54 | 55 | 56 | Switch the code between LCH Relay Modulle and Sonooff 57 | 58 | for LCH uncomment #define LCH and comment out the SONOFF 59 | for SONOFF uncomment #define SONOFF and comment out the LCH 60 | 61 | For All Sunoff Modules : 62 | 63 | To upload : 64 | 65 | 1. Do not plug into the USB on your computer. 66 | 67 | 2. Do not connect the Sonoff to mains power. 68 | 69 | 3. Press and hold the push button on the Sonoff board. 70 | 71 | 4. Insert the FTDI converter USB in your computer (while holding the push button). 72 | 73 | 5. After 2–3 seconds, release the push button. 74 | 75 | 76 | Do not connect AC power during the flash cable connection. 77 | 78 | Sonoff Basic: 79 | 80 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266.jpg) 81 | 82 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_PCB.jpg) 83 | 84 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_CH340G_1.jpg) 85 | 86 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_CH340G_2.jpg) 87 | 88 | 89 | Note: newer version of the Sonoff module consist of five pins below the button. Follow the image above and ignore the pin furthest to the Button. 90 | 91 | 92 | 93 | Sonoff Dual: 94 | 95 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_Dual_ESP8266.jpg) 96 | 97 | Dual GPIO0 grounded Programming the Sonoff Dual is also more difficult as the button is not connected to GPIO0 which is needed to put the ESP8266 in programming mode during power up. 98 | I suggest to solder a 4 pin header for the serial interface as shown in the image on the right (the vertical connector) and use the small inter layer VIA to ground GPIO0 using the GND pin from the button 0 and button 1 header. 99 | 100 | The 4 pin header in the middle, which is normally not present, is not needed but might be used in programming the ESP8266 as there must be a better way to get the initial code loaded ... 101 | 102 | S20 Smart Socket 103 | 104 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_Socket_ESP8266.jpg) 105 | 106 | The picture on the right, shows how to program the S20 Smart Socket powered by the FTDI USB converter. 107 | Remember that during programming the Smart Socket is NOT connected to mains. 108 | 109 | Sonoff Slampher 110 | 111 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_Slampher_1.jpg) 112 | 113 | 114 | S26 Smart Socket 115 | 116 | The s26 is quite challenging - following is a step by step picture based instructions 117 | 118 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_1.jpg) 119 | 120 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_2.jpg) 121 | 122 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_3.jpg) 123 | 124 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_4.jpg) 125 | 126 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_5.jpg) 127 | 128 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_6.jpg) 129 | 130 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_7.jpg) 131 | 132 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_8.jpg) 133 | 134 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_9.jpg) 135 | 136 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_10.jpg) 137 | 138 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_11.jpg) 139 | 140 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_12.jpg) 141 | 142 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/Sonoff_ESP8266_S26_13.jpg) 143 | 144 | Smart Lighting Base (TYWE2S) 145 | 146 | Make sure that you choose Arduino IDE board profile : Generic ESP8295 Module / 1MB (no SPIFFS) 147 | 148 | Is also a challenge - the two plastic parts are actually glued together and you need to break them apart using a screwdriver or knife. 149 | 150 | Comment out Sonoff and LCH and uncomment TYWE2S. 151 | 152 | // FOR LCH RELAY MODULE 153 | 154 | //#define LCH 155 | 156 | // FOR SONOFF 157 | 158 | //#define SONOFF 159 | 160 | // FOR TYWE2S 161 | 162 | #define TYWE2S 163 | 164 | After that follow the picture instructions below. 165 | 166 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/TYWE2S_1.jpg) 167 | 168 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/TYWE2S_2.jpg) 169 | 170 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/TYWE2S_3.jpg) 171 | 172 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/TYWE2S_4.jpg) 173 | 174 | ![Cat](https://github.com/i4things/NodeAPI/blob/master/examples/ESP8266-01/1CH_RELAY/thing/TYWE2S_5.jpg) 175 | 176 | 177 | 178 | -------------------------------------------------------------------------------- /examples/ESP8266-01/1CH_RELAY_RESTART/thing/thing.ino: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | /////////////////////////////////////////////////////////////////////////////////// 16 | // 17 | // The RESTARTER 18 | //(the idea is to check internet connectivity and if not available to restart the modem) 19 | // 20 | // Heartbeat is send every 4 minutes 21 | // and if not received acknowledge in 10 min ( from one of the two heart beats ) 22 | // e.g. two heartbeats has been missed the relay is switched OFF for 10 sec and after that ON 23 | // The button, if available e.g. in case of Sonoff or TYWE2S is used to toggle from ON to OFF and vise verse 24 | // If the relay is off for 10 sec then it will be automatically switched ON 25 | 26 | 27 | // 5min 28 | #define HEARTBEAT_TIMEOUT (1000 * 60 * 4) 29 | // time of last ack has been received e.g. communication with the server is available 30 | uint32_t LAST_HEARTBEAT_TIME; 31 | 32 | // 10min 33 | #define ACK_TIMEOUT (1000 * 60 * 10) 34 | // time of last ack has been received e.g. communication with the server is available 35 | uint32_t LAST_ACK_TIME; 36 | 37 | // 10 sec 38 | #define RELAY_OFF_TIMEOUT (1000 * 10) 39 | // time when relay has been switched off 40 | uint32_t RELAY_OFF_TIME; 41 | 42 | 43 | // FOR LCH RELAY MODULE 44 | //#define LCH 45 | 46 | // FOR SONOFF 47 | #define SONOFF 48 | 49 | // FOR TYWE2S 50 | //#define TYWE2S 51 | 52 | uint8_t RELAY1_STATE; // 0-OFF 1-ON 53 | 54 | #if defined(LCH) 55 | //ESP8266-01 1 CHANNEL RELAYY 56 | // relay,0,1 = A0 01 01 A2 57 | // relay,0,0 = A0 01 00 A1 58 | #define RELEAY_COMMAND_SIZE 4 59 | 60 | uint8_t RELAY1_ON[RELEAY_COMMAND_SIZE] = { 0xA0, 0x01, 0x01, 0xA2}; 61 | uint8_t RELAY1_OFF[RELEAY_COMMAND_SIZE] = { 0xA0, 0x01, 0x00, 0xA1}; 62 | #endif 63 | 64 | #if defined(SONOFF) 65 | #define RELAY_PIN 12 66 | #define LED_PIN 13 67 | #define BUTTON_PIN 0 68 | uint8_t BUTTON_DOWN; // 0 - UP , 1 - DOWN 69 | #define BUTTON_TIMEOUT 100 70 | uint32_t BUTTON_LAST_EXECUTE; 71 | #endif 72 | 73 | 74 | #if defined(TYWE2S) 75 | #define RELAY_PIN 12 76 | #define LED_PIN 4 77 | #define BUTTON_PIN 13 78 | uint8_t BUTTON_DOWN; // 0 - UP , 1 - DOWN 79 | #define BUTTON_TIMEOUT 100 80 | uint32_t BUTTON_LAST_EXECUTE; 81 | // define sonoff as everything else is the same 82 | #define SONOFF 83 | #endif 84 | 85 | /////////////////////////////////////////////////////////////////////////////////// 86 | // THING LIB 87 | #include "IoTThing.h" 88 | 89 | // make sure you register in www.i4things.com and get your own device ID - 90 | // the key(private key) - is random bytes choose by you - they need to be the same here and in the iot_get_send.html file) 91 | // also for the wifi API you need to register a gateway for every node and fill gateway ID and gateway KEY 92 | // you also need to set the network key in the iot_get_send.html - which can be obtained when creating new node in the www.i4things.com client area 93 | // in node details 94 | 95 | 96 | inline void relay_on() 97 | { 98 | // ON 99 | RELAY1_STATE = 1; 100 | #if defined(LCH) 101 | for (uint8_t i = 0; i < RELEAY_COMMAND_SIZE; i++) 102 | { 103 | Serial.write(RELAY1_ON[i]); 104 | } 105 | #endif 106 | #if defined(SONOFF) 107 | digitalWrite(RELAY_PIN, HIGH); 108 | digitalWrite(LED_PIN, LOW); 109 | #endif 110 | } 111 | 112 | inline void relay_off() 113 | { 114 | // OFF 115 | RELAY1_STATE = 0; 116 | #if defined(LCH) 117 | for (uint8_t i = 0; i < RELEAY_COMMAND_SIZE; i++) 118 | { 119 | Serial.write(RELAY1_OFF[i]); 120 | } 121 | #endif 122 | #if defined(SONOFF) 123 | digitalWrite(RELAY_PIN, LOW); 124 | digitalWrite(LED_PIN, HIGH); 125 | // set time off for auto on after timeout 126 | RELAY_OFF_TIME = millis(); 127 | 128 | #endif 129 | } 130 | 131 | void ack_callback(int16_t rssi_) 132 | { 133 | LAST_ACK_TIME = millis(); 134 | } 135 | 136 | #define gateway_id 4172 137 | #define gateway_key "6869376AF0D54449C1C22ED5BBA2A18F" 138 | 139 | #define ssid "PLUSNET-7F63NX" 140 | #define pass "4e3acd6a4f" 141 | 142 | #define thing_id 37 143 | 144 | uint8_t thing_key[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 145 | IoTThing thing(ssid, pass, thing_id, thing_key, gateway_id, gateway_key); 146 | 147 | 148 | void setup() 149 | { 150 | #if defined(LCH) 151 | // init serial 152 | Serial.begin(9600); 153 | // Initial delay to give chance to the com port to connect 154 | delay(2000); 155 | #endif 156 | 157 | #if defined(SONOFF) 158 | pinMode(RELAY_PIN, OUTPUT); 159 | digitalWrite(RELAY_PIN, LOW); 160 | 161 | pinMode(LED_PIN, OUTPUT); 162 | digitalWrite(LED_PIN, HIGH); 163 | 164 | pinMode(BUTTON_PIN, INPUT); 165 | BUTTON_LAST_EXECUTE = millis(); 166 | BUTTON_DOWN = 0; 167 | #endif 168 | // init vars 169 | LAST_ACK_TIME = millis(); 170 | LAST_HEARTBEAT_TIME = millis(); 171 | 172 | 173 | // initt state 174 | RELAY1_STATE = 0; 175 | 176 | // thing init 177 | thing.register_ack(ack_callback); 178 | thing.init(); 179 | 180 | // switch on 181 | relay_on(); 182 | } 183 | 184 | 185 | /////////////////////////////////////////////////////////////////////////////////// 186 | // MAIN LOOP 187 | 188 | void loop() 189 | { 190 | #if defined(SONOFF) 191 | //deal with the button 192 | if (((uint32_t)(((uint32_t)millis()) - BUTTON_LAST_EXECUTE)) >= BUTTON_TIMEOUT) 193 | { 194 | BUTTON_LAST_EXECUTE = millis(); 195 | if (digitalRead(BUTTON_PIN) == LOW) 196 | { 197 | BUTTON_DOWN = 1; 198 | } 199 | else 200 | { 201 | if (BUTTON_DOWN == 1) 202 | { 203 | // button released toggle relay 204 | if (RELAY1_STATE == 1) 205 | { 206 | relay_off(); 207 | } 208 | else 209 | { 210 | relay_on(); 211 | } 212 | } 213 | BUTTON_DOWN = 0; 214 | } 215 | } 216 | #endif 217 | 218 | if (((uint32_t)(((uint32_t)millis()) - LAST_HEARTBEAT_TIME)) >= HEARTBEAT_TIMEOUT) 219 | { 220 | LAST_HEARTBEAT_TIME = millis(); 221 | 222 | uint8_t msg[IoTThing_MAX_MESSAGE_LEN]; 223 | uint8_t msg_size = 0; 224 | 225 | // just send something 226 | msg[msg_size++] = 1; 227 | 228 | // check if IoT layer is ready to accept new message 229 | if (thing.is_ready()) 230 | { 231 | thing.send(msg, msg_size); 232 | } 233 | else 234 | { 235 | // cancel previouse work and send new message 236 | thing.cancel(); 237 | thing.send(msg, msg_size); 238 | } 239 | } 240 | 241 | if (RELAY1_STATE == 0) 242 | { 243 | if (((uint32_t)(((uint32_t)millis()) - RELAY_OFF_TIME)) >= RELAY_OFF_TIMEOUT) 244 | { 245 | relay_on(); 246 | } 247 | } 248 | 249 | if (((uint32_t)(((uint32_t)millis()) - LAST_ACK_TIME)) >= ACK_TIMEOUT) 250 | { 251 | LAST_ACK_TIME = millis(); 252 | // need restart 253 | relay_off(); 254 | } 255 | 256 | 257 | thing.work(); 258 | 259 | yield(); 260 | } 261 | -------------------------------------------------------------------------------- /examples/WEMOS/Garage/thing/thing.ino: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | /////////////////////////////////////////////////////////////////////////////////// 16 | // LOG constants 17 | //#define LOG64_ENABLED 18 | // 19 | //#include 20 | 21 | //Garage example 22 | // 23 | // Scenario : Wemos, DHT22 sensor measuring temperature and humidity and 2 relays 24 | // Relay 1 is for Automatic Garage door - when Open/Close button on web page is clicked Relay 1 is ON for 2 sec 25 | // DTH22 measures temp and humidity and send it every 10 min to the server ( if different) 26 | // Relay 2 is connected to a fan 27 | // When humidity over 70% relay 2 is automatically switched ON for 2 hours cycle 28 | // When clicked on web page - "Relay 2 ON" button Relay 2 is switched ON. 29 | // When clicked on web page - "Relay 2 OFF" button Relay 2 is switched OFF. ( if humidity is > 70% it will be switched ON automatically after 10 minutes again) 30 | // Relay 2 cannot stay ON for more then 2 hours every 2.5 hours 31 | // if Relay 2 is switched OFF because max ON ( 2 hours) is reached it cannot be switched ON for the next 1/2h 32 | // 33 | // * The default pins on D1 Relay Shield and DHT Shiled cannot be used as they clash with serial interface 34 | // for logging and built-in led 35 | // Please make sure they are not connected and you have actually bridged them as described below 36 | // 37 | // DOOR Relay controling pin to D7 38 | // FAN Relay controling pin to D6 39 | // DHT data pin to D5 40 | 41 | 42 | 43 | //PINS 44 | #define RELAY_DOOR_PIN D7 45 | #define RELAY_FAN_PIN D6 46 | #define DHT_PIN D5 47 | 48 | //TRESHOLDS 49 | #define MAX_HUMIDITY 70 50 | 51 | 52 | /////////////////////////////////////////////////////////////////////////////////// 53 | // THING LIB 54 | #include "IoTThing.h" 55 | 56 | // make sure you register in www.i4things.com and get your own device ID - 57 | // the key(private key) - is random bytes choose by you - they need to be the same here and in the iot_get_send.html file) 58 | // also for the wifi API you need to register a gateway for every node and fill gateway ID and gateway KEY 59 | // you also need to set the network key in the iot_get_send.html - which can be obtained when creating new node in the www.i4things.com client area 60 | // in node details 61 | 62 | 63 | bool FORCE_DATA_MESSAGE; 64 | 65 | uint8_t RELAY_DOOR_STATE; 66 | uint8_t RELAY_FAN_STATE; 67 | uint8_t DHT_TEMP; // TEMP IN C = DHT_TEMP - 100 68 | uint8_t DHT_HUM; // 0 - 100 in % 69 | 70 | #include "thing_dht.h" 71 | #include "thing_relay_door.h" 72 | #include "thing_relay_fan.h" 73 | 74 | // called when packet received from node 75 | void received(uint8_t buf[], uint8_t size, int16_t rssi) 76 | { 77 | // is there enough data 78 | if (size >= 1) 79 | { 80 | Serial.print("CALLBACK "); Serial.println((uint16_t)buf[0]); 81 | 82 | if (buf[0] == 0) 83 | { 84 | // RELAY DOOR CLICK 85 | if (RELAY_DOOR_click()) 86 | { 87 | FORCE_DATA_MESSAGE = true; 88 | Serial.println("F0RCE MESSAGE from DOOR_click"); 89 | } 90 | } 91 | else if (buf[0] == 1) 92 | { 93 | if (RELAY_FAN_off()) 94 | { 95 | FORCE_DATA_MESSAGE = true; 96 | Serial.println("F0RCE MESSAGE from FAN_off"); 97 | } 98 | } 99 | else 100 | { 101 | // all else is FAN ON for buf[0] munutes 102 | if (RELAY_FAN_on(((uint32_t)(buf[0] - 1)) * (1000 * 60))) // convert minutes to millis 103 | { 104 | FORCE_DATA_MESSAGE = true; 105 | Serial.print("F0RCE MESSAGE from FAN_on for minutes : "); Serial.println(((uint32_t)buf[0]) - 1); 106 | } 107 | } 108 | } 109 | } 110 | 111 | #define gateway_id 4172 112 | #define gateway_key "6869376AF0D54449C1C22ED5BBA2A18F" 113 | 114 | #define ssid "PLUSNET-7F63NX" 115 | #define pass "4e3acd6a4f" 116 | 117 | #define thing_id 37 118 | 119 | uint8_t thing_key[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 120 | IoTThing thing(ssid, pass, thing_id, thing_key, gateway_id, gateway_key, received); 121 | 122 | // need to be here as thing need to be visible 123 | #include "thing_led.h" 124 | 125 | void setup() 126 | { 127 | // Serial for debug 128 | Serial.begin(115200); 129 | delay(2000); // give sometime to serial to connect 130 | 131 | // LED 132 | LED_init(); 133 | Serial.println("LED Initialized"); 134 | 135 | // init request to send data messsage 136 | FORCE_DATA_MESSAGE = true; 137 | Serial.println("FORCE MESSAGE Initialized"); 138 | 139 | // RELAY DOOR init 140 | RELAY_DOOR_init(); 141 | Serial.println("DOOR Initialized"); 142 | 143 | // RELAY FAN init 144 | RELAY_FAN_init(); 145 | Serial.println("FAN Initialized"); 146 | 147 | // DHT init 148 | DHT_init(); 149 | Serial.println("DHT Initialized"); 150 | 151 | // thing init 152 | thing.init(); 153 | Serial.println("THING Initialized"); 154 | 155 | } 156 | 157 | 158 | /////////////////////////////////////////////////////////////////////////////////// 159 | // MAIN LOOP 160 | 161 | void loop() 162 | { 163 | //keep the return bool pattern for consistency ( not used in LED module ) 164 | if (LED_work()) 165 | { 166 | // should never happened 167 | Serial.println("F0RCE MESSAGE from LED"); 168 | FORCE_DATA_MESSAGE = true; 169 | } 170 | 171 | // return true if temp is updated 172 | if (DHT_work()) 173 | { 174 | Serial.println("F0RCE MESSAGE from DHT"); 175 | FORCE_DATA_MESSAGE = true; 176 | if (DHT_HUM > MAX_HUMIDITY) 177 | { 178 | RELAY_FAN_on(); 179 | } 180 | } 181 | 182 | if (RELAY_DOOR_work()) 183 | { 184 | Serial.println("F0RCE MESSAGE from DOOR"); 185 | FORCE_DATA_MESSAGE = true; 186 | } 187 | 188 | if (RELAY_FAN_work()) 189 | { 190 | Serial.println("F0RCE MESSAGE from FAN"); 191 | FORCE_DATA_MESSAGE = true; 192 | } 193 | 194 | // check if send message is required 195 | if (FORCE_DATA_MESSAGE) 196 | { 197 | FORCE_DATA_MESSAGE = false; 198 | 199 | uint8_t msg[IoTThing_MAX_MESSAGE_LEN]; 200 | uint8_t msg_size = 0; 201 | 202 | msg[msg_size++] = RELAY_DOOR_STATE; 203 | msg[msg_size++] = RELAY_FAN_STATE; 204 | msg[msg_size++] = DHT_TEMP; 205 | msg[msg_size++] = DHT_HUM; 206 | 207 | Serial.print("DOOR :"); Serial.println((RELAY_DOOR_STATE == 1) ? "ON" : "OFF"); 208 | Serial.print("FAN :"); Serial.println((RELAY_FAN_STATE == 1) ? "ON" : "OFF"); 209 | Serial.print("TEMP :"); Serial.println((uint16_t)(DHT_TEMP - 100)); 210 | Serial.print("HUMIDITY :"); Serial.print(DHT_HUM); Serial.println("%"); 211 | 212 | // check if IoT layer is ready to accept new message 213 | if (thing.is_ready()) 214 | { 215 | thing.send(msg, msg_size); 216 | } 217 | else 218 | { 219 | // cancel previouse work and send new message 220 | thing.cancel(); 221 | thing.send(msg, msg_size); 222 | } 223 | 224 | } 225 | 226 | thing.work(); 227 | 228 | yield(); 229 | } 230 | -------------------------------------------------------------------------------- /gprs_api/thing/IoTSim800l.h: -------------------------------------------------------------------------------- 1 | /** 2 | USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 3 | OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH 4 | THE PRODUCT. 5 |

6 | IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD B2N LTD., ITS 7 | RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY 8 | CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR 9 | DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES 10 | ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR 11 | DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR 12 | DERIVED FROM THIS SOURCE CODE FILE. 13 | */ 14 | 15 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 16 | //GPRS SIM800L 17 | 18 | // CONNECT/PIN 19 | // GND -> GND 20 | // VCC -> 3.3v - 4.2V 21 | // TXD -> 21 22 | // RXD -> 13 23 | // GND -> GND 24 | 25 | // fomrat 26 | // { 27 | // {COMMAND, NULL}, 28 | // {COMMAND1, NULL}, 29 | // {RESULT1, RESULT1 ALTERNATIVE} 30 | // {RESULT2, RESULT2 ALTERNATIVE} 31 | // {RESULT3, RESULT3 ALTERNATIVE} 32 | // } 33 | // NULL means empty 34 | // 35 | // GPRS_RECEIVE_AT_INDEX need to be set to pouint the RESULT that will indicate that data is received from the TCP 36 | // GPRS_DNS_AT_INDEX need to be set to pouint the RESULT that will indicate the DNS response 37 | // GPRS_TCPSEND_RESPONSE_INDEX need to be set - as no \r or \n will be returned from the modem in this case 38 | // GPRS_SIGNAL_INDEX need to be set to pouint the GPS SIGNAL QUERY 39 | const char * GPRS_COMMAND[GPRS_STATE_LEN][4][2] = 40 | { 41 | { 42 | { "AT+CFUN=1,1", NULL}, // 0 soft reset 43 | { "OK", NULL}, 44 | { NULL, NULL}, 45 | { NULL, NULL} 46 | }, 47 | { 48 | { "ATE0", NULL}, // 1 ECHO OFF 49 | { "OK", NULL}, 50 | { NULL, NULL}, 51 | { NULL, NULL} 52 | }, 53 | { 54 | { "AT+CFUN=1", NULL}, // 2 all services 55 | { "OK", NULL}, 56 | { NULL, NULL}, 57 | { NULL, NULL} 58 | }, 59 | { 60 | { "AT+CNMI=0", NULL}, // 3 stop SMS notify 61 | { GPRS_RESPONSE_ANY, NULL}, 62 | { NULL, NULL}, 63 | { NULL, NULL} 64 | }, 65 | { 66 | { "AT+CPIN?", NULL}, // 4 query SIM card available 67 | { "+CPIN: READY", NULL}, 68 | { "OK", NULL}, 69 | { NULL, NULL} 70 | }, 71 | { 72 | { "AT+CREG?", NULL}, // 5 query registration 73 | { "+CREG: 0,1", "+CREG: 0,5"}, 74 | { "OK", NULL}, 75 | { NULL, NULL} 76 | }, 77 | { 78 | { "AT+CSQ", NULL}, // 6 query signal custom handling make sure GPRS_SIGNAL_INDEX is set to this index 79 | { "+CSQ:", NULL}, 80 | { "OK", NULL}, 81 | { NULL, NULL} 82 | }, 83 | { 84 | { "AT+CIPSHUT", NULL}, // 7 deactivate the bearer context 85 | { GPRS_RESPONSE_ANY, NULL}, 86 | { NULL, NULL}, 87 | { NULL, NULL} 88 | }, 89 | { 90 | { "AT+CSTT=\"@APN@\",\"@USER@\",\"@PASS@\"", NULL}, // 8 APN, USER, PASS 91 | { "OK", NULL}, 92 | { NULL, NULL}, 93 | { NULL, NULL} 94 | }, 95 | { 96 | { "AT+CGATT=1", NULL}, // 9 set the GPRS attach 97 | { "OK", NULL}, 98 | { NULL, NULL}, 99 | { NULL, NULL} 100 | }, 101 | { 102 | { "AT+CGATT?", NULL}, // 10 query the GPRS attach status 103 | { "+CGATT: 1", NULL}, 104 | { "OK", NULL}, 105 | { NULL, NULL} 106 | }, 107 | { 108 | { "AT+CIICR", NULL}, // 11 activate the connection 109 | { "OK", NULL}, 110 | { NULL, NULL}, 111 | { NULL, NULL} 112 | }, 113 | { 114 | { "AT+CIFSR", NULL}, // 12 query the PPP connection status 115 | { GPRS_RESPONSE_ANY, NULL}, 116 | { NULL, NULL}, 117 | { NULL, NULL} 118 | }, 119 | { 120 | { "AT+CIPQSEND=0", NULL}, // 13 Set normal mode 121 | { "OK", NULL}, 122 | { NULL, NULL}, 123 | { NULL, NULL} 124 | }, 125 | { 126 | { "AT+CIPSPRT=1", NULL}, // 14 set ">" and SEND OK 127 | { "OK", NULL}, 128 | { NULL, NULL}, 129 | { NULL, NULL} 130 | }, 131 | 132 | { 133 | { "AT+CIPSTART=\"TCP\",\"@SERVER_HOST@\",\"@SERVER_PORT@\"", NULL}, // 15 setup tcp connection 134 | { "OK", NULL}, 135 | { "CONNECT OK", NULL}, 136 | { NULL, NULL} 137 | }, 138 | { 139 | { "AT+CIPSEND=@DATA_LEN@", NULL}, // 16 tcp send (1, size) custom handling make sure GPRS_TCPSEND_RESPONSE_INDEX is set to this index 140 | { ">", NULL}, 141 | { NULL, NULL}, 142 | { NULL, NULL} 143 | }, 144 | { 145 | { "@DATA@", NULL}, // 17 data send special handling when you send the actual data you receive first " " next SEND OK next 0x0A and next the server response -- custom handling - make sure you have set GPRS_DATA_AT_INDEX to point this index 146 | { "SEND OK", NULL}, 147 | { NULL, NULL}, 148 | { NULL, NULL} 149 | }, 150 | { 151 | { NULL, NULL}, // 18 data receive - custom handling - make sure you have set GPRS_RECEIVE_AT_INDEX to point this index 152 | { NULL, NULL}, 153 | { NULL, NULL}, 154 | { NULL, NULL} 155 | }, 156 | { 157 | { "AT+CIPCLOSE=0", NULL}, // 19 tcp close 158 | { "CLOSE OK", NULL}, 159 | { NULL, NULL}, 160 | { NULL, NULL} 161 | }, 162 | { 163 | { "AT+CGATT=0", NULL}, // 20 detach PPP 164 | { GPRS_RESPONSE_ANY, NULL}, // +PDP: DEACT ( any to handle ocasanal not allowed) 165 | { GPRS_RESPONSE_ANY, NULL}, // OK ( any to handle ocasanal not allowed) 166 | { NULL, NULL} 167 | } 168 | }; 169 | 170 | // max timeout for operation in msec 171 | uint32_t GPRS_TIMEOUT[GPRS_STATE_LEN] = 172 | { 173 | 400000, // 0 soft restart 174 | 20000, // 1 echo off 175 | 20000, // 2 all services 176 | 20000, // 3 stop sms notify 177 | 60000, // 4 query SIM card available 178 | 210000, // 5 query registration 179 | 30000, // 6 query signal 180 | 30000, // 7 deactivate the bearer context 181 | 15000, // 8 APN, USER, PASS 182 | 30000, // 9 set the GPRS attach 183 | 30000, // 10 query the GPRS attach status 184 | 60000, // 11 activate the PPP connection 185 | 30000, // 12 query the PPP connection status 186 | 15000, // 13 Set normal mode 187 | 15000, // 14 set ">" and SEND OK 188 | 30000, // 15 setup tcp connection 189 | 30000, // 16 tcp send 190 | 120000, // 17 data send 191 | 120000, // 18 data receive 192 | 30000, // 19 tcp close 193 | 30000 // 20 detach PPP 194 | }; 195 | 196 | // wait after execute the command - this will eat from the timeout - e.g. make sure the timeot is properly calculated 197 | uint32_t GPRS_TIMEOUT_BEFORE_RESULT[GPRS_STATE_LEN] = 198 | { 199 | 100000, // 0 soft restart 200 | 500, // 1 echo off 201 | 500, // 1 all services 202 | 500, // 1 stop sms noifyy 203 | 500, // 2 query SIM card available 204 | 5000, // 3 query registration 205 | 5000, // 4 query signal 206 | 500, // 5 deactivate the bearer context 207 | 5000, // 6 APN, USER, PASS 208 | 5000, // 7 set the GPRS attach 209 | 5000, // 8 query the GPRS attach status 210 | 5000, // 9 activate the PPP connection 211 | 5000, // 10 query the PPP connection status 212 | 500, // 11 Set normal mode 213 | 500, // 12 set ">" and SEND OK 214 | 1000, // 13 setup tcp connection 215 | 0, // 14 tcp send 216 | 0, // 15 data send 217 | 0, // 16 data receive 218 | 500, // 17 tcp close 219 | 500 // 18 detach PPP 220 | }; 221 | 222 | 223 | // how many times to retry a command before giving up and reset 224 | uint32_t GPRS_COMMAND_RETRY[GPRS_STATE_LEN] = 225 | { 226 | 0, // 0 soft restart 227 | 1, // 1 echo off 228 | 0, // 1 all services 229 | 0, // 1 estop sms notify 230 | 5, // 2 query SIM card available 231 | 40, // 3 query registration 232 | 5, // 4 query signal 233 | 0, // 5 deactivate the bearer context 234 | 2, // 6 APN, USER, PASS 235 | 5, // 7 set the GPRS attach 236 | 5, // 8 query the GPRS attach status 237 | 5, // 9 activate the PPP connection 238 | 5, // 10 query the PPP connection status 239 | 0, // 11 Set normal mode 240 | 0, // 12 set ">" and SEND OK 241 | 20, // 13 setup tcp connection 242 | 0, // 14 tcp send 243 | 0, // 15 data send 244 | 0, // 16 data receive 245 | 0, // 17 tcp close 246 | 0 // 18 detach PPP 247 | }; 248 | --------------------------------------------------------------------------------