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

How to push data to data.sparkfun.com for Internet of Things

How to push data to data.sparkfun.com for Internet of Things

This post shows how to connect Arduino platform to data.sparkfun.com for Internet of Things.
* Scope of post
* Internet Connectivity : W5500 Ethernet Shield
* Cloud Service : data.sparkfun.com
* Arduino IDE 1.7.6 (arduino.org); surpports Ethernet libraries for W5500
* 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.

Prepare materials

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

  • Tool : Arduino IDE
  • Registration on data.sparkfun.com
    To create a data stream, head over to data.sparkfun.com, and click “CREATE”.

    • Create a Data Stream
      • New Stream example
        ![Registration2 @ data.sparkfun.com](C:\Users\root\Desktop\CC_AUG\FIG\EDITED\E_New Stream.png)

        • Fields – This comma-separated list of words defines data stream to post a list of unique values.
        • Stream Alias – This testbox defines domain name for you Data Stream
      • Create Data Steam: After creating a data Stream, you will confirm URL, Keys for accessing for your data stream.
        ![Registration1 @ data.sparkfun.com](C:\Users\root\Desktop\CC_AUG\FIG\EDITED\E_New Stream1.png)

Software

Codes flow

  • Configuration Arduino’s I/O pins

    • D3 – Active-low momentary button (pulled high internally)
    • A1 – Photoresistor (which is combined with a 10k resistor to form a voltage divider output to the Arduino).
    • A2 – Temporature Sensor (LM35)
  • Configuration Phat Stuff
    • Insert your publicKey
    • Insert your privateKey
    • Generat Fileds; ‘Files name shoud be same “field name” in Create Stream form’
  • setup()
    • Call Serial.begin(115200);
    • Setting Input pins
    • Call setupEthernet(): do DHCP Client and writing MAC Addrerss
  • loop()
    • 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.

Arduino’s I/O pins:

const int triggerPin = 3;
const int lightPin = A1;
const int tempPin = A2; 

void setup()
{
...

  // Setup Input Pins:
  pinMode(triggerPin, INPUT_PULLUP);
  pinMode(lightPin, INPUT_PULLUP);
  pinMode(tempPin, INPUT_PULLUP);
...
}

Phant Stuff

const String publicKey = "insert_your_publicKey"; 
const String privateKey = "insert_your_privateKey";

const byte NUM_FIELDS = 2;
const String fieldNames[NUM_FIELDS] = {"lux", "temp"}; // Fileds shoud be same "field names" in Create Stream.
int fieldData[NUM_FIELDS];

Make Query string over HTTP

client.print("GET /input/");
client.print(publicKey);
client.print("?private_key=");
client.print(privateKey);
for (int i=0; i<NUM_FIELDS; i++)
{
  client.print("&");
  client.print(fieldNames[i]);
  client.print("=");
  client.print(fieldData[i]);
}
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println("Connection: close");
client.println();

Phant_Ethernet.ino

