Components and supplies
ESP8266 ESP-01
Through Hole Resistor, 220 kohm
Wire, Hook Up
Arduino Oplà IoT Kit
LED (generic)
Tools and machines
Soldering iron (generic)
3D Printer (generic)
Apps and platforms
Arduino IDE
Arduino IoT Cloud
Project description
Code
OplathingProperties.h
arduino
1// Code generated by Arduino IoT Cloud, DO NOT EDIT. 2 3#include <ArduinoIoTCloud.h> 4#include <Arduino_ConnectionHandler.h> 5 6const char SSID[] = SECRET_SSID; // Network SSID (name) 7const char PASS[] = SECRET_PASS; // Network password (use for WPA, or use as key for WEP) 8 9void onOnAirSignOplaChange(); 10 11bool onAirSignOpla; 12 13void initProperties(){ 14 15 ArduinoCloud.addProperty(onAirSignOpla, READWRITE, ON_CHANGE, onOnAirSignOplaChange, 1); 16 17} 18 19WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS); 20
Opla.ino
arduino
1#include <SPI.h> 2#include <WiFiNINA.h> 3#include <ArduinoHttpClient.h> 4#include "thingProperties.h" 5#include <Arduino_MKRIoTCarrier.h> 6MKRIoTCarrier carrier; 7 8struct Event { 9 String from; 10 String to; 11 String title; 12}; 13 14char server[] = "calendar.google.com"; 15String feed; 16WiFiClient client; 17int port = 443; 18 19bool firstFetch = true; 20int tick = 0; 21 22Event events[20]; 23int event_index = -1; 24int event_length = event_index + 1; 25 26CloudTime currentTime; 27 28uint32_t colorRed = carrier.leds.Color(0, 200, 0); 29uint32_t colorGreen = carrier.leds.Color(200, 0, 0); 30uint32_t colorBlue = carrier.leds.Color(0, 0, 200); 31 32bool buttonsPressed = true; 33int actual = 0; 34 35Event nomore { 36 "00:00", 37 "23:59", 38 "No more meeting" 39}; 40 41 42void loading() { 43 carrier.display.fillScreen(0x0000); 44 carrier.display.setRotation(0); 45 carrier.display.setTextWrap(true); 46 carrier.display.setTextColor(0xFFFF); 47 carrier.display.setTextSize(3); 48 carrier.display.setCursor(35, 100); 49 carrier.display.print("Loading"); 50 for (int i = 0; i < 3; i++) 51 { 52 carrier.display.print("."); 53 delay(1000); 54 } 55} 56 57void setup() { 58 Serial.begin(9600); 59 delay(1500); 60 61 initProperties(); 62 63 ArduinoCloud.begin(ArduinoIoTPreferredConnection); 64 65 setDebugMessageLevel(2); 66 ArduinoCloud.printDebugInfo(); 67 68 while (ArduinoCloud.connected() != 1) { 69 ArduinoCloud.update(); 70 delay(500); 71 } 72 73 delay(500); 74 CARRIER_CASE = true; 75 carrier.begin(); 76 carrier.display.setRotation(0); 77 events[0] = nomore; 78 event_length = 1; 79 loading(); 80} 81 82 83void sendRequestICalendarFeed() { 84 if (client.connectSSL(server, port)) { 85 String get("GET /calendar/ical/"); 86 get += SECRET_ICALENDAR; 87 get += "/basic.ics HTTP/1.1"; 88 client.println(get); 89 client.println("Host: calendar.google.com"); 90 client.println("Connection: close"); 91 client.println(); 92 Serial.println("Request sent."); 93 } 94} 95time_t parseTime(char const * time) 96{ 97 int month, day, year; 98 struct tm t = 99 { 100 0 /* tm_sec */, 101 0 /* tm_min */, 102 0 /* tm_hour */, 103 0 /* tm_mday */, 104 0 /* tm_mon */, 105 0 /* tm_year */, 106 0 /* tm_wday */, 107 0 /* tm_yday */, 108 0 /* tm_isdst */ 109 }; 110 sscanf(time, "%4d%2d%2dT*", &year, &month, &day); 111 t.tm_mon = month - 1; 112 t.tm_mday = day; 113 t.tm_year = year - 1900; 114 t.tm_isdst = -1; 115 t.tm_hour = 12; 116 117 return mktime(&t); 118} 119 120struct tm extractTime(char const * time) 121{ 122 int month, day, year, hour, minutes; 123 struct tm t = 124 { 125 0 /* tm_sec */, 126 0 /* tm_min */, 127 0 /* tm_hour */, 128 0 /* tm_mday */, 129 0 /* tm_mon */, 130 0 /* tm_year */, 131 0 /* tm_wday */, 132 0 /* tm_yday */, 133 0 /* tm_isdst */ 134 }; 135 sscanf(time, "%4d%2d%2dT%2d%2d*", &year, &month, &day, &hour, &minutes); 136 t.tm_mon = month - 1; 137 t.tm_mday = day; 138 t.tm_year = year - 1900; 139 t.tm_isdst = -1; 140 t.tm_hour = hour; 141 t.tm_min = minutes; 142 143 return t; 144} 145 146bool is_today(char const* timeStr, unsigned long localTime) { 147 unsigned long t = parseTime(timeStr); 148 bool same = abs((long)(t - localTime)) < 43200; 149 return same; 150} 151 152void load(WiFiClient client) { 153 String line; 154 String buffer = ""; 155 String key; 156 String value; 157 bool insideEvent = false; 158 bool today = false; 159 int idx = -1; 160 while (client.connected()) { 161 String line = client.readStringUntil('\ 162'); 163 if (line == "0\ ") { 164 break; 165 } 166 if (line.charAt(0) == ' ') { 167 // collecting multiline prop 168 if (buffer.length() < 100) 169 buffer += line.substring(1); 170 } else { 171 if (buffer != "") { 172 // process previous prop 173 auto m = buffer.indexOf(':'); 174 if (m == -1) 175 m = buffer.indexOf(';'); 176 key = buffer.substring(0, m); 177 value = buffer.substring(m + 1); 178 if (key.compareTo("BEGIN") == 0 && value.compareTo("VEVENT\ ") == 0) { 179 if (idx < 19){ 180 idx++; 181 } 182 insideEvent = true; 183 } else if (key.compareTo("END") == 0 && value.compareTo("VEVENT\ ") == 0) { 184 insideEvent = false; 185 if (!is_today(events[idx].from.c_str(), ArduinoCloud.getLocalTime())) { 186 idx--; 187 } 188 } else if (key.compareTo("DTSTART") == 0 && insideEvent) { 189 events[idx].from = value; 190 } else if (key.compareTo("DTEND") == 0 && insideEvent) { 191 events[idx].to = value; 192 } else if (key.compareTo("SUMMARY") == 0 && insideEvent) { 193 events[idx].title = value; 194 } 195 buffer = ""; 196 } 197 buffer = line; 198 } 199 } 200 event_length = idx + 1; 201 if (!client.connected()) { 202 client.stop(); 203 } 204} 205 206void readICalendarFeed() { 207 load(client); 208 firstFetch = false; 209} 210 211 212void prev(){ 213 actual--; 214 if (actual<0) { 215 actual = event_length - 1; 216 } 217} 218 219void next(){ 220 actual++; 221 if (actual >= event_length) { 222 actual = 0; 223 } 224} 225 226void toggle(){ 227 onAirSignOpla = !onAirSignOpla; 228} 229 230String pad(int n) { 231 return String((n >=0 && n < 10)?"0":"") + n; 232} 233 234void meeting(Event events[]){ 235 if (buttonsPressed) { 236 carrier.display.fillScreen(0x0000); 237 carrier.display.setRotation(0); 238 carrier.display.setTextWrap(true); 239 if (onAirSignOpla) { 240 carrier.display.setTextColor(ST77XX_RED); 241 } else { 242 carrier.display.setTextColor(ST77XX_WHITE); 243 } 244 carrier.display.setTextSize(2); 245 carrier.display.setCursor(85, 20); 246 carrier.display.print("On Air"); 247 248 carrier.display.setTextColor(ST77XX_ORANGE); 249 carrier.display.setCursor(40, 65); 250 carrier.display.setTextSize(2); 251 struct tm from = extractTime(events[actual].from.c_str()); 252 struct tm to = extractTime(events[actual].to.c_str()); 253 carrier.display.print(pad(from.tm_hour) + ":" + pad(from.tm_min) + " - " + pad(to.tm_hour) + ":" + pad(to.tm_min)); 254 255 carrier.display.setCursor(20, 90); 256 carrier.display.setTextColor(ST77XX_GREEN); 257 carrier.display.setTextSize(2); 258 carrier.display.print(events[actual].title); 259 260 carrier.display.setTextColor(ST77XX_WHITE); 261 carrier.display.setCursor(40, 180); 262 carrier.display.setTextSize(2); 263 carrier.display.print("Prev"); 264 265 266 carrier.display.setCursor(150, 180); 267 carrier.display.setTextSize(2); 268 carrier.display.print("Next"); 269 270 carrier.leds.setBrightness(65); 271 carrier.leds.setPixelColor(0, colorGreen); 272 if (onAirSignOpla) { 273 carrier.leds.setPixelColor(2, colorRed); 274 } else { 275 carrier.leds.setPixelColor(2, colorGreen); 276 } 277 carrier.leds.setPixelColor(4, colorGreen); 278 carrier.leds.show(); 279 buttonsPressed = false; 280 } 281 282 carrier.Buttons.update(); 283 if (carrier.Buttons.onTouchDown(TOUCH0)) { 284 prev(); 285 buttonsPressed = true; 286 } 287 if (carrier.Buttons.onTouchDown(TOUCH2)) { 288 toggle(); 289 buttonsPressed = true; 290 } 291 if (carrier.Buttons.onTouchDown(TOUCH4)) { 292 next(); 293 buttonsPressed = true; 294 } 295} 296 297 298 299void loop() { 300 if ((currentTime != 0 && firstFetch) ||(tick%5000 == 20 && !firstFetch)){ 301 Serial.println("Update meeting feed"); 302 sendRequestICalendarFeed(); 303 readICalendarFeed(); 304 } 305 ArduinoCloud.update(); 306 currentTime = ArduinoCloud.getLocalTime(); 307 if (events[0].title != nomore.title) { 308 meeting(events); 309 } else { 310 loading(); 311 } 312 delay(100); 313 tick++; 314 if (tick > 5000) { 315 tick-=5000; 316 } 317} 318 319void onOnAirSignOplaChange() { 320 buttonsPressed = true; 321}
OplathingProperties.h
arduino
thingProperties.h for Opla
1// Code generated by Arduino IoT Cloud, DO NOT EDIT. 2 3#include <ArduinoIoTCloud.h> 4#include <Arduino_ConnectionHandler.h> 5 6const char SSID[] = SECRET_SSID; // Network SSID (name) 7const char PASS[] = SECRET_PASS; // Network password (use for WPA, or use as key for WEP) 8 9void onOnAirSignOplaChange(); 10 11bool onAirSignOpla; 12 13void initProperties(){ 14 15 ArduinoCloud.addProperty(onAirSignOpla, READWRITE, ON_CHANGE, onOnAirSignOplaChange, 1); 16 17} 18 19WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS); 20
esp-onair.ino
arduino
ESP8266 code for on Air sign
1 2 3#include <ESP8266WiFi.h> 4#include "thingProperties.h" 5 6int 7 pin = 2; 8 9// in my case my router had DHCP issues for this particular ESP01 10 so I decided to assign ip statically, in your case you may not need this block with 11 call WiFi.config 12IPAddress local_IP(192, 168, 150, 5); 13IPAddress gateway(192, 14 168, 150, 1); 15IPAddress subnet(255, 255, 255, 0); 16IPAddress primaryDNS(8, 17 8, 8, 8); //optional 18IPAddress secondaryDNS(8, 8, 4, 4); //optional 19 20void 21 setup() { 22 Serial.begin(115200); 23 if (!WiFi.config(local_IP, gateway, subnet, 24 primaryDNS, secondaryDNS)) { 25 Serial.println("STA Failed to configure"); 26 27 } 28 29 30 pinMode(pin, OUTPUT); 31 32 // Defined in thingProperties.h 33 34 initProperties(); 35 36 // Connect to Arduino IoT Cloud 37 ArduinoCloud.begin(ArduinoIoTPreferredConnection); 38 39 40 /* 41 The following function allows you to obtain more information 42 43 related to the state of network and IoT Cloud connection and errors 44 the 45 higher number the more granular information you’ll get. 46 The default is 0 47 (only errors). 48 Maximum is 4 49 */ 50 setDebugMessageLevel(4); 51 ArduinoCloud.printDebugInfo(); 52} 53 54 55void 56 loop() { 57 ArduinoCloud.update(); 58 // Your code here 59 delay(1000); 60} 61 62 63 64/* 65 66 Since OnAirSign is READ_WRITE variable, onOnAirSignChange() is 67 executed every 68 time a new value is received from IoT Cloud. 69*/ 70void onOnAirSignChange() { 71 72 digitalWrite(pin, onAirSign?HIGH:LOW); 73} 74
Opla.ino
arduino
1#include <SPI.h> 2#include <WiFiNINA.h> 3#include <ArduinoHttpClient.h> 4#include "thingProperties.h" 5#include <Arduino_MKRIoTCarrier.h> 6MKRIoTCarrier carrier; 7 8struct Event { 9 String from; 10 String to; 11 String title; 12}; 13 14char server[] = "calendar.google.com"; 15String feed; 16WiFiClient client; 17int port = 443; 18 19bool firstFetch = true; 20int tick = 0; 21 22Event events[20]; 23int event_index = -1; 24int event_length = event_index + 1; 25 26CloudTime currentTime; 27 28uint32_t colorRed = carrier.leds.Color(0, 200, 0); 29uint32_t colorGreen = carrier.leds.Color(200, 0, 0); 30uint32_t colorBlue = carrier.leds.Color(0, 0, 200); 31 32bool buttonsPressed = true; 33int actual = 0; 34 35Event nomore { 36 "00:00", 37 "23:59", 38 "No more meeting" 39}; 40 41 42void loading() { 43 carrier.display.fillScreen(0x0000); 44 carrier.display.setRotation(0); 45 carrier.display.setTextWrap(true); 46 carrier.display.setTextColor(0xFFFF); 47 carrier.display.setTextSize(3); 48 carrier.display.setCursor(35, 100); 49 carrier.display.print("Loading"); 50 for (int i = 0; i < 3; i++) 51 { 52 carrier.display.print("."); 53 delay(1000); 54 } 55} 56 57void setup() { 58 Serial.begin(9600); 59 delay(1500); 60 61 initProperties(); 62 63 ArduinoCloud.begin(ArduinoIoTPreferredConnection); 64 65 setDebugMessageLevel(2); 66 ArduinoCloud.printDebugInfo(); 67 68 while (ArduinoCloud.connected() != 1) { 69 ArduinoCloud.update(); 70 delay(500); 71 } 72 73 delay(500); 74 CARRIER_CASE = true; 75 carrier.begin(); 76 carrier.display.setRotation(0); 77 events[0] = nomore; 78 event_length = 1; 79 loading(); 80} 81 82 83void sendRequestICalendarFeed() { 84 if (client.connectSSL(server, port)) { 85 String get("GET /calendar/ical/"); 86 get += SECRET_ICALENDAR; 87 get += "/basic.ics HTTP/1.1"; 88 client.println(get); 89 client.println("Host: calendar.google.com"); 90 client.println("Connection: close"); 91 client.println(); 92 Serial.println("Request sent."); 93 } 94} 95time_t parseTime(char const * time) 96{ 97 int month, day, year; 98 struct tm t = 99 { 100 0 /* tm_sec */, 101 0 /* tm_min */, 102 0 /* tm_hour */, 103 0 /* tm_mday */, 104 0 /* tm_mon */, 105 0 /* tm_year */, 106 0 /* tm_wday */, 107 0 /* tm_yday */, 108 0 /* tm_isdst */ 109 }; 110 sscanf(time, "%4d%2d%2dT*", &year, &month, &day); 111 t.tm_mon = month - 1; 112 t.tm_mday = day; 113 t.tm_year = year - 1900; 114 t.tm_isdst = -1; 115 t.tm_hour = 12; 116 117 return mktime(&t); 118} 119 120struct tm extractTime(char const * time) 121{ 122 int month, day, year, hour, minutes; 123 struct tm t = 124 { 125 0 /* tm_sec */, 126 0 /* tm_min */, 127 0 /* tm_hour */, 128 0 /* tm_mday */, 129 0 /* tm_mon */, 130 0 /* tm_year */, 131 0 /* tm_wday */, 132 0 /* tm_yday */, 133 0 /* tm_isdst */ 134 }; 135 sscanf(time, "%4d%2d%2dT%2d%2d*", &year, &month, &day, &hour, &minutes); 136 t.tm_mon = month - 1; 137 t.tm_mday = day; 138 t.tm_year = year - 1900; 139 t.tm_isdst = -1; 140 t.tm_hour = hour; 141 t.tm_min = minutes; 142 143 return t; 144} 145 146bool is_today(char const* timeStr, unsigned long localTime) { 147 unsigned long t = parseTime(timeStr); 148 bool same = abs((long)(t - localTime)) < 43200; 149 return same; 150} 151 152void load(WiFiClient client) { 153 String line; 154 String buffer = ""; 155 String key; 156 String value; 157 bool insideEvent = false; 158 bool today = false; 159 int idx = -1; 160 while (client.connected()) { 161 String line = client.readStringUntil('\n'); 162 if (line == "0\ ") { 163 break; 164 } 165 if (line.charAt(0) == ' ') { 166 // collecting multiline prop 167 if (buffer.length() < 100) 168 buffer += line.substring(1); 169 } else { 170 if (buffer != "") { 171 // process previous prop 172 auto m = buffer.indexOf(':'); 173 if (m == -1) 174 m = buffer.indexOf(';'); 175 key = buffer.substring(0, m); 176 value = buffer.substring(m + 1); 177 if (key.compareTo("BEGIN") == 0 && value.compareTo("VEVENT\ ") == 0) { 178 if (idx < 19){ 179 idx++; 180 } 181 insideEvent = true; 182 } else if (key.compareTo("END") == 0 && value.compareTo("VEVENT\ ") == 0) { 183 insideEvent = false; 184 if (!is_today(events[idx].from.c_str(), ArduinoCloud.getLocalTime())) { 185 idx--; 186 } 187 } else if (key.compareTo("DTSTART") == 0 && insideEvent) { 188 events[idx].from = value; 189 } else if (key.compareTo("DTEND") == 0 && insideEvent) { 190 events[idx].to = value; 191 } else if (key.compareTo("SUMMARY") == 0 && insideEvent) { 192 events[idx].title = value; 193 } 194 buffer = ""; 195 } 196 buffer = line; 197 } 198 } 199 event_length = idx + 1; 200 if (!client.connected()) { 201 client.stop(); 202 } 203} 204 205void readICalendarFeed() { 206 load(client); 207 firstFetch = false; 208} 209 210 211void prev(){ 212 actual--; 213 if (actual<0) { 214 actual = event_length - 1; 215 } 216} 217 218void next(){ 219 actual++; 220 if (actual >= event_length) { 221 actual = 0; 222 } 223} 224 225void toggle(){ 226 onAirSignOpla = !onAirSignOpla; 227} 228 229String pad(int n) { 230 return String((n >=0 && n < 10)?"0":"") + n; 231} 232 233void meeting(Event events[]){ 234 if (buttonsPressed) { 235 carrier.display.fillScreen(0x0000); 236 carrier.display.setRotation(0); 237 carrier.display.setTextWrap(true); 238 if (onAirSignOpla) { 239 carrier.display.setTextColor(ST77XX_RED); 240 } else { 241 carrier.display.setTextColor(ST77XX_WHITE); 242 } 243 carrier.display.setTextSize(2); 244 carrier.display.setCursor(85, 20); 245 carrier.display.print("On Air"); 246 247 carrier.display.setTextColor(ST77XX_ORANGE); 248 carrier.display.setCursor(40, 65); 249 carrier.display.setTextSize(2); 250 struct tm from = extractTime(events[actual].from.c_str()); 251 struct tm to = extractTime(events[actual].to.c_str()); 252 carrier.display.print(pad(from.tm_hour) + ":" + pad(from.tm_min) + " - " + pad(to.tm_hour) + ":" + pad(to.tm_min)); 253 254 carrier.display.setCursor(20, 90); 255 carrier.display.setTextColor(ST77XX_GREEN); 256 carrier.display.setTextSize(2); 257 carrier.display.print(events[actual].title); 258 259 carrier.display.setTextColor(ST77XX_WHITE); 260 carrier.display.setCursor(40, 180); 261 carrier.display.setTextSize(2); 262 carrier.display.print("Prev"); 263 264 265 carrier.display.setCursor(150, 180); 266 carrier.display.setTextSize(2); 267 carrier.display.print("Next"); 268 269 carrier.leds.setBrightness(65); 270 carrier.leds.setPixelColor(0, colorGreen); 271 if (onAirSignOpla) { 272 carrier.leds.setPixelColor(2, colorRed); 273 } else { 274 carrier.leds.setPixelColor(2, colorGreen); 275 } 276 carrier.leds.setPixelColor(4, colorGreen); 277 carrier.leds.show(); 278 buttonsPressed = false; 279 } 280 281 carrier.Buttons.update(); 282 if (carrier.Buttons.onTouchDown(TOUCH0)) { 283 prev(); 284 buttonsPressed = true; 285 } 286 if (carrier.Buttons.onTouchDown(TOUCH2)) { 287 toggle(); 288 buttonsPressed = true; 289 } 290 if (carrier.Buttons.onTouchDown(TOUCH4)) { 291 next(); 292 buttonsPressed = true; 293 } 294} 295 296 297 298void loop() { 299 if ((currentTime != 0 && firstFetch) ||(tick%5000 == 20 && !firstFetch)){ 300 Serial.println("Update meeting feed"); 301 sendRequestICalendarFeed(); 302 readICalendarFeed(); 303 } 304 ArduinoCloud.update(); 305 currentTime = ArduinoCloud.getLocalTime(); 306 if (events[0].title != nomore.title) { 307 meeting(events); 308 } else { 309 loading(); 310 } 311 delay(100); 312 tick++; 313 if (tick > 5000) { 314 tick-=5000; 315 } 316} 317 318void onOnAirSignOplaChange() { 319 buttonsPressed = true; 320}
thingProperties.h
arduino
ESP8266 code for on Air sign
1// Code generated by Arduino IoT Cloud, DO NOT EDIT. 2 3#include <ArduinoIoTCloud.h> 4#include <Arduino_ConnectionHandler.h> 5 6const char DEVICE_LOGIN_NAME[] = "71c3db28-b3d0-4576-8d60-083190dc4e6b"; 7 8const char SSID[] = "<Your SSID>"; // Network SSID (name) 9const char PASS[] = "<Your PASS>"; // Network password (use for WPA, or use as key for WEP) 10const char DEVICE_KEY[] = "<DEVICE KEY>"; // Secret device password 11 12void onOnAirSignChange(); 13 14bool onAirSign; 15 16void initProperties(){ 17 18 ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME); 19 ArduinoCloud.setSecretDeviceKey(DEVICE_KEY); 20 21 ArduinoCloud.addProperty(onAirSign, READWRITE, ON_CHANGE, onOnAirSignChange); 22 23} 24 25WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS); 26
OplathingProperties.h
arduino
thingProperties.h for Opla
1// Code generated by Arduino IoT Cloud, DO NOT EDIT. 2 3#include <ArduinoIoTCloud.h> 4#include <Arduino_ConnectionHandler.h> 5 6const char SSID[] = SECRET_SSID; // Network SSID (name) 7const char PASS[] = SECRET_PASS; // Network password (use for WPA, or use as key for WEP) 8 9void onOnAirSignOplaChange(); 10 11bool onAirSignOpla; 12 13void initProperties(){ 14 15 ArduinoCloud.addProperty(onAirSignOpla, READWRITE, ON_CHANGE, onOnAirSignOplaChange, 1); 16 17} 18 19WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS); 20
OplathingProperties.h
arduino
thingProperties.h for Opla
1// Code generated by Arduino IoT Cloud, DO NOT EDIT. 2 3#include <ArduinoIoTCloud.h> 4#include 5 <Arduino_ConnectionHandler.h> 6 7const char SSID[] = SECRET_SSID; // 8 Network SSID (name) 9const char PASS[] = SECRET_PASS; // Network password 10 (use for WPA, or use as key for WEP) 11 12void onOnAirSignOplaChange(); 13 14bool 15 onAirSignOpla; 16 17void initProperties(){ 18 19 ArduinoCloud.addProperty(onAirSignOpla, 20 READWRITE, ON_CHANGE, onOnAirSignOplaChange, 1); 21 22} 23 24WiFiConnectionHandler 25 ArduinoIoTPreferredConnection(SSID, PASS); 26
esp-onair.ino
arduino
ESP8266 code for on Air sign
1 2 3#include <ESP8266WiFi.h> 4#include "thingProperties.h" 5 6int pin = 2; 7 8// in my case my router had DHCP issues for this particular ESP01 so I decided to assign ip statically, in your case you may not need this block with call WiFi.config 9IPAddress local_IP(192, 168, 150, 5); 10IPAddress gateway(192, 168, 150, 1); 11IPAddress subnet(255, 255, 255, 0); 12IPAddress primaryDNS(8, 8, 8, 8); //optional 13IPAddress secondaryDNS(8, 8, 4, 4); //optional 14 15void setup() { 16 Serial.begin(115200); 17 if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) { 18 Serial.println("STA Failed to configure"); 19 } 20 21 22 pinMode(pin, OUTPUT); 23 24 // Defined in thingProperties.h 25 initProperties(); 26 27 // Connect to Arduino IoT Cloud 28 ArduinoCloud.begin(ArduinoIoTPreferredConnection); 29 30 /* 31 The following function allows you to obtain more information 32 related to the state of network and IoT Cloud connection and errors 33 the higher number the more granular information you’ll get. 34 The default is 0 (only errors). 35 Maximum is 4 36 */ 37 setDebugMessageLevel(4); 38 ArduinoCloud.printDebugInfo(); 39} 40 41 42void loop() { 43 ArduinoCloud.update(); 44 // Your code here 45 delay(1000); 46} 47 48 49 50/* 51 Since OnAirSign is READ_WRITE variable, onOnAirSignChange() is 52 executed every time a new value is received from IoT Cloud. 53*/ 54void onOnAirSignChange() { 55 digitalWrite(pin, onAirSign?HIGH:LOW); 56} 57
Downloadable files
On Air sign
On Air sign
On Air sign
On Air sign
Documentation
On Air sign box
On Air sign box
On Air sign
On Air sign
On Air sign
On Air sign
On Air sign box
On Air sign box
Comments
Only logged in users can leave comments