MAX32620HSP | mbed

Source: MAX32620HSP | mbed

Advertisements

[WIZwiki_W7500ECO] HTTPClient with JSON parser

JSON is easy for machines to parse and generate which is based on a subset of the JavaScript Programming Language. Currently many Web Services allow to access data in JSON format. However, JSON parser is too big for low-end device as like a ARMmbed platform which has limited-resource. This post shows how to use HTTPClient parse Json data in ARMmbed platform.
IMG_20151029_165139//embedr.flickr.com/assets/client-code.js

Preparation materials

  1. Software

* JSON Parser: MbedJSONValue libs
* Ethernet Networking : WIZnetInterface
* HTTP Server with JSON : Fraka6 Blog – No Free Lunch: The simplest python server example 😉
2. Hardware
* WIZwiki-W7500ECONET: WIZwiki-W7500 + ECO Shield Ethernet
IMG_20151029_164448//embedr.flickr.com/assets/client-code.js

Simplest python JSON server on PC

def run(port=8000): #set port

print('http server is starting...')
#ip and port of server
#server_address = ('127.0.0.1', port)
server_address = ('192.168.0.223', port)#set port
httpd = HTTPServer(server_address, Handler)
print('http server is running...listening on port %s' %port)
httpd.serve_forever()
  • Modify JSON form in do_GET handler
#handle GET command
def do_GET(self):
if format == 'html':
self.send_response(200)
self.send_header("Content-type", "text/plain")
self.send_header('Content-type','text-html')
self.end_headers()
self.wfile.write("body")
elif format == 'json':
#self.request.sendall(json.dumps({'path':self.path}))
#self.request.sendall(json.dumps({'pi':3.14}))
self.request.sendall(json.dumps({'name':'John snow', 'age': 30, 'gender':'male'}))
else:
self.request.sendall("%s\t%s" %('path', self.path))
return

Make main.cc

// Enter a MAC address for your controller below.
uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02};

printf("initializing Ethernet\r\n");
// initializing MAC address
eth.init(mac_addr, "192.168.0.34", "255.255.255.0", "192.168.0.1");

// Check Ethenret Link
if(eth.link() == true) printf("- Ethernet PHY Link-Done \r\n");
else printf("- Ethernet PHY Link- Fail\r\n");

// Start Ethernet connecting: Trying to get an IP address using DHCP
if (eth.connect() 0) {
http_rx_msg[returnCode] = '\0';
printf("Received %d chars from server:\n\r%s\n", returnCode, http_rx_msg);
}
  • Do JSON parse
parse(parser, http_rx_msg);
  • Output the parsed data
// parsing "string" in string type
printf("name =%s\r\n" , parser["name"].get().c_str());
// parsing "age" in integer type
printf("age =%d\r\n" , parser["age"].get());
// parsing "gender" in string type
printf("gender =%s\r\n" , parser["gender"].get().c_str());

Demo. HTTPClient with JSON parser

  1. Network config.
  2. Confirm Received JSON data
  3. Print-out the pasing data
    2015-10-29_16-42-55//embedr.flickr.com/assets/client-code.js

Packet Capture

  1. TCP-Connection
  2. Target board sends GET Form to simple python JSON server
  3. simple python JSON server sends JSON data to Target board
    2015-10-29_16-22-56//embedr.flickr.com/assets/client-code.js

How to collect and analyze sensing data of IoT platform

This post shows how to connect IoT platform to Cloud service and how to display sensing data for graphical analysis.
* Scope of post
* Platform : WIZwiki-W7500
* cloud data loger : data.sparkfun.com (Phant.io)
* cloud chart : analog.io
* IDE; Web-Compiler(mbed.com)
* HTTP Query

data.sparkfun.com

  • What is Phant?
    • Phant is a open source cloud server platform by powered Sparkfun Electronics.
    • Sparkfun created data.spartfun.com ,which is a free cloud service running phant. –
    • To collect data from your device to cloud service, you just need to register a new stream.
    • After register, you get two keys for accessing the data; one is q private key is required to update that stream, other is a public key grants access to any other stream on the service.
    • All communication with Phant is carried out over HTTP. So, your device should be acted as HTTP Client.
    • http://data.sparkfun.com/input/%5BpublicKey%5D?private_key=%5BprivateKey%5D&%5Bfield1%5D=%5Bvalue%5D&%5Bfield2%5D=%5Bvalue%5D

  • Phant : Phant.io

    Phant is a modular node.js based data logging tool for collecting data from the Internet of Things. It is the open source software that powers data.sparkfun.com, and is actively maintained by SparkFun Electronics. Phant is short for elephant. Elephants are known for their remarkable recall ability, so it seemed appropriate to name a data logging project in honor of an animal that never forgets.

