![](/media/cache/group/WIZnet_logo_001.jpg.50x50_q85.jpg)
Dweet IO example with "Wiznet W5500 Ethernet kit for IoT".
Dependencies: HTTPClient WIZnet_Library mbed WIZnetInterface
1. WIZwiki-W7500
Prerequisite
This example is for sending data to DweetIO.
To implement this function, you need a Platform board, network Interface board.
- WIZwiki-W7500 from WIZnet (Platform board and Ethernet I/F board)
- ETC: PGM5537(CDS sensor) + 10k resistor
Hardware Configuration
WIZwiki-W7500 Pin map
Software
main.cpp
#include "mbed.h" #include "HTTPClient.h" #ifdef TARGET_LPC11U68 #include "WIZnetInterface.h" #endif #if defined(TARGET_WIZWIKI_W7500) #include "EthernetInterface.h" #endif #define USE_DHCP 0 const char * IP_Addr = "IP Address"; const char * IP_Subnet = "IP Subnet"; const char * IP_Gateway = "IP Gateway"; unsigned char MAC_Addr[6] = {0x00,0x08,0xDC,0x12,0x34,0x56}; Serial pc(USBTX, USBRX); #ifdef TARGET_LPC11U68 SPI spi(P0_9,P0_8,P1_29); WIZnetInterface ethernet(&spi,P0_2,P1_13); AnalogIn CDSSensor(P1_9);//Analog A0 input. pgm5537 CDS sensor and 10k resistor. /****************** VCC A0 GND | | | | | | | | | | | | --10k-----CDS--- *******************/ #endif #if defined(TARGET_WIZWIKI_W7500) EthernetInterface ethernet; Serial pc(USBTX, USBRX); AnalogIn CDSSensor(PC_15);//Analog A0 input. pgm5537 CDS sensor and 10k resistor. #endif 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"; 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(10); } }
2. W5500 Ethernet Kit
- Platform: LPCXpresso11U68
- Component: W5500 Ethernet kit for IoT.
- ETC: PGM5537 + 10k resistor
now, I can send data to dweet.io & freeboard.io but so simple ;).
thanks to Andr.oid Eric(http://arduino-er.blogspot.kr/2015/04/iot-experience-arduino-uno-ethernet.html)
main.cpp@3:61b01b267232, 2017-04-12 (annotated)
- Committer:
- cliff1
- Date:
- Wed Apr 12 05:03:18 2017 +0000
- Revision:
- 3:61b01b267232
- Parent:
- 2:c30d558a8e5c
Added WIZnetInterface Library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bangbh | 0:d372849df255 | 1 | #include "mbed.h" |
cliff1 | 1:f7cb96a075a8 | 2 | #include "HTTPClient.h" |
cliff1 | 1:f7cb96a075a8 | 3 | |
cliff1 | 1:f7cb96a075a8 | 4 | #ifdef TARGET_LPC11U68 |
bangbh | 0:d372849df255 | 5 | #include "WIZnetInterface.h" |
cliff1 | 1:f7cb96a075a8 | 6 | #endif |
cliff1 | 1:f7cb96a075a8 | 7 | |
cliff1 | 1:f7cb96a075a8 | 8 | #if defined(TARGET_WIZWIKI_W7500) |
cliff1 | 1:f7cb96a075a8 | 9 | #include "EthernetInterface.h" |
cliff1 | 1:f7cb96a075a8 | 10 | #endif |
bangbh | 0:d372849df255 | 11 | |
bangbh | 0:d372849df255 | 12 | #define USE_DHCP 0 |
bangbh | 0:d372849df255 | 13 | |
cliff1 | 1:f7cb96a075a8 | 14 | const char * IP_Addr = "IP Address"; |
cliff1 | 1:f7cb96a075a8 | 15 | const char * IP_Subnet = "IP Subnet"; |
cliff1 | 1:f7cb96a075a8 | 16 | const char * IP_Gateway = "IP Gateway"; |
bangbh | 0:d372849df255 | 17 | unsigned char MAC_Addr[6] = {0x00,0x08,0xDC,0x12,0x34,0x56}; |
bangbh | 0:d372849df255 | 18 | |
bangbh | 0:d372849df255 | 19 | Serial pc(USBTX, USBRX); |
bangbh | 0:d372849df255 | 20 | |
bangbh | 0:d372849df255 | 21 | #ifdef TARGET_LPC11U68 |
bangbh | 0:d372849df255 | 22 | SPI spi(P0_9,P0_8,P1_29); |
bangbh | 0:d372849df255 | 23 | WIZnetInterface ethernet(&spi,P0_2,P1_13); |
bangbh | 0:d372849df255 | 24 | AnalogIn CDSSensor(P1_9);//Analog A0 input. pgm5537 CDS sensor and 10k resistor. |
bangbh | 0:d372849df255 | 25 | /****************** |
bangbh | 0:d372849df255 | 26 | VCC A0 GND |
bangbh | 0:d372849df255 | 27 | | | | |
bangbh | 0:d372849df255 | 28 | | | | |
bangbh | 0:d372849df255 | 29 | | | | |
bangbh | 0:d372849df255 | 30 | | | | |
bangbh | 0:d372849df255 | 31 | --10k-----CDS--- |
bangbh | 0:d372849df255 | 32 | *******************/ |
bangbh | 0:d372849df255 | 33 | #endif |
bangbh | 0:d372849df255 | 34 | |
cliff1 | 1:f7cb96a075a8 | 35 | #if defined(TARGET_WIZWIKI_W7500) |
cliff1 | 2:c30d558a8e5c | 36 | EthernetInterface ethernet; |
cliff1 | 1:f7cb96a075a8 | 37 | Serial pc(USBTX, USBRX); |
cliff1 | 1:f7cb96a075a8 | 38 | AnalogIn CDSSensor(PC_15);//Analog A0 input. pgm5537 CDS sensor and 10k resistor. |
cliff1 | 1:f7cb96a075a8 | 39 | #endif |
cliff1 | 1:f7cb96a075a8 | 40 | |
cliff1 | 1:f7cb96a075a8 | 41 | |
bangbh | 0:d372849df255 | 42 | int main() { |
bangbh | 0:d372849df255 | 43 | |
bangbh | 0:d372849df255 | 44 | mbed_mac_address((char *)MAC_Addr); //Use mbed mac addres |
bangbh | 0:d372849df255 | 45 | pc.baud(115200); |
bangbh | 0:d372849df255 | 46 | #if USE_DHCP |
bangbh | 0:d372849df255 | 47 | int ret = ethernet.init(MAC_Addr); |
bangbh | 0:d372849df255 | 48 | #else |
bangbh | 0:d372849df255 | 49 | int ret = ethernet.init(MAC_Addr,IP_Addr,IP_Subnet,IP_Gateway); |
bangbh | 0:d372849df255 | 50 | #endif |
bangbh | 0:d372849df255 | 51 | if (!ret) { |
bangbh | 0:d372849df255 | 52 | pc.printf("Initialized, MAC: %s\r\n", ethernet.getMACAddress()); |
bangbh | 0:d372849df255 | 53 | ret = ethernet.connect(); |
bangbh | 0:d372849df255 | 54 | if (!ret) { |
bangbh | 0:d372849df255 | 55 | pc.printf("IP: %s, MASK: %s, GW: %s\r\n", |
bangbh | 0:d372849df255 | 56 | ethernet.getIPAddress(), ethernet.getNetworkMask(), ethernet.getGateway()); |
bangbh | 0:d372849df255 | 57 | } else { |
bangbh | 0:d372849df255 | 58 | pc.printf("Error ethernet.connect() - ret = %d\r\n", ret); |
bangbh | 0:d372849df255 | 59 | exit(0); |
bangbh | 0:d372849df255 | 60 | } |
bangbh | 0:d372849df255 | 61 | } else { |
bangbh | 0:d372849df255 | 62 | pc.printf("Error ethernet.init() - ret = %d\r\n", ret); |
bangbh | 0:d372849df255 | 63 | exit(0); |
bangbh | 0:d372849df255 | 64 | } |
bangbh | 0:d372849df255 | 65 | |
cliff1 | 1:f7cb96a075a8 | 66 | char str[512] = ""; |
bangbh | 0:d372849df255 | 67 | char get_msg[128]= ""; |
bangbh | 0:d372849df255 | 68 | |
bangbh | 0:d372849df255 | 69 | /* |
bangbh | 0:d372849df255 | 70 | http://dweet.io/follow/nameYouWant |
bangbh | 0:d372849df255 | 71 | */ |
bangbh | 0:d372849df255 | 72 | char nameYouWant[] = "nameYouWant"; |
bangbh | 0:d372849df255 | 73 | while(1) |
bangbh | 0:d372849df255 | 74 | { |
bangbh | 0:d372849df255 | 75 | sprintf(get_msg,"http://dweet.io/dweet/for/%s?a0=%d",nameYouWant,(int)(CDSSensor.read()*1000)); |
bangbh | 0:d372849df255 | 76 | HTTPClient http; |
bangbh | 0:d372849df255 | 77 | |
bangbh | 0:d372849df255 | 78 | pc.printf("Send post message to dweet.io\r\n"); |
bangbh | 0:d372849df255 | 79 | pc.printf("msg : %s\r\n",get_msg); |
bangbh | 0:d372849df255 | 80 | ret = http.get(get_msg, str, sizeof(str)); |
bangbh | 0:d372849df255 | 81 | if(!ret) |
bangbh | 0:d372849df255 | 82 | { |
bangbh | 0:d372849df255 | 83 | pc.printf("\r\nPage fetched successfully - read %d characters\r\n", strlen(str)); |
bangbh | 0:d372849df255 | 84 | pc.printf("Result: %s\r\n", str); |
bangbh | 0:d372849df255 | 85 | } |
bangbh | 0:d372849df255 | 86 | else |
bangbh | 0:d372849df255 | 87 | { |
bangbh | 0:d372849df255 | 88 | pc.printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); |
bangbh | 0:d372849df255 | 89 | } |
cliff1 | 1:f7cb96a075a8 | 90 | wait(10); |
bangbh | 0:d372849df255 | 91 | } |
bangbh | 0:d372849df255 | 92 | |
bangbh | 0:d372849df255 | 93 | } |