/*****************************************************************
Phant_Ethernet.ino
Post data to SparkFun's data stream server system (phant) using
an Arduino and an Ethernet Shield.
Jim Lindblom @ SparkFun Electronics
Original Creation Date: July 3, 2014
Roy Kim(Soohwan Kim) embeddist@gmail.com
Modified DateL August 26, 2015
S

This sketch uses an Arduino Uno to POST sensor readings to 
SparkFun's data logging streams (http://data.sparkfun.com). A post
will be initiated whenever pin 3 is connected to ground.

Before uploading this sketch, there are a number of global vars
that need adjusting:
1. Ethernet Stuff: Fill in your desired MAC and a static IP, even
   if you're planning on having DCHP fill your IP in for you.
   The static IP is only used as a fallback, if DHCP doesn't work.
2. Phant Stuff: Fill in your data stream's public, private, and 
data keys before uploading!

Hardware Hookup:
  * These components are connected to the Arduino's I/O pins:
    <Original>
    * D3 - Active-low momentary button (pulled high internally)
    * A0 - Photoresistor (which is combined with a 10k resistor
           to form a voltage divider output to the Arduino).
    * D5 - SPDT switch to select either 5V or 0V to this pin.
    <Modified>
    * D3 - Active-low momentary button (pulled high internally)
    * A1 - Photoresistor (which is combined with a 10k resistor
           to form a voltage divider output to the Arduino).
    * A2 - Temporature Sensor (LM35)

  * A CC3000 Shield sitting comfortable on top of your Arduino.

Development environment specifics:
    <Original>
    IDE: Arduino 1.0.5 
    Hardware Platform: RedBoard & PoEthernet Shield
    <Modified>
    IDE: Arduino 1.7.6 
    Hardware Platform: Arduino DUE & W5500 Ethernet Shield

This code is beerware; if you see me (or any other SparkFun 
employee) at the local, and you've found our code helpful, please 
buy us a round!

Much of this code is largely based on David Mellis' WebClient
example in the Ethernet library.

Distributed as-is; no warranty is given.
*****************************************************************/
#include <SPI.h> // Required to use Ethernet
//#include <Ethernet.h> // The Ethernet library includes the client for W5100
#include <Ethernet2.h> // The Ethernet library includes the client for W5500
//#include <Progmem.h> // Allows us to sacrifice flash for DRAM //@Modified: Don't use

///////////////////////
// Ethernet Settings //
///////////////////////
// Enter a MAC address for your controller below.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(54,86,132,254);  // numeric IP for data.sparkfun.com
char server[] = "data.sparkfun.com";    // name address for data.sparkFun (using DNS)
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192,168,0,177);

// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

/////////////////
// Phant Stuff //
/////////////////
const String publicKey = "6JZbNolApzF4om2l9yYK";
const String privateKey = "Ww0vPW1yrkUNDqWPV9jE";

const byte NUM_FIELDS = 2;
const String fieldNames[NUM_FIELDS] = {"lux", "temp"};
int fieldData[NUM_FIELDS];

//////////////////////
// Input Pins, Misc //
//////////////////////
const int triggerPin = 3;
const int lightPin = A1;
const int tempPin = A2; 

float tempC;
int reading;
//String name = "Ether-anon";
String name = "Roy";
boolean newName = true;

void setup()
{
  Serial.begin(115200);

  // Setup Input Pins:
  pinMode(triggerPin, INPUT_PULLUP);
  pinMode(lightPin, INPUT_PULLUP);
  pinMode(tempPin, INPUT_PULLUP);

  // Set Up Ethernet:
  setupEthernet();

  Serial.println(F("=========== Ready to Stream ==========="));
  Serial.println(F("Press the button (D3) to send an update"));
#if 0 // don't use
  Serial.println(F("Type your name (no spaces!), followed by '!' to update name"));
#endif
}

void loop()
{
  // If the trigger pin (3) goes low, send the data.
  if (!digitalRead(triggerPin))
  {
    // Gather data:
        fieldData[0] = analogRead(lightPin);
        fieldData[1] = analogRead(tempPin);
    //fieldData[2] = name;

    Serial.println("Posting!");
    postData(); // the postData() function does all the work, 
                // check it out below.

    delay(1000);
  }
#if 0 // don't use
  // Check for a new name input:
  if (Serial.available())
  {
    char c = Serial.read();
    if (c == '!')
    {
      newName = true;
      Serial.print("Your name is ");
      Serial.println(name);
    }
    else if (newName)
    {
      newName = false;
      name = "";
      name += c;
    }
    else
    {
      name += c;
    }
  }
#endif
}