analog.io

  • 3rd party of data.sparkfun.com
  • Graphing front end
    >analog.io is a full stack IoT web service and hardware platforms where people can create connected devices and share them with the world. It is designed to solve all kinds of world problems from air pollution, improving farm output or studying the bee population. It is really only limited by the users imagination. (for more detail)
    2015-09-22_19-36-25//embedr.flickr.com/assets/client-code.js

Prepare materials

  • Hardware
    IMG_20150922_195307//embedr.flickr.com/assets/client-code.js

    • mbed platform : WIZwiki-W7500
      • ARM® Cortex™-M0 Core 48MHz
      • 128KB Flash memory
      • 16KB to 48 KB SRAM (Min 16KB available if 32KB socket buffer is used, Max 48KB available if no socket buffer is used)
      • Hardwired TCP/IP Core (8 Sockets, MII: Medium-Independent Interface)
      • 12-bit, 8ch ADC
      • 53 I/Os
      • 1ch Watchdog, 4ch Timers and 8ch PWM
      • 3ch UART
      • 2ch SPI
      • 2ch I2C
    • Sensors (ywrobot easy module shield v1): DHT11
      ywrobot//embedr.flickr.com/assets/client-code.js

  • Registrations

    • data.sparkfun.com
      To create a data stream, head over to data.sparkfun.com, and click “CREATE”.

Software

2015-09-22_20-28-32//embedr.flickr.com/assets/client-code.js
* Used Lib
* WIZnetInterface Lib. : for Ethernet connectivity of W7500
* DHT Lib. : for DHT11 sensor

Codes flow

/*
 *Input Pins, Misc
 * D4 - Temp. and Hum. Sensor
 * D3 - Push buttom
 */
DHT sensor(D4, DHT11);
DigitalIn  triggerPin(D3);
  • Configuration Phat Stuff
/*
 * Phant Stuffs
 * Insert your publicKey
 * Insert your privateKey
 * Generat Fileds; 'Files name shoud be same "field name" in Create Stream form'
 */
char publicKey[] = "insert_your_publicKey";
char privateKey[] = "insert_your_privateKey";
uint8_t NUM_FIELDS = 2;
char fieldNames1[] = "hum";
char fieldNames2[] = "temp";
  • Network Configuration : DHCP Client
   // Enter a MAC address for your controller below.
    uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02};     

    printf("initializing Ethernetrn");
    // initializing MAC address
    eth.init(mac_addr);

    // Check Ethenret Link
    if(eth.link() == true)   printf("- Ethernet PHY Link-Done rn");
    else printf("- Ethernet PHY Link- Failrn");

    // Start Ethernet connecting: Trying to get an IP address using DHCP
    if (eth.connect()<0)    printf("Fail - Ethernet Connecing");

    // Print your local IP address:
    printf("IP=%snr",eth.getIPAddress());
    printf("MASK=%snr",eth.getNetworkMask());
    printf("GW=%snr",eth.getGateway());
  • HTTP Client
/*
 *  - If the trigger pin (3) goes low, send the data.
 *      - Get sensing datas by using analogread()
 *      - Call postData
 *          - Open socket as TCP Client
 *          - Try to connet TCP server (data.sparkfun.com); if needs, do DNS clinet for getting IP address of server
 *          - Make query string based on Phant frame
 *          - Send query
 *          - Check for a response from the server, and route it out the serial port.
 */

    while(1)
    {
        if(triggerPin ==0)
        {
            sensor.readData();
            c   = sensor.ReadTemperature(CELCIUS);
            h   = sensor.ReadHumidity();
           printf("Temperature in Celcius: %4.2f", c);
           printf("Humidity is %4.2fn", h, dp, dpf);

          sock.connect("data.sparkfun.com", 80);

          snprintf(http_cmd, http_cmd_sz,  "GET /input/%s?private_key=%s&%s=%2.2f&%s=%3.3f HTTP/1.1rnHost: data.sparkfun.comrnConection: closernrn", 
                                            publicKey, privateKey, fieldNames1, h, fieldNames2, c);
          sock.send_all(http_cmd, http_cmd_sz-1);

          while ( (returnCode = sock.receive(buffer, buffer_sz-1)) > 0)
          {
              buffer[returnCode] = '';
              printf("Received %d chars from server:nr%sn", returnCode, buffer);
          }

          sock.close();         
        }

        wait(2);
    } 

