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