void postData()
{
  // Make a TCP connection to remote host
  if (client.connect(server, 80))
  {
    // Post the data! Request should look a little something like:
    // GET /input/publicKey?private_key=privateKey&light=1024&switch=0&name=Jim HTTP/1.1n
    // Host: data.sparkfun.comn
    // Connection: closen
    // n
    client.print("GET /input/");
    client.print(publicKey);
    client.print("?private_key=");
    client.print(privateKey);
    for (int i=0; i<NUM_FIELDS; i++)
    {
      client.print("&");
      client.print(fieldNames[i]);
      client.print("=");
      client.print(fieldData[i]);
    }
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(server);
    client.println("Connection: close");
    client.println();
  }
  else
  {
    Serial.println(F("Connection failed"));
  } 

  // Check for a response from the server, and route it
  // out the serial port.
  while (client.connected())
  {
    if ( client.available() )
    {
      char c = client.read();
      Serial.print(c);
    }      
  }
  Serial.println();
  client.stop();
}

void setupEthernet()
{
  Serial.println("Setting up Ethernet...");
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println(F("Failed to configure Ethernet using DHCP"));
    // no point in carrying on, so do nothing forevermore:
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  Serial.print("My IP address: ");
  Serial.println(Ethernet.localIP());
  // give the Ethernet shield a second to initialize:
  delay(1000);
}

Demo:

Serial Monitor

  1. DHCP Clinet message
  2. Press the button to send query to server, then postData() is called.
  3. Confirm the response message
    office monitoring@ data.sparkfun.com

https://data.sparkfun.com/office_monitoring

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 performance of SoC with TCP/IP Offload engine, W7500

This post shows how to measure Network perfromance by using Iperf and how to configure W7500 to improve Network performance.

.

TOE allows to offload the processing of TCP/IP protocols from the host microcontroller,
In TCP/IP protocol stack

TOE

TOE performance according to AHB bus clock (w/o DMA, RX Buffer:8KB)

Network performance

How to connect mbed LPC114FN28 to AXEDA for Internet of Things?

This post shows how to connect mbed LPC114FN28 to AXEDA Service for Internet of Things.

mbed LPC1114FN28

mbed LPC1114FN28

The mbed LPC1114FN28 operates at CPU frequencies of 48 MHz. The LPC1114FN28 includes up to 32 kB of flash memory, up to 4 kB of data memory, one Fastmode Plus I2C-bus interface, one RS-485/EIA-485 UART, one SPI interface with SSP features, four general purpose counter/timers, a 10-bit ADC, and up to 22 general purpose I/O pins.

*http://developer.mbed.org/platforms/LPC1114FN28/

Note: LPC1114FN28 platform doesn’t support RTOS due to its flash size. Please do not import mbed-rtos library into your project.

mbed LPC1114FN28 has very limited size memory size and no Internet connectivity.
In addition, LPC114EN28 doesn’t support RTOS and EthernetInterface.

How to connect mbed LPC114FN28 to AXEDA (IoT Cloud Platform)?
An answer is WIZ550io.

WIZ550io
WIZ550io is an auto configurable Ethernet controller that includes a W5500 (TCP/IP hardwired chip and PHY embedded), a transformer and RJ45. It supports Serial Peripheral Interface (SPI) bus as host interface. Therefore,
host system can be simply connect to Internet without EthernetInterface or TCP/IP software stack (included in RTOS).
http://developer.mbed.org/components/WIZ550io/

Hardware – mbed LPC1114FN28 + WIZ550io

mbed LPC1114FN28

  • WIZ550io: Ethernet Connectivity
    pin name LPC1114FN28 direction WIZ550io
    miso dp1 J1:3
    sck dp6 —> J1:5
    scs dp26 —> J1:6
    RSTn dp25 —> J2:3
  • Potentiometer:

    pin name LPC1114FN28 direction Potentiometer
    AnalogIn dp13 <— 2(OUT)
Software – AxedaGo-mbedNXP + W5500Interface
  1. Import AxedaGo-mbedNXP

  2. Change a platform as mbed LPC1114FN28
    • This program is made for LPC1768. But, we will use LPC1114FN28. So, LPC1114EN28 is selected the right platform in the compiler.
      mbed LPC1114FN28
  3. Delete EthernetInterface and mbed-rtos on AxedaGo-mbedNXP_WIZ550io

  4. Import W5500Interface

  5. Porting main.cc
    • For using WIZ550io, EthernetInterface Init. should be changed as below,