Demo

Serial Monitor

  1. DHCP Clinet message
  2. Press the button to send query to server.
  3. Confirm the response message on serial terminal and data.spark.com/your_stream
    initializing Ethernet
    - Ethernet PHY Link-Done
    IP=192.168.11.224
    MASK=255.255.255.0
    GW=192.168.11.1
    Temperature in Celcius: 27.00Humidity is 55.00
    Received 299 chars from server:
    HTTP/1.1 200 OK
    Access-Control-Allow-Origin: *
    Access-Control-Allow-Methods: GET,POST,DELETE
    Access-Control-Allow-Headers: X-Requested-With, Phant-Private-Key
    Content-Type: text/plain
    X-Rate-Limit-Limit: 300
    X-Rate-Limit-Remaining: 298
    X-Rate-Limit-Reset: 1441353380.898
    Date: Fri, 04 Sep 20
    Received 299 chars from server:
    15 07:46:03 GMT
    Transfer-Encoding: chunked
    Set-Cookie: SERVERID=phantworker2; path=/
    Cache-control: private
    

https://data.sparkfun.com/office_monitoring

2015-09-04_16-39-51//embedr.flickr.com/assets/client-code.js

analog.io: import stream from data.sparkfun.com/your_stream

WIZnetInterface for ARMmbed

This is WIZnet Ethernet Interface using Hardware TCP/IP chip, W5500 and TCP/IP Offload Engine, W7500.
Users » embeddist » Code » WIZnetInterface
-> WIZnetInterface Lib will be released on Team WIZnet

This is an Ethernet Interface library port-based on EthernetInterface. This is where the driver using TCP/IP offload(W5500/W7500), which is a market-proven hardwired TCP/IP stack, is implemented. Therefore, this library does not need lwip-eth.library.

  • The Socket folder contains files that implement the SocketAPI and Protocols as like DHCP and DNS.
  • The arch folder contains files that implement the driver for W5500 and W7500x_TOE.
  • The EthernetInterface.c/.h implement the functions from SocketAPI/EthernetInterface.h
  • The eth_arch.h implement to select TCP/IP TOE depending on platform.

What is new?

  • eth_arch.h
    The eth_arch.h file is added to select arch depending to Target platform, we used define of TARGET_platform.
#if defined(TARGET_WIZwiki_W7500)
#include "W7500x_toe.h"
#define __DEF_USED_IC101AG__  //For using IC+101AG@WIZwiki-W7500
#else
#include "W5500.h"            // W5500 Ethernet Shield 
//#define USE_WIZ550IO_MAC    // WIZ550io; using the MAC address
#endif
  • link()
    The link function is added to check Ethernet link (PHY) up or not.
    * Check if an ethernet link is pressent or not.
    *
    * @returns true if successful
    */
    bool link(int wait_time_ms= 3*1000);
  • link_set()
    The set_link function is added to check Ethernet link (PHY) up or not.
   /*
    * Sets the speed and duplex parameters of an ethernet link.
    *
    * @returns true if successful
    */
    void set_link(PHYMode phymode);
  • Included DHCP and DNS lib
    DHCP and DNS lib moved in Socket folder.
    Included DHCP&DNS

How to import

  • import and update
    • Right Click and click ‘From Import Wizard’ to import WIZnetInterface Library
      import library
    • In import Wizard, input ‘WIZnetInterfae” in search box and click ‘Search’ button. Click ‘WIZnetInterface’ in search result window and click ‘Import’ button.
      Search WIZnetInterface
    • Set ‘Import name’ and ‘Target path’, check ‘update’
      import and update WIZnetInterface

Where is Clone repository

hg clone https://embeddist@developer.mbed.org/users/embeddist/code/WIZnetInterface/

