Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Thingspeak_template LM75B mbed-rtos EthernetInterface MMA7660
Dependents: Thingspeak_template
main.cpp
00001 #include "mbed.h" 00002 #include "HTTPClient.h" 00003 #include "LM75B.h" 00004 #include "MMA7660.h" 00005 #include "EthernetInterface.h" 00006 00007 00008 LM75B sensor(D14,D15); 00009 MMA7660 accel(PTE25 , PTE24); 00010 char buffer[256]; 00011 char resp[1024]; 00012 char val[4][16]; 00013 int ret = 0; 00014 00015 Serial pc(USBTX,USBRX); 00016 //Ethernet Interface 00017 EthernetInterface eth; 00018 //HTTP Client for interfacing to web services 00019 HTTPClient http; 00020 #define IP "184.106.153.149" // thingspeak.com IP Address 00021 00022 //http client init 00023 HTTPMap map; 00024 HTTPText inText(resp, 1024); 00025 //String thingtweetAPIKey = "TTEVLP931ODJ5GMT"; 00026 00027 00028 int main () { 00029 //ethernet init 00030 eth.init(); //Use DHCP 00031 ret= eth.connect(); 00032 00033 if (!ret){ 00034 pc.printf("\r\nConnected, IP: %s, MASK: %s, GW: %s", 00035 eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway()); 00036 } else { 00037 pc.printf("\r\nError eth.connect() - ret = %d", ret); 00038 } 00039 00040 while(1){ 00041 pc.printf("\r\nWriting to thingspeak"); 00042 map.put("api_key","xxx"); /* Fill your thingspeak API KEY*/ 00043 sprintf(val[0],"%4.1f",sensor.read()); 00044 map.put("field1", val[0]); 00045 pc.printf("\r\nPosting Data..."); 00046 ret = http.post("https://api.thingspeak.com/update", map, &inText); //writing data to Thingspeak 00047 if (!ret){ 00048 pc.printf("\r\nPOST successfully - read %d characters", strlen(resp)); 00049 pc.printf("\r\nResult: %s\n", resp); 00050 }else{ 00051 pc.printf("\r\nError Connecting to ethernet port - ret = %d - HTTP return code = %d", ret, http.getHTTPResponseCode()); 00052 } 00053 } 00054 }
Generated on Mon Aug 8 2022 20:49:56 by
1.7.2