Test code to interface AOD UPAS with IoT provider.
Dependencies: ESP8266_AT NCP5623BMUTBG mbed ADS1115 AOD_Calculation BME280 PMS5003 SunPosition CAM_M8
main.cpp
- Committer:
- eawendtjr
- Date:
- 2017-11-22
- Revision:
- 2:3df874f33c42
- Parent:
- 1:702f144a88b2
- Child:
- 3:f878eab2ebe0
File content as of revision 2:3df874f33c42:
#include "mbed.h" #include "NCP5623BMUTBG.h" #include "ESP8266_AT.h" ///////////////////////////////////////////// //Define core buses and pin states. ///////////////////////////////////////////// I2C i2c(PB_9, PB_8);//(D14, D15); SDA,SCL Serial pc(USBTX, USBRX); DigitalOut pumps(PA_9, 0);//(D8, 0); DigitalOut pbKill(PC_12, 1); // Digital input pin that conncect to the LTC2950 battery charger used to shutdown the UPAS DigitalIn nINT(PA_15); //Connected but currently unused is a digital ouput pin from LTC2950 battery charger. http://cds.linear.com/docs/en/datasheet/295012fd.pdf NCP5623BMUTBG RGB_LED(PB_9, PB_8); //(D14, D15); ///////////////////////////////////////////// //RN4677 BT/BLE Module ///////////////////////////////////////////// Serial ble(PB_10, PB_11); DigitalOut bleRTS(PB_14, 0); DigitalOut bleCTS(PB_13, 0); DigitalOut BT_IRST(PC_8, 0); DigitalOut BT_SW(PA_12, 0); ///////////////////////////////////////////// //Analog to Digital Converter ///////////////////////////////////////////// DigitalIn ADS_ALRT(PA_10); //Connected but currently unused. (ADS1115) http://www.ti.com/lit/ds/symlink/ads1115.pdf ///////////////////////////////////////////// //Battery, Charger, & Supply Monitoring ///////////////////////////////////////////// DigitalIn LTCALT(PB_2); //High for normal operation. Low when a threshold is exceeded for Voltage, gas gauge, or temp DigitalIn bcs1(PC_9); //Batt charging if High. (BQ24100)[U23] DigitalIn bcs2(PA_8); //Charge complete if High. (BQ24100)[U23] DigitalIn bc_npg(PB_1); //Power to the charge controller. (BQ24100)[U23] DigitalIn SW3flt(PC_4); //When EN = 0 pin is HIGH, When EN = 1, LOW can be current limit, thermal limit, or UVLO. ///////////////////////////////////////////// //Sensirion SDP3X(s) ///////////////////////////////////////////// DigitalIn SDP3Xflt(PC_0); DigitalIn SDP3XAltflt(PB_7); ///////////////////////////////////////////// //Accelerometer and Magnometer ///////////////////////////////////////////// DigitalOut iNemoEnable(PA_1, 0); DigitalIn iNemoReady(PB_0); DigitalIn iNemoInt1(PC_5); DigitalIn iNemoInt2(PC_6); DigitalIn iNemoInt3(PC_7); ///////////////////////////////////////////// //UV and Visible Light Sensor ///////////////////////////////////////////// ///////////////////////////////////////////// //GPS ///////////////////////////////////////////// DigitalOut gpsEN(PB_15, 0); DigitalIn gpsENFault(PB_12); ///////////////////////////////////////////// //SD Card ///////////////////////////////////////////// DigitalIn sdCD(PA_11); DigitalOut sdClk(PB_3,0 ); DigitalIn sdMISO(PB_4); DigitalOut sdMOSI(PB_5, 0); DigitalOut sdCS(PB_6, 1); DigitalIn pbIso(PA_0); DigitalOut hFault1(PA_7, 0); DigitalOut hFault2(PA_6, 0); DigitalOut hFault3(PA_5, 0); DigitalOut hFault4(PA_4, 0); DigitalOut wifiNReset(PC_1, 0); DigitalOut wifiEnable(PC_2, 0); DigitalOut qdEnable(PC_3, 0); DigitalIn qdFault(PC_13); 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]; char aod_sel_5off[1]; char plant_sel[1]; ////////////////////////////////////////////////////////////// //Main Function ////////////////////////////////////////////////////////////// int main() { pc.baud(115200); RGB_LED.set_led(1, 0, 1); wait(1); aod_sel_5on[0] = 0xCB; aod_sel_5off[0] = 0xC9; plant_sel[0] = 0xCF; RGB_LED.set_led(1, 1, 1); i2c.write(addr, aod_sel_5off, 1); pc.printf("Plantower off\r\n"); wait(1); //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(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(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.send_data_tcp(0, someArray); esp.close_connection(0); esp.create_tcp_server(80); pc.printf("%s\r\n", someArray); } } }