How to use

  • make main.cpp
    • WIZwiki_W7500
    #define _DHCP_
    EthernetInterface eth;  /*1. Creat eth object from EthernetInteface class*/
    
    main()
    {
        uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x01, 0x02, 0x03};  
    
        /*2. Set MAC, IP, Gatway address and Subnet Mask*/
    #ifdef _DHCP_
        /*2.1 Set  MAC address, Initialize the interface with DHCP*/
        eth.init(mac_addr); 
    #else   
        /*2.2 Set  MAC address and Set MAC, IP, Gatway address and Subnet Mask*/
        eth.init(mac_addr, "192.168.77.34", "255.255.255.0", "192.168.77.1"); 
    #endif
    
        /*3. Check Ethernet Link-Done */
        printf("Check Ethernet Link\r\n");
        if(eth.link() == true) { printf("- Ethernet PHY Link-Done \r\n"); }
        else {printf("- Ethernet PHY Link- Fail\r\n");}
    
        /*4. Set IP addresses ,start DHCP if needed  */
        eth.connect();
        printf("Connected, IP: %s\n\r", eth.getIPAddress());
        printf("MASK: %s\n\r", eth.getNetworkMask());
        printf("GW: %s\n\r",eth.getGateway());
        ...
    
        /* Your application 
           Visit for examples - https://developer.mbed.org/teams/WIZnet/
        */
    
    }
    
    • W5500 Ethernet Shield
    #define _DHCP_
    /* 0. Set SPI Interface with SPI API*/
    SPI spi(D11, D12, D13);                  // mosi, miso, sclk
    /*1. Creat eth object from EthernetInteface class*/
    EthernetInterface eth(&spi, D10, D9);    // spi, cs, reset
    
    main()
    {
        uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x1D, 0x62, 0x11}; 
        /*2. Set MAC, IP, Gatway address and Subnet Mask*/
    #ifdef _DHCP_
        /*2.1 Set  MAC address, Initialize the interface with DHCP*/
        eth.init(mac_addr); 
    #else
        /*2.2 Set  MAC address and Set MAC, IP, Gatway address and Subnet Mask */
        eth.init(mac_addr, "192.168.77.34", "255.255.255.0", "192.168.77.1"); 
    #endif
    
        /*3. Check Ethernet Link-Done */
        printf("Check Ethernet Link\r\n");
        if(eth.link() == true) { printf("- Ethernet PHY Link-Done \r\n"); }
        else {printf("- Ethernet PHY Link- Fail\r\n");}
    
        /*4. Set IP addresses ,start DHCP if needed  */
        eth.connect();
        printf("Connected, IP: %s\n\r", eth.getIPAddress());
        printf("MASK: %s\n\r", eth.getNetworkMask());
        printf("GW: %s\n\r",eth.getGateway());
        ...
    
        /* Your application 
           Visit for examples - https://developer.mbed.org/teams/WIZnet/
        */
    
    }
    

WIZnetInterface Implementations for mbed Ethenret Interface

For networking based on Ethernet network, Ethenret Interface library is provided and is composed TCP/IP Protocol layer, Ethernet, EthernetInterface and Socket. In other words, the EthernetInterface library includes the networking stack necessary for connect betwwen mbed platform and Internet.

Each layer in EthernetInterface provides APIs to connect to the internet.
* EthernetInterfaec : https://developer.mbed.org/handbook/Ethernet-Interface
* Socket : https://developer.mbed.org/handbook/Socket
* TCP/IP Protocols : https://developer.mbed.org/handbook/TCP-IP-protocols-and-APIs
* Ethernet : https://developer.mbed.org/handbook/Ethernet

