Transmit data from mbed to thingspeak using wifi module
Dependencies: HTTPClient WiflyInterface mbed
main.cpp
- Committer:
- maman95
- Date:
- 2018-02-12
- Revision:
- 0:2474e21be40b
File content as of revision 0:2474e21be40b:
#include "mbed.h" #include "WiflyInterface.h" #include "HTTPClient.h" WiflyInterface wifly(p9, p10, p30, p29, "Don", "don123456", WPA); Serial pc (USBTX, USBRX); AnalogIn moisture(p15); DigitalOut myled1(LED1); HTTPClient http; //I2C tempsensor(p28, p27); //sda, sc1 //const int addr = 0x90; //char config_t[2]; //char temp_read[2]; //float temp; int main() { wifly.init(); //Use DHCP wifly.connect(); pc.printf("\nClient IP Address is %s\n\r", wifly.getIPAddress()); float value=0; while(1) { //char buf[24]; char urlBuffer[100]; //sprintf (buf, value1); value = moisture; int value1 = (int)(value * 1000); sprintf(urlBuffer, "https://api.thingspeak.com/update?api_key=KQ8Z2C2RTE2B2FWV&field1=%d", value1); //url for update thingspeak data printf("Send to %s\r\n", urlBuffer); //http.get http.get(urlBuffer, urlBuffer, 100); wait(16); // limited by ThingSpeak's API } }