for orginal PCB
Dependencies: EthernetInterface SCP1000 WebSocketClient mbed-rtos mbed
Fork of ku-make_sensor201302 by
main.cpp@5:8d05d8d98218, 2013-02-09 (annotated)
- Committer:
- kumajoi
- Date:
- Sat Feb 09 20:14:20 2013 +0000
- Revision:
- 5:8d05d8d98218
- Parent:
- 4:99410a172710
for orginal PCB
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kumajoi | 3:49cc55a3a463 | 1 | #include "mbed.h" |
kumajoi | 3:49cc55a3a463 | 2 | #include "SCP1000.h" |
kumajoi | 3:49cc55a3a463 | 3 | #include "EthernetInterface.h" |
kumajoi | 3:49cc55a3a463 | 4 | #include "Websocket.h" |
kumajoi | 3:49cc55a3a463 | 5 | |
kumajoi | 3:49cc55a3a463 | 6 | DigitalOut myled(LED1); |
kumajoi | 3:49cc55a3a463 | 7 | AnalogIn light_in(p20); |
kumajoi | 3:49cc55a3a463 | 8 | AnalogIn temp_in(p19); |
kumajoi | 3:49cc55a3a463 | 9 | AnalogIn humid_in(p18); |
kumajoi | 3:49cc55a3a463 | 10 | SCP1000 scp1000(p11,p12,p13,p14); |
kumajoi | 3:49cc55a3a463 | 11 | |
kumajoi | 3:49cc55a3a463 | 12 | |
kumajoi | 3:49cc55a3a463 | 13 | int main() |
kumajoi | 3:49cc55a3a463 | 14 | { |
kumajoi | 3:49cc55a3a463 | 15 | |
kumajoi | 4:99410a172710 | 16 | const char apikey[] = "xxxxxxxxxxxxxxxxxxxxxx"; //Change your apikey |
kumajoi | 4:99410a172710 | 17 | const char feed[]= "/feeds/00000"; //Change your feed URL |
kumajoi | 4:99410a172710 | 18 | |
kumajoi | 3:49cc55a3a463 | 19 | char cms[512]; |
kumajoi | 3:49cc55a3a463 | 20 | char recv[512]; |
kumajoi | 3:49cc55a3a463 | 21 | int token = 0; |
kumajoi | 3:49cc55a3a463 | 22 | EthernetInterface eth; |
kumajoi | 3:49cc55a3a463 | 23 | eth.init(); |
kumajoi | 3:49cc55a3a463 | 24 | eth.connect(); |
kumajoi | 3:49cc55a3a463 | 25 | wait(5); |
kumajoi | 3:49cc55a3a463 | 26 | printf("IP Address is %s\n\r", eth.getIPAddress()); |
kumajoi | 3:49cc55a3a463 | 27 | |
kumajoi | 3:49cc55a3a463 | 28 | while (1) { |
kumajoi | 3:49cc55a3a463 | 29 | Websocket ws("ws://api.cosm.com:8080/feeds/"); |
kumajoi | 3:49cc55a3a463 | 30 | ws.connect(); |
kumajoi | 3:49cc55a3a463 | 31 | if(ws.read(recv)) { |
kumajoi | 3:49cc55a3a463 | 32 | printf("rcv: %s\r\n", recv); |
kumajoi | 3:49cc55a3a463 | 33 | } |
kumajoi | 3:49cc55a3a463 | 34 | |
kumajoi | 3:49cc55a3a463 | 35 | float r_light, r_temp, r_humid, r_hpa; |
kumajoi | 3:49cc55a3a463 | 36 | float light, temp, humid, hpa; |
kumajoi | 3:49cc55a3a463 | 37 | |
kumajoi | 3:49cc55a3a463 | 38 | light = light_in; |
kumajoi | 3:49cc55a3a463 | 39 | temp = temp_in; |
kumajoi | 3:49cc55a3a463 | 40 | humid = humid_in; |
kumajoi | 3:49cc55a3a463 | 41 | hpa = scp1000.readPressure(); |
kumajoi | 3:49cc55a3a463 | 42 | |
kumajoi | 4:99410a172710 | 43 | // If you want, please change the value. |
kumajoi | 3:49cc55a3a463 | 44 | r_light = light * 3.3 * 5 / 0.013; |
kumajoi | 3:49cc55a3a463 | 45 | r_temp = temp * 3.3 * 100 - 60 - 1; |
kumajoi | 3:49cc55a3a463 | 46 | r_humid = humid * 3.3 * 100 + 2; |
kumajoi | 3:49cc55a3a463 | 47 | r_hpa = hpa / 100; |
kumajoi | 3:49cc55a3a463 | 48 | |
kumajoi | 3:49cc55a3a463 | 49 | |
kumajoi | 3:49cc55a3a463 | 50 | myled = 1; |
kumajoi | 4:99410a172710 | 51 | // If you want, change the ID, Number of digits. |
kumajoi | 5:8d05d8d98218 | 52 | 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); |
kumajoi | 3:49cc55a3a463 | 53 | |
kumajoi | 3:49cc55a3a463 | 54 | printf ("%s\r\n",cms); |
kumajoi | 3:49cc55a3a463 | 55 | token++; |
kumajoi | 3:49cc55a3a463 | 56 | int res = ws.send(cms); |
kumajoi | 3:49cc55a3a463 | 57 | myled= 0 ; |
kumajoi | 3:49cc55a3a463 | 58 | wait(5); |
kumajoi | 3:49cc55a3a463 | 59 | |
kumajoi | 3:49cc55a3a463 | 60 | if(ws.read(recv)) { |
kumajoi | 3:49cc55a3a463 | 61 | printf("rcv: %s\r\n", recv); |
kumajoi | 3:49cc55a3a463 | 62 | wait(1); |
kumajoi | 3:49cc55a3a463 | 63 | } |
kumajoi | 3:49cc55a3a463 | 64 | |
kumajoi | 3:49cc55a3a463 | 65 | ws.close(); |
kumajoi | 4:99410a172710 | 66 | // If you want, change the Interval. |
kumajoi | 3:49cc55a3a463 | 67 | wait(300); |
kumajoi | 3:49cc55a3a463 | 68 | |
kumajoi | 3:49cc55a3a463 | 69 | } |
kumajoi | 0:d368632c8662 | 70 | } |