WIZnetInterface Implementation base on mbed Ethernet Interface

  • EthernetInterface- EthernetInterface Class
    Type Func. Descriptions WIZnetInterface Support
    static int init () Initialize the interface with DHCP. O
    static int init (const char *ip, const char *mask, const char *gateway) Initialize the interface with a static IP address. O
    static int connect (unsigned int timeout_ms=15000) Connect Bring the interface up, start DHCP if needed. O
    static int disconnect () Disconnect Bring the interface down. X
    static char* getMACAddress () Get the MAC address of your Ethernet interface. O
    static char* getIPAddress () Get the IP address of your Ethernet interface. O
    static char* getGateway () Get the Gateway address of your Ethernet interface. O
    static char* getNetworkMask () Get the Network mask of your Ethernet interface. O
    void EthernetInterface (PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset) Initialize SPI SPI pins to user for SPI interface and Reset pin for W5500 0 (for W5500)
    void EthernetInterface (SPI* spi, PinName cs, PinName reset) Initialize SPI SPI pins to user for SPI interface and Reset pin for W5500 O (for W5500)
  • Socket – TCPSocketServer Class

    Type Func. Descriptions WIZnetInterface Support
    TCPSocketServer () Instantiate a TCP Server. O
    int bind (int port) Bind a socket to a specific port. O
    int listen (int backlog=1) Start listening for incoming connections. O
    int accept ( TCPSocketConnection &connection) Accept a new connection. O
    void set_blocking (bool blocking, unsigned int timeout=1500) Set blocking or non-blocking mode of the socket and a timeout on blocking socket operations. O
    int set_option (int level, int optname, const void *optval, socklen_t optlen) Set socket options. X
    int get_option (int level, int optname, void *optval, socklen_t *optlen) Get socket options. X
    int close (bool shutdown=true) Get socket options. O
  • Socket – TCPSocketConnection Class

    Type Func. Descriptions WIZnetInterface Support
    TCPSocketConnection () TCP socket connection. O
    int connect (const char *host, const int port) Connects this TCP socket to the server. O
    bool is_connected (void) Check if the socket is connected. O
    int send (char *data, int length) Send data to the remote host. O
    int send_all (char *data, int length) Send all the data to the remote host. O
    int receive (char *data, int length) Receive data from the remote host. O
    int receive_all (char *data, int length) Receive all the data from the remote host. O
    void set_blocking (bool blocking, unsigned int timeout=1500) Set blocking or non-blocking mode of the socket and a timeout on blocking socket operations. O
    int set_option (int level, int optname, const void *optval, socklen_t optlen) Set socket options. X
    int get_option (int level, int optname, void *optval, socklen_t *optlen) Get socket options. X
    int close (bool shutdown=true) Close the socket. O
    void reset_address (void) Reset the address of this endpoint. O
    int set_address (const char *host, const int port) Set the address of this endpoint. O
    char* get_address (void) Get the IP address of this endpoint. O
    int get_port (void) Get the port of this endpoint. O
  • etnerhet_api – ethernet_api Class

    Type Func. Descriptions WIZnetInterface Support
    Ethernet () Initialise the ethernet interface. X
    virtual ~Ethernet () Powers the hardware down. X
    int write (const char *data, int size) Writes into an outgoing ethernet packet. X
    int send () Send an outgoing ethernet packet. X
    int receive () Recevies an arrived ethernet packet. X
    int read (const char *data, int size) Read from an recevied ethernet packet. X
    void address (char *mac) Gives the ethernet address of the mbed. X
    int link() Returns if an ethernet link is pressent or not. O
    void set_link(Mode mode) Sets the speed and duplex parameters of an ethernet link. O

##Revision History
* Initial Release : 19 June. 2015

Network Handbook in ARM mbed

Handbook in ARM mbed includes settup tutorials for mbed platform such as Ethernet as well as mbed library.

Networking Handbook

For networking based on Ethernet network, Ethenret Interface library is provided and is composed TCP/IP Protocol layer, Ethernet, EthernetInterface and Socket. In other words, the EthernetInterface library includes the networking stack necessary for connect betwwen mbed platform and Internet.

