for orginal PCB
Dependencies: EthernetInterface SCP1000 WebSocketClient mbed-rtos mbed
Fork of ku-make_sensor201302 by
main.cpp
00001 #include "mbed.h" 00002 #include "SCP1000.h" 00003 #include "EthernetInterface.h" 00004 #include "Websocket.h" 00005 00006 DigitalOut myled(LED1); 00007 AnalogIn light_in(p20); 00008 AnalogIn temp_in(p19); 00009 AnalogIn humid_in(p18); 00010 SCP1000 scp1000(p11,p12,p13,p14); 00011 00012 00013 int main() 00014 { 00015 00016 const char apikey[] = "xxxxxxxxxxxxxxxxxxxxxx"; //Change your apikey 00017 const char feed[]= "/feeds/00000"; //Change your feed URL 00018 00019 char cms[512]; 00020 char recv[512]; 00021 int token = 0; 00022 EthernetInterface eth; 00023 eth.init(); 00024 eth.connect(); 00025 wait(5); 00026 printf("IP Address is %s\n\r", eth.getIPAddress()); 00027 00028 while (1) { 00029 Websocket ws("ws://api.cosm.com:8080/feeds/"); 00030 ws.connect(); 00031 if(ws.read(recv)) { 00032 printf("rcv: %s\r\n", recv); 00033 } 00034 00035 float r_light, r_temp, r_humid, r_hpa; 00036 float light, temp, humid, hpa; 00037 00038 light = light_in; 00039 temp = temp_in; 00040 humid = humid_in; 00041 hpa = scp1000.readPressure(); 00042 00043 // If you want, please change the value. 00044 r_light = light * 3.3 * 5 / 0.013; 00045 r_temp = temp * 3.3 * 100 - 60 - 1; 00046 r_humid = humid * 3.3 * 100 + 2; 00047 r_hpa = hpa / 100; 00048 00049 00050 myled = 1; 00051 // If you want, change the ID, Number of digits. 00052 sprintf (cms,"{\"method\" : \"put\",\"resource\" : \"%s\",\"params\" : {},\"headers\" : {\"X-ApiKey\":\"%s\"},\"body\" :{\"version\" : \"1.0.0\",\"datastreams\" : [{\"id\" : \"0\",\"current_value\" : \"%4.0f\"},{\"id\" : \"1\",\"current_value\" : \"%3.0f\"},{\"id\" : \"2\",\"current_value\" : \"%3.0f\"},{\"id\" : \"3\",\"current_value\" : \"%4.0f\"}]},\"token\" : \"0x%d\"}\r\n",feed,apikey,r_light,r_temp,r_humid,r_hpa,token); 00053 00054 printf ("%s\r\n",cms); 00055 token++; 00056 int res = ws.send(cms); 00057 myled= 0 ; 00058 wait(5); 00059 00060 if(ws.read(recv)) { 00061 printf("rcv: %s\r\n", recv); 00062 wait(1); 00063 } 00064 00065 ws.close(); 00066 // If you want, change the Interval. 00067 wait(300); 00068 00069 } 00070 }
Generated on Wed Jul 13 2022 12:51:12 by 1.7.2