mod
Dependencies: HTTPClient WIZnetInterface mbed
Fork of dweetIo_CloudService_Helloworld_WIZwiki-W7500 by
main.cpp
- Committer:
- eunkyoungkim
- Date:
- 2015-09-14
- Revision:
- 2:4d82eafe860d
- Parent:
- 1:c212e07d1f23
- Child:
- 3:9000aa421555
File content as of revision 2:4d82eafe860d:
#include "mbed.h" #include "EthernetInterface.h" #include "HTTPClient.h" #define USE_DHCP 1 unsigned char MAC_Addr[6] = {0x00,0x08,0xDC,0x12,0x34,0x56}; char IP_Addr[] = "192.168.0.100"; char IP_Subnet[] = "255.255.255.0"; char IP_Gateway[] = "192.168.0.1"; Serial pc(USBTX, USBRX); /****************** VCC A0 GND | | | | | | | | | | | | --10k-----CDS--- *******************/ EthernetInterface ethernet; AnalogIn CDSSensor(A0); int main() { /// mbed_mac_address((char *)MAC_Addr); //Use mbed mac addres pc.baud(115200); #if USE_DHCP int ret = ethernet.init(MAC_Addr); #else int ret = ethernet.init(MAC_Addr,IP_Addr,IP_Subnet,IP_Gateway); #endif if (!ret) { pc.printf("Initialized, MAC: %s\r\n", ethernet.getMACAddress()); ret = ethernet.connect(); if (!ret) { pc.printf("IP: %s, MASK: %s, GW: %s\r\n", ethernet.getIPAddress(), ethernet.getNetworkMask(), ethernet.getGateway()); } else { pc.printf("Error ethernet.connect() - ret = %d\r\n", ret); exit(0); } } else { pc.printf("Error ethernet.init() - ret = %d\r\n", ret); exit(0); } char str[512]; char get_msg[128]= ""; /* http://dweet.io/follow/nameYouWant */ char nameYouWant[] = "nameYouWant"; //char nameYouWant[] = "sep152015test"; while(1) { sprintf(get_msg,"http://dweet.io/dweet/for/%s?a0=%d",nameYouWant,(int)(CDSSensor.read()*1000)); HTTPClient http; pc.printf("Send post message to dweet.io\r\n"); pc.printf("msg : %s\r\n",get_msg); ret = http.get(get_msg, str, sizeof(str)); if(!ret) { pc.printf("\r\nPage fetched successfully - read %d characters\r\n", strlen(str)); pc.printf("Result: %s\r\n", str); } else { pc.printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); } wait(5); } }