#if defined(TARGET_LPC1114)
    SPI spi(dp2, dp1, dp6); // mosi, miso, sclk
    EthernetInterface eth(&spi, dp25, dp26); // spi, cs, reset
    AnalogIn pot1(dp13);
#else
    EthernetInterface eth;
    AnalogIn pot1(p19);
    AnalogIn pot2(p20);
#endif 
* AnalogIn ports should be also configured by depending on platform.
AXEDA
    char *SERIAL_NUM = "SerialNumber"; 
Enjoy AXEDA with LPC1114FN24 + WIZ550io

Before Enjoy Axeda, click the Compile button at the top of the page and download .bin on your platform.

  • Serial Terminal Log.
    You will comfirm DHCP IP address, Protentiometer value and sending message in debugging message.
    Connected to COM42.

    initializing Ethernet
     - Ethernet ready
    Ethernet.connecting 
     - connecting returned 0 
    Trying to get IP address..
      -  IP address:192.168.13.53    //&lt;---  DHCP IP address 
    Sending Value for well1 0.00     //&lt;--- Potentiometer value
    Received 36 chars from server:   //sending message
    HTTP/1.1 200 
    Content-Lengtved 36 chars from server:
    HTTP/1.1 200 
    Content-Length: 0
    
    Sending Value for well1 0.14     //&lt;--- Potentiometer value
    Received 36 chars from server:   //sending message
    HTTP/1.1 200 
    Content-Length: 0
    
    Sending Value for well1 0.27    
    Received 36 chars from server:
    HTTP/1.1 200 
    Content-Length: 0
    
    Sending Value for well1 0.29
    Received 36 chars from server:
    HTTP/1.1 200 
    Content-Length: 0
    
  • Axeda Developer Toolbox
    Your mbed board is now connected to your Axeda Toolbox account.
    Open up the mbed Widget by proceeding to your dashboard from the staging page.

mbed LPC1114FN28

In Data Items, it is able to displays to Potentiometer values from LPC1114FN24 + WIZ550io with graphic line.
mbed LPC1114FN28

Comparison of mbed LPC1768 and mbed LPC1114FN28 for Axeda
mbed LPC1768 (lwIP) mbed LPC1114FN28 (WIZ550io)
Codes  sw stack codes TOE codes
Memory usage sw memory usage sw memory usage

In casd of mbed LPC1768, the code size for Axeda is more than double the size of the Flash memory of the LPC1114 to 66.8kB. On the other hand, memory usage of LPC1114FN28 + WIZ550io is 65% (20.8kB).

Get Codes

http://developer.mbed.org/users/embeddist/code/AxedaGo-mbedNXP_WIZ550io/

Firewall SoC with TCP/IP Offload Engine for Internet of Things

There is no doubt that the number of IoTs will increase explosively.

Gartner, Inc. forecasts that 4.9 billion connected things will be in use in 2015, up 30 percent from 2014, and will reach 25 billion by 2020.

As the IoT device continues to increase, IoT devices will be faced with the network flooding attack, such as DDoS, more frequently. However, because of its capacity of memory and MCU, nearly most IoT devices are very vulnerable to heavy network attacks and traffisc.

Weakness of these IoT device must be a great opportunity to TOE-embedded MCU, W7500. While TOE under Network attack is to reduce the MCU and memory resources of IoT device, because it is possible to protect the System of IoT device.

What is Firewall TCP/IP offload Engine for IoT?

Software TCP/IP stack

First, let’s examine the Software TCP/IP stack.

Software TCP/IP stack implemented on host system requires more capacity of extra memory and extra processing power for network communications. Normally, ARM Cortex-M core copies data from Ethernet MAC buffer to memory, analyze the received packets in memory using the software stack and then executes an appropriate process.

Software TCP/IP Stack

If network flooding attack has occurres, Cortex-M will repeatedly excute process in order to process flooding packets. Therefor, excessive number of TCP requests such as SYN-flooding attacks will overload the IoT device.