Each layer in EthernetInterface provides APIs to connect to the internet.

  • mbed – Ethernet Class Reference
    Type Func. Descriptions
    Ethernet () Initialise the ethernet interface.
    virtual ~Ethernet () Powers the hardware down.
    int write (const char *data, int size) Writes into an outgoing ethernet packet.
    int send () Send an outgoing ethernet packet.
    int receive () Recevies an arrived ethernet packet.
    int read (const char *data, int size) Read from an recevied ethernet packet.
    void address (char *mac) RGives the ethernet address of the mbed.
    int link() Returns if an ethernet link is pressent or not.
    void set_link(Mode mode) Sets the speed and duplex parameters of an ethernet link.
  • mbed – EthernetInterface Class Reference

    Type Func. Descriptions
    static int init () Initialize the interface with DHCP.
    static int init (const char *ip, const char *mask, const char *gateway) Initialize the interface with a static IP address.
    static int connect (unsigned int timeout_ms=15000) Connect Bring the interface up, start DHCP if needed.
    static int disconnect () Disconnect Bring the interface down.
    static char* getMACAddress () Get the MAC address of your Ethernet interface.
    static char* getIPAddress () Get the IP address of your Ethernet interface.
    static char* getGateway () Get the Gateway address of your Ethernet interface.
    static char* getNetworkMask () Get the Network mask of your Ethernet interface.
  • Socket – TCPSocketServer Class Reference

    Type Func. Descriptions
    TCPSocketServer () Instantiate a TCP Server.
    int bind (int port) Bind a socket to a specific port.
    int listen (int backlog=1) Start listening for incoming connections.
    int accept ( TCPSocketConnection &connection) Accept a new connection.
    void set_blocking (bool blocking, unsigned int timeout=1500) Set blocking or non-blocking mode of the socket and a timeout on blocking socket operations.
    int set_option (int level, int optname, const void *optval, socklen_t optlen) Set socket options.
    int get_option (int level, int optname, void *optval, socklen_t *optlen) Get socket options.
    int close (bool shutdown=true) Get socket options.
  • Socket – TCPSocketConnection Class Reference

    Type Func. Descriptions
    TCPSocketConnection () TCP socket connection.
    int connect (const char *host, const int port) Connects this TCP socket to the server.
    bool is_connected (void) Check if the socket is connected.
    int send (char *data, int length) Send data to the remote host.
    int send_all (char *data, int length) Send all the data to the remote host.
    int receive (char *data, int length) Receive data from the remote host.
    int receive_all (char *data, int length) Receive all the data from the remote host.
    void set_blocking (bool blocking, unsigned int timeout=1500) Set blocking or non-blocking mode of the socket and a timeout on blocking socket operations.
    int set_option (int level, int optname, const void *optval, socklen_t optlen) Set socket options.
    int get_option (int level, int optname, void *optval, socklen_t *optlen) Get socket options.
    int close (bool shutdown=true) Close the socket.
    void reset_address (void) Reset the address of this endpoint.
    int set_address (const char *host, const int port) Set the address of this endpoint.
    char* get_address (void) Get the IP address of this endpoint.
    int get_port (void) Get the port of this endpoint.

TCP Server Example

The TCP Server example shows how to get started with the Socket API & Ethernet.

  • EthernetInterface includes lwip as software TCP/IP stck
  • EthernetInterface is expected to build the “mbed-rtos”
    TCPserver

  • lwip is a small TCP/IP protocol

  • Protocols: IP, ICMP, UDP, TCP, IGMP, ARP, PPPoS, PPPoE
  • DHCP client, DNS client, AutoIP/APIPA (Zeroconf), SNMP agent (private MIB support)
  • APIs: specialized APIs for enhanced performance, optional Berkeley-alike socket API
    lwIP
include "mbed.h"
#include "EthernetInterface.h"

EthernetInterface eth;

int main()
{
printf("Trying rn");

// as your env. change to real IP address and so on.
int ret = eth.init("192.168.77.34", "255.255.255.0", "192.168.77.1");

if (!ret) {
printf("Initialized, MAC: %snr", eth.getMACAddress());
printf("Connected, IP: %s, MASK: %s, GW: %snr",
eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway());
} else {
printf("Error eth.init() - ret = %dnr", ret);
return -1;
}

eth.connect();
printf("IP Address is %sn", eth.getIPAddress());

TCPSocketServer server;
server.bind(5000);
server.listen();

while (true) {
printf("nWait for new connection...n");
TCPSocketConnection client;
server.accept(client);

client.set_blocking(false, 1500); // Timeout after (1.5)s

printf("Connection from: %sn", client.get_address());

char buffer[2048];
while (true) {
int n = client.receive(buffer, sizeof(buffer));
////int n = client.receive(buffer, 0);
//printf("rcv data len is : %drn", n);
if (n < 0) break; // !_is_connected
/*
if (n <= 0) break; // !_is_connected or !wait_readable
client.send_all(buffer, n);
if (n <= 0) break;
*/
}
client.close();
}

}

How to build ARM mbed projects on GNU Tools (offline)

  • GNU Tools for ARM Embedded Processor
    https://launchpad.net/gcc-arm-embedded

  • Download GNU Tools on GNU Tools page
    https://launchpad.net/gcc-arm-embedded/+download

    • relsase.txt – release notes
    • win32/ win64 – windows installer
    • linux – linux installation
    • mac – MAC installation
    • How-to-build-tolchain.pdf – how to build
    • readme.txt
    • license.txt
  • Uncompress tar file
    tar xvf gcc-arm-none-eabi-4_7-2013q3-20130916-linux.tar.bz2

  • make /usr/local/arm, /arm/ is the custom software folder
    mkdir /usr/local/arm

  • Move gcc-arm-none-eabi-4_7-2013q3 to /usr/loack/arm
    sudo mv gcc-arm-none-eabi-4_7-2013q3 /usr/local/arm

  • Add path to existing shell, and apply
    vi ~/.bashrc
    export PATH=/usr/loacl/arm/gcc-arm-none-eabi-4_7-2013q3/bin:$PATH
    source ~/.bashrc

