IOT
Dependencies: EthernetInterface mbed-rtos mbed
main.cpp
- Committer:
- rohangala
- Date:
- 2015-06-15
- Revision:
- 0:9d11a3afff01
File content as of revision 0:9d11a3afff01:
#include "mbed.h" #include "EthernetInterface.h" #include "stdio.h" float lux(void) { AnalogIn ain(p15); float vr=0,lr=0; float vol[12]={0.36,0.61,0.8,0.9,1.23,1.45,1.81,2.06,2.62,2.81,3.02,3.25}; float lux[12]={27000,20000,16000,11000,4000,1500,833,578,201,104,40,23}; int i; float m=0; vr=ain*3.3; for(i=0; vr> vol[i];i++); m = ((lux[i]-lux[i+1])/(vol[i]-vol[i+1])); lr=lux[i+1]+(m*(vr-(vol[i+1]))); return vr; } #include "mbed.h" #include "EthernetInterface.h" int main() { float l=0; EthernetInterface eth; eth.init(); //Use DHCP eth.connect(); printf("IP Address is %s\n", eth.getIPAddress()); char* public_key = "wpv0ajajxXsllRZOlbn0" ; char* private_key = "wzep7E7EPDCRR0b5Rdga" ; char http_cmd[256]; for(int i=0 ; i<5 ;i++) { //char c=i; TCPSocketConnection sock; sock.connect("data.sparkfun.com", 80); l=lux(); printf("volt = %.2f",l); sprintf(http_cmd,"GET /input/%s?private_key=%s&var1=%.2f HTTP/1.0\n\n", public_key, private_key, l); //char http_cmd[] = "GET /input/wpv0ajajxXsllRZOlbn0?private_key=wzep7E7EPDCRR0b5Rdga&var1=%c HTTP/1.0\n\n",i; sock.send_all(http_cmd, sizeof(http_cmd)-1); char buffer[300]; int ret; while (true) { ret = sock.receive(buffer, sizeof(buffer)-1); if (ret <= 0) break; buffer[ret] = '\0'; printf("Received %d chars from server:\n%s\n", ret, buffer); } sock.close(); } eth.disconnect(); while(1) {} }