Hardware TCP/IP TOE

Hardware TCP/IP TOE

On the other hand, the hardware TCP/IP TOE, which is implemented as Hardwired logic from Ethernet MAC Layer to TCP/IP Layer, is able to protect IoT system against network attack under excessive number of flooding packet by making discard flooding packets detected.

Comparison of Software TCP/IP stack and Hardware TCP/IP TOE under the Network attack such as DDoS.

Hardware TCP/IP SoC

This means that Cortex-M does not have to handle the flooding packet even under Network attack. Further, because the TCP / IP stack processing is performed in TOE, it is possible to save the amount of memory for TCP/IP communications.

These TOE features are not to limited to the Network attack, it is also possible to expect the same performance under heavy network traffic.

We compared the network performance of software TCP/IP stack and Hardware TCP/IP TOE under DoS Attack (Syn-flood attack).

Comparison of Software and Hardware TCP/IP System
Software TCP/IP Hardware TCP/IP
Platform Pic. mbed1768 W7500_EVB
Platform Name mbed1768 W7500 EVB
Max Clock (MHz) 96 48
Flash (KB) 512 128
RAM (KB) 64 32
Use DMA O O
software RTOS + lwIP Non-OS + Fireware
Code size (KB) Flash:64.5 / RAM:35.2 Flash: 9.09 / RAM: 8.99
Compiler Web-compiler (mbed.org) keil
Test tools Iperf.exe, scapy (python)
Network configurations for Network Performancs tests

Network config

How to use iperf

Iperf is a tool to measure maximum TCP bandwidth, allowing the tuning of various parameters and UDP characteristics. Iperf reports bandwidth, delay jitter, datagram loss.

https://iperf.fr/

# ex.) host IP(192.168.77.34):port[5000], display format is Mbit/sec, interval 1 sec.
>iperf.exe -c 192.168.77.34 -p 5000 -f m -i 1
  • -c : –client host, -c will connect to the host specified.
  • -p : –port #, the server port for the server to listen.
  • -f : –format [], ‘m’ = Mbit/sec
  • -i : –interval #, Sets the interval time in seconds between periodic bandwidth through performance
Scripts for DoS Attack (Syn-flood attack)

We used the scapy (python library) as DoS Attack.

Scapy is a powerful interactive packet manipulation program. It can easily handle most classical tasks like scanning, tracerouting, probing, unit tests, attacks or network discovery.
http://www.secdev.org/projects/scapy/

from scapy.all import
inter = input('inter(time in seconds to wait between 2packets) :')

def synFlood(src, tgt, inter):
    IPlayer = IP(src, dst=tgt)
    TCPlayer= TCP(sport=3000, dport=3000) # as your env. change source and destination port
    pkt = IPlayer / TCPlayer
    send(pkt, loop=1, inter=inter) #

#send(pkts, inter=0, loop=0, verbose=None)
#  Send packets at layer 3, using the conf.L3socket supersocket. pkts can
#  be a packet, an implicit packet or a list of them.
#  loop: send the packets endlessly if not 0.
#  inter: time in seconds to wait between 2 packets
#  verbose: override the level of verbosity. Make the function totally silent when 0.
#   * Refer to http://www.secdev.org/projects/scapy/files/scapydoc.pdf for more detail.

# as your env. change to real IP address and so on.
src = "192.168.77.253" # PC IP address
tgt = "192.168.77.34"  # target board
synFlood(src, tgt, inter)

Network performance

Network_performance

It is possible to prove that the network performance of Hardware TCP/IP TOE is better and more stable than software TCP/IP stack under SYN flood attack. In particular, when interval is 0.001sec., the network performance of TOE is 9 times better than the software TCP/IP stack even though the platform embedded software TCP/IP stack is better than TOE platform.

It is confirmed that the Hardware TCP/IP TOE is able to maintain the network performance even if SYN-flood attack is increased. Otherwise, it is possible to observe that the network performance of software TCP/IP stack became extremely worse according to the interval of SYN-attack.