mbed RPC with W5500 Ethernet Shield

This post shows how to use mbed RPC with W5500 Ethernet Shield and how to port an Ethernet application used lwIP to W5500Interface.

Remote Procedure Call

In computer science, a remote procedure call (RPC) is an inter-process communication that allows a computer program to cause a subroutine or procedure to execute in another address space (commonly on another computer on a shared network) without the programmer explicitly coding the details for this remote interaction.
http://en.wikipedia.org/wiki/Remote_procedure_call

RPC
*source – http://uw714doc.sco.com/en/SDK_netapi/rpcpD.how_RPC_works.html

HW – FRDM-KL25Z + W5500 Ethernet Shield

FRDM-KL25Z + W5500 Ethernet Shield
http://developer.mbed.org/platforms/KL25Z/
http://developer.mbed.org/components/W5500-Ethernet-Kit-for-IoT/
HW connection : D10 – SCS / D11 – MOSI / D12 – MISO / D13 – SCLK

SW – mbed RPC

Server that executes remote procedure call (RPC) commands through HTTP.
mbed RPC @developer.mbed.org/handbook
In RPC libaray, a simple HTTP Server can execute RPC commands sent from HTTP Client.
This library uses EthernetInterface (lwIP) and mbedOS.

RPC command

The RPC command is encoded in this way :

  • container that wraps a skeleton’s ID
  • method that will be invoked
  • parameters that will be inputted (optional)
    • Command examples
      PUT command : “/DigitalOut/new?arg=LED2&name=led2”
      GET command : “/led2/write?arg=1”

Request handlers

To process requests, the server relies on RequestHandler. Each RequestHandler is assigned to a request type. Each type of request is assigned to a certain role :

  • PUT requests to create new objects
  • DELETE requests to delete objects
  • GET requests to call a function of an object

Porting EthernetInterface to W5500Interface

Here is a guide how to modify :

  • Folk HTTP-Server in you program workspace
  • Delete 2 Folders; EthernetInterface(lwIP) & mbed-rtos in HTTP-Server
  • Added array for MAC Address which was written at Source Hardware Address Register in W5500.
    uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02};`
    
  • Change EthernetInterface() and set SPI Interface for W5500
        /*  Use EthernetInterface
         *EthernetInterface eth;
         *if(eth.init())
         *int ret = eth.init("192.168.77.34", "255.255.255.0", "192.168.77.1");    
         */
        /* ----- Use W5500 Ethernet Shied -----*/
        SPI spi(D11, D12, D13);      /* mosi, miso, sclk */
        //spi.frequency(12500000); /* Optional : set proper SPI clock */
        EthernetInterface eth(&spi, D10, D9); /* spi, cs, reset(dummy) */
        ...
        /* ----- Use W5500 Ethernet Shied -----*/
    
  • Set Network configuration: I will use fixed Address.
        /*  in case of using W5500 Ethenret Shield */
        int ret = eth.init(mac_addr, "192.168.77.34", "255.255.255.0", "192.168.77.1");    
        /* in case of using W550io (has a unique real MAC address) */
        //int ret = eth.init("192.168.77.34", "255.255.255.0", "192.168.77.1");   
    

Repository : Users » embeddist » Code » HTTP-Server_W5500Interface

http://developer.mbed.org/users/embeddist/code/HTTP-Server_W5500Interface/

Demo – Using a browser for HTTP Client

Here is a quick guide how to run this program :

  • Compiles this program and copies it to the mbed
  • Open TeraTerm (install it if you don’t have it), select serial and choose the port named “mbed Serial Port”
  • Reset your mbed
  • The IP address should appear in teraterm. In this example, I will use 192.168.77.34
    Terminal
  • Open your browser and go to http://192.168.77.34
    connecttingl
  • If everything is ok, you should see a webpage.

  • Create Red LED as arg=LED1 and name=RLED
    RGB LED
    Create Red LED

  • To procedure, send command: RLED/write 0
    Reset Red LED

  • To procedure, send command: RLED/write 1
    Reset Red LED