Test code to interface AOD UPAS with IoT provider.
Dependencies: ESP8266_AT NCP5623BMUTBG mbed ADS1115 AOD_Calculation BME280 PMS5003 SunPosition CAM_M8
Diff: main.cpp
- Revision:
- 1:702f144a88b2
- Parent:
- 0:62df2a5864d5
- Child:
- 2:3df874f33c42
diff -r 62df2a5864d5 -r 702f144a88b2 main.cpp --- a/main.cpp Tue Nov 21 00:47:43 2017 +0000 +++ b/main.cpp Wed Nov 22 01:36:27 2017 +0000 @@ -84,6 +84,14 @@ ESP8266_AT esp(PC_10, PC_11); +Timer t; + +char ssid[] = "VOLTAR"; +char password[] = "CedhCedh"; +char server[] = "api.thingspeak.com"; +char apiKey[] = "SU35AOKAZ30E0CAX"; +char conn_type[] = "TCP"; + // For selecting the WiFi UART const int addr = 0x3F << 1; char aod_sel_5on[1]; @@ -96,50 +104,62 @@ int main() { pc.baud(115200); - RGB_LED.set_led(0.5, 0, 1); + RGB_LED.set_led(1, 0, 1); + wait(1); aod_sel_5on[0] = 0xCB; aod_sel_5off[0] = 0xC9; plant_sel[0] = 0xCF; - - wait(15); - pc.printf("Plantower on\r\n"); - RGB_LED.set_led(1, 0, 1); - wait(15); + RGB_LED.set_led(1, 1, 1); i2c.write(addr, aod_sel_5off, 1); pc.printf("Plantower off\r\n"); - - RGB_LED.set_led(1, 0, 0); - wait(15); - i2c.write(addr, aod_sel_5on, 1); - pc.printf("Plantower off - 5V on\r\n"); + wait(1); - RGB_LED.set_led(0, 0, 1); - wait(15); - i2c.write(addr, plant_sel, 1); - pc.printf("Plantower on\r\n"); - - RGB_LED.set_led(0, 1, 0); - wait(15); - i2c.write(addr, aod_sel_5off, 1); - pc.printf("Plantower off\r\n"); - - wait(15); - + //Enable the WiFi chip RGB_LED.set_led(0, 1, 1); // Light LED so we know something is happening wifiEnable = 1; // Enable power to the WiFi while in reset, and wait a short while wait_ms(100); wifiNReset = 1; // Now de-assert the reset signal RGB_LED.set_led(1, 1, 0); // Color change of LED to indicate something is happening. - wait(1); + wait(10); + + RGB_LED.set_led(0, 1, 0); + esp.check_esp(); + esp.version_info(); + esp.software_reset(); + + esp.command_echo_mode(ESP_ECHO_ON); + esp.set_wifi_mode(ESP_DUAL_CONFIG); + esp.enable_multiple_connections(); + esp.create_tcp_server(80); + + //esp.set_server_timeout(5); + + esp.list_access_points(); + esp.wifi_connect(ssid, password); + esp.check_ap(); + esp.get_ip(); + + char someArray[150]; + + t.start(); while(1) { - RGB_LED.set_led(1, 1, 1); - esp.check_esp(); - wait(1); - RGB_LED.set_led(0, 1, 0); - wait(1); + RGB_LED.set_led(0, 0, 1); + if(t.read()>30)//if 30 seconds passed + { + t.reset();//reset timer + //now send temperature value to thingspeak + //use your thingspeak channel's Write api key + sprintf(someArray,"GET https://api.thingspeak.com/update?api_key=SU35AOKAZ30E0CAX&field1=%d\r\n\r\n",rand() % 10 + 1); + + esp.delete_tcp_server(); + esp.establish_connection(0, conn_type, server, 80); + esp.create_tcp_server(80); + esp.close_connection(0); + pc.printf("%s\r\n", someArray); + } } }