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

pin map


/media/uploads/cliff1/sim.png


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

now, I can send data to dweet.io & freeboard.io but so simple ;). /media/uploads/bangbh/dweet_example.png /media/uploads/bangbh/dweet_example_connect.png /media/uploads/bangbh/dweetio.png

thanks to Andr.oid Eric(http://arduino-er.blogspot.kr/2015/04/iot-experience-arduino-uno-ethernet.html)

Files at this revision

API Documentation at this revision

Comitter:
bangbh
Date:
Thu May 07 02:19:12 2015 +0000
Child:
1:f7cb96a075a8
Commit message:
Dweet IO example with "Wiznet W5500 Ethernet kit for IoT".

Changed in this revision

HTTPClient.lib Show annotated file Show diff for this revision Revisions of this file
WIZnet_Library.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPClient.lib	Thu May 07 02:19:12 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/kaizen/code/HTTPClient/#9ba72b4d7ffc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WIZnet_Library.lib	Thu May 07 02:19:12 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/WIZnet/code/WIZnet_Library/#ca8405b9564d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu May 07 02:19:12 2015 +0000
@@ -0,0 +1,79 @@
+#include "mbed.h"
+#include "WIZnetInterface.h"
+#include "HTTPClient.h"
+
+#define USE_DHCP    0
+
+const char * IP_Addr    = "222.98.173.212";
+const char * IP_Subnet  = "255.255.255.192";
+const char * IP_Gateway = "222.98.173.254";
+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
+
+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(5);
+    }
+   
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu May 07 02:19:12 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/8ab26030e058
\ No newline at end of file