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: HTTPClient WIZnetInterface mbed
Fork of dweetIoExample by
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetInterface.h" 00003 #include "HTTPClient.h" 00004 00005 const char * IP_Addr = "IP Address"; 00006 const char * IP_Subnet = "IP Subnet"; 00007 const char * IP_Gateway = "IP Gateway"; 00008 unsigned char MAC_Addr[6] = {0x00,0x08,0xDC,0x12,0x34,0x56}; 00009 00010 Serial pc(USBTX, USBRX); 00011 AnalogIn CDSSensor(PC_15);//Analog A0 input. pgm5537 CDS sensor and 10k resistor. 00012 /****************** 00013 VCC A0 GND 00014 | | | 00015 | | | 00016 | | | 00017 | | | 00018 --10k-----CDS--- 00019 *******************/ 00020 00021 int main() { 00022 00023 pc.printf("Start!\r\n\r\n"); 00024 00025 EthernetInterface ethernet; 00026 00027 mbed_mac_address((char *)MAC_Addr); //Use mbed mac addres 00028 pc.baud(115200); 00029 00030 #if USE_DHCP 00031 int ret = ethernet.init(MAC_Addr); 00032 #else 00033 int ret = ethernet.init(MAC_Addr,IP_Addr,IP_Subnet,IP_Gateway); 00034 #endif 00035 if (!ret) { 00036 pc.printf("Initialized, MAC: %s\r\n", ethernet.getMACAddress()); 00037 ret = ethernet.connect(); 00038 if (!ret) { 00039 pc.printf("IP: %s, MASK: %s, GW: %s\r\n", 00040 ethernet.getIPAddress(), ethernet.getNetworkMask(), ethernet.getGateway()); 00041 } else { 00042 pc.printf("Error ethernet.connect() - ret = %d\r\n", ret); 00043 exit(0); 00044 } 00045 } else { 00046 pc.printf("Error ethernet.init() - ret = %d\r\n", ret); 00047 exit(0); 00048 } 00049 00050 char str[512] = ""; 00051 char get_msg[128] = ""; 00052 00053 /* 00054 http://dweet.io/follow/nameYouWant 00055 */ 00056 char nameYouWant[] = "nameYouWant"; 00057 while(1) 00058 { 00059 sprintf(get_msg,"http://dweet.io/dweet/for/%s?a0=%d",nameYouWant,(int)(CDSSensor.read()*1000)); 00060 HTTPClient http; 00061 00062 pc.printf("Send post message to dweet.io\r\n"); 00063 pc.printf("msg : %s\r\n",get_msg); 00064 ret = http.get(get_msg, str, sizeof(str)); 00065 if(!ret) 00066 { 00067 pc.printf("\r\nPage fetched successfully - read %d characters\r\n", strlen(str)); 00068 pc.printf("Result: %s\r\n", str); 00069 } 00070 else 00071 { 00072 pc.printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); 00073 } 00074 wait(10); 00075 } 00076 00077 }
Generated on Thu Jul 14 2022 01:19:34 by
1.7.2
