Dweet IO example for WIZwiki-W7500

Dependencies:   HTTPClient WIZnetInterface mbed

Fork of dweetIoExample by WIZnet

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 "EthernetInterface.h"
#include "HTTPClient.h"

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);
AnalogIn CDSSensor(PC_15);//Analog A0 input. pgm5537 CDS sensor and 10k resistor.
/******************
VCC     A0      GND
 |      |       |
 |      |       |
 |      |       |
 |      |       |
 --10k-----CDS---
*******************/

int main() {
    
    pc.printf("Start!\r\n\r\n");
    
    EthernetInterface ethernet;

    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);
    }
   
}

History

Dweet IO example In WIZwiki-W7500 default tip

2017-04-12, by cliff1 [Wed, 12 Apr 2017 00:08:18 +0000] rev 1

Dweet IO example In WIZwiki-W7500


Dweet IO example with "Wiznet W5500 Ethernet kit for IoT".

2015-05-07, by bangbh [Thu, 07 May 2015 02:19:12 +0000] rev 0

Dweet IO example with "Wiznet W5500 Ethernet kit for IoT".