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

Advertisements

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

WZTOE Coding Guide for WIZwiki-W7500

WIZwiki_W7500

wizwiki_W7500

  • WIZnet W7500
  • 32-bit ARM Cortex-M0
  • 128KB Flash / 48 SRAM
  • Hardware TCP/IP coe (WIZnet TCP/IP Engine)
  • 64TQFP( 7x7mm)

  • CMSIS-DAP

  • SWD Con.

  • WIZwiki-W7500 feature

  • Arduino Pin compatible

  • ISP / SD Slot / REG LED
  • Ethernet PHY

HW : MII Interface

MII Interface
* WZTOE Signals

W7500_WZTOE Ethernet PHY
PD_00 CRS
PD_01 RXDV
PD_02 RXD0
PD_03 RXD1
PD_04 RXD2
PD_06 RXD3
PB_04 TXEN
PB_05 COL
PB_07 RXCLK
PB_08 DUP
PB_09 TXCLK
PB_10 TXD0
PB_11 TXD1
PB_12 TXD2
PB_13 TXD3
  • MDIO via GPIO

    Management Data Input/Output (MDIO), also known as Serial Management Interface (SMI) or Media Independent Interface Management (MIIM), is a serial bus defined for the Ethernet family of IEEE 802.3 standards for the Media Independent Interface, or MII. The MII connects Media Access Control (MAC) devices with Ethernet physical layer (PHY) circuits.
    http://en.wikipedia.org/wiki/Management_Data_Input/Output

  • PB_14 — MDIO (@IC+101)

  • PB_15 — MDC (@IC+101

SW : (will update code location)

  • ioLibary :“Internet Offload Library” for WIZnet chip. It includes drivers and application protocols.
    $\W7500_FW\Projects\Peripheral_Examples\WZTOE\ioLibrary

  • MDIO via GPIO: It Includes the MDIO Read and Write functions.
    $\W7500_FW\Projects\Peripheral_Examples\WZTOE\ioLibrary\MDIO\W7500x_miim.h
    $\W7500_FW\Projects\Peripheral_Examples\WZTOE\ioLibrary\MDIO\W7500x_miim.c

  • W7500 WZTOE (WIZnet TCPIP Engine) Driver
    $\W7500_FW\Libraries\W7500x_stdPeriph_Driver\inc\W7500x_WZTOE.h
    $\W7500_FW\Libraries\W7500x_stdPeriph_Driver\src\W7500x_WZTOE.c

Coding Guides

  • To use accurate Ticker of 1usec, set WZ100US value according to main clock(HCLK)
/* Set WZ_100US Register */
setTIC100US((GetSystemClock()/10000));
//getTIC100US();
//printf(" GetSystemClock: %X, getTIC100US: %X, (%X) rn",
// GetSystemClock, getTIC100US(), *(uint32_t *)TIC100US);
  • To clear Interrupt register, use Interrupt Clear Register (ICR) , Socket Interrupt Clear Register(Sn_ICR).
setSn_IMR(socket_number, interrupt_mask_bits);
...
socket_interrupt_state = getSn_IR(socket_number);
...
socket_interrupt_state = setSn_ICR(socket_number, interrupt_clear_bit);
  • To use previous codes, setSn_ICR() is warped by setSn_IR().

  • How to access WZTOE
    Memory map of TOE memory

  • Registers

#define WZTOE_COMMON_REGISTER_BASEADDR (0x4100_0000)
#define WZTOE_SOCKET_REGISTER_BASEADDR(sock_num) (0x4101_0000 + (sock_num)<<18))

/* Write to wztoe common register with offset address of 3 */
offset_addr = 3;
*(volatile uint32_t *)(WZTOE_COMMON_REGISTER_BASEADDR + offset_addr) = 0x12;

/* Read to wztoe socket 3 register with offset address of 8 */
sock_num = 3;
offset_addr = 8;
val = *(volatile uint32_t *)(WZTOE_SOCKET_REGISTER_BASEADDR(sock_num) + offset_addr)
  • TX/RX Buffer
    Cortex-m0 is able to access by 32-bits address. However, Sn_TX_WR(Socket n TX Write Pointer Register) and Sn_RX_RD (Socket n RX Read Pointer Register) is only the lower 16 bits of the pointer. Hence, to calcurate the address boundary, offset address shoud be masked by 0xFFFF.
#define WZTOE_SOCKET_TXBUF_BASEADDR(sock_num) (0x4102_0000 + (sock_num)<<18))
#define WZTOE_SOCKET_RXBUF_BASEADDR(sock_num) (0x4103_0000 + (sock_num)<<18))

/* Write to wztoe TX buffer with offset address of 3 */
sock_num = 3;
offset_addr = 0x0001_0000;
*(volatile uint32_t *)(WZTOE_SOCKET_TXBUF_BASEADDR(sock_num) + (offset_addr&0xFFFF)) = 0x12;

/* Read to wztoe RX buffer with offset address of 8 */
sock_num = 2;
offset_addr = 8;
val = *(volatile uint32_t *)(WZTOE_SOCKET_RXBUF_BASEADDR(sock_num) + (offset_addr&0xFFFF)
  • API for TX/RX Buffer
void WIZCHIP_READ_BUF (uint32_t BaseAddr, uint32_t ptr, uint8_t* pBuf, uint16_t len)
{
uint16_t i = 0;
WIZCHIP_CRITICAL_ENTER();

for(i = 0; i < len; i++)
pBuf[i] = *(volatile uint8_t *)(BaseAddr +((ptr+i)&0xFFFF));

WIZCHIP_CRITICAL_EXIT();
}

void WIZCHIP_WRITE_BUF(uint32_t BaseAddr, uint32_t ptr, uint8_t* pBuf, uint16_t len)
{
uint16_t i = 0;
WIZCHIP_CRITICAL_ENTER();

for( i=0; i<len; i++)
*(volatile uint8_t *)(BaseAddr + ((ptr+i)&0xFFFF)) = pBuf[i];

WIZCHIP_CRITICAL_EXIT();
}

void wiz_send_data(uint8_t sn, uint8_t *wizdata, uint16_t len)
{
uint32_t ptr = 0;
uint32_t sn_tx_base = 0;

if(len == 0) return;
ptr = getSn_TX_WR(sn);
sn_tx_base = (TXMEM_BASE) | ((sn&0x7)<<18);
WIZCHIP_WRITE_BUF(sn_tx_base, ptr, wizdata, len);
ptr += len;
setSn_TX_WR(sn,ptr);
}

void wiz_recv_data(uint8_t sn, uint8_t *wizdata, uint16_t len)
{
uint32_t ptr = 0;
uint32_t sn_rx_base = 0;

if(len == 0) return;
ptr = getSn_RX_RD(sn);
sn_rx_base = (RXMEM_BASE) | ((sn&0x7)<<18); WIZCHIP_READ_BUF(sn_rx_base, ptr, wizdata, len); ptr += len; setSn_RX_RD(sn,ptr); } ``` ### MDIO via GPIO * Port Init. ```cpp /* Set GPIOs for MDIO and MDC */ GPIO_InitTypeDef GPIO_InitDef; GPIO_InitDef.GPIO_Pin = GPIO_Pin_MDC | GPIO_Pin_MDIO; GPIO_InitDef.GPIO_Mode = GPIO_Mode_OUT; GPIO_Init(GPIOx, &GPIO_InitDef); PAD_AFConfig(PAD_PB, GPIO_Pin_MDIO, PAD_AF1); PAD_AFConfig(PAD_PB, GPIO_Pin_MDC, PAD_AF1); ``` * MDIO APIs ```cpp uint32_t link(void) { return ((mdio_read(GPIOB, PHYREG_STATUS)>>SVAL)&0x01);
}

void set_link(SetLink_Type mode)
{
uint32_t val=0;
assert_param(IS_SETLINK_TYPE(mode));

if( mode == CNTL_AUTONEGO)
{
val = CNTL_AUTONEGO;
}
else
{
val = (mode & (CNTL_SPEED|CNTL_DUPLEX));
}

mdio_write(GPIOB, PHYREG_CONTROL, val);

}
  • MDIO Read/Write Functions
void output_MDIO(GPIO_TypeDef* GPIOx, uint32_t val, uint32_t n)
{
for(val <<= (32-n); n; val<<=1, n--)
{
if(val & 0x80000000)
GPIO_SetBits(GPIOx, MDIO);
else
GPIO_ResetBits(GPIOx, MDIO);

delay(1);
GPIO_SetBits(GPIOx, MDC);
delay(1);
GPIO_ResetBits(GPIOx, MDC);
}
}

uint32_t input_MDIO( GPIO_TypeDef* GPIOx )
{
uint32_t i, val=0;
for(i=0; i<16; i++)
{
val <<=1;
GPIO_SetBits(GPIOx, MDC);
delay(1);
GPIO_ResetBits(GPIOx, MDC);
delay(1);
val |= GPIO_ReadInputDataBit(GPIOx, MDIO);
}
return (val);
}

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/

An Simple IoT example – connected CO2 Sensor with WIZ550S2E

WIZ5500S2E and S-300

This IoT example shows how to connect CO2 sensor to your ethernet network, and how to send sensing data by using Serial-to-Ethernet gateway module as UDP client. Using S-to-E gatewat module, your device does not need any additional codes and hardware requried.

In this example, WIZ550S2E-232 as a S-to-E module and S-300 as a CO2 sonsor module are used.

  • WIZ550S2E-232: This module is a gateway module that converts RS-232 protocol into TCP/IP protocol and enables remote gauging, remote management of the device through the network based on the Ethernet and the TCP/IP by connecting to existing equipment with RS-232 serial interface.

  • S-300: This SO2 (Carbon Dioxide) sensor module designed by ELT (http://eltsensor.co.kr/) and has available output with TTL-UART for sampling interval of about 3 seconds .

Block Diagram and Network Configurations

  • This figure is shown the block diagram and network configurations for this project.

    • IoT Sensor Node is made up as follows
      • S-to-E : WIZ550S2E-232
      • CO2 Sonsor : S-300
      • UDP Client embedded on S-to-E
    • Monitoring Server is composed as follows
      • UDP server : Hercules (TCP/IP utils) on PC

    Diagram

  • Serial-to-Ethernet Module : WIZ550S2E-232

    WIZ550S2E-232

    • Gateway module that converts RS-232 protocol into TCP/IP protocol
    • Serial to Ethernet Module based on W5500 & Cortex-M0
    • RJ-45 mounted, Pin-header type module
    • Serial signals : TXD, RXD, RTS, CTS, GND
    • Support the configuration method of AT command & Configuration tool program
    • Configuration tool program operates on Windows, Linux & MAC OS
    • Support the interface board for RS-232 and RS422/485
    • 10/100Mbps Ethernet & Max.230kbps serial speed
    • Support WIZ VSP (Virtual Serial Port) program
    • Dimension (mm) : 55(L) x 30 (W) x 23.49 (H)
  • Co2 Sensor: ELT Sensor : S-300

    S-300

    • Non-Dispersive Infrared (NDIR) technology used to measure CO₂levels.
    • Pre-calibrated
    • Available outputs : TTL-UART, I2C, ALARM, PWM/Analog Voltage.
    • Gold-plated sensor provides long-term calibration stability.
    • Installed re-calibration function
    • Operate as ACDL mode (Automatic Calibration in Dimming Light mode).
    • Manual Re-Calibration function is executable.
    • ROHS Directive- 2011/65/EU,[EN50581 : 2012,IEC 62321-3-1 : 2013]
    • Size : 33mmx33mmx13.1mm
    • Weight : 10 grams

Hardware connections

Three lines as below the may be connected for Sensor node.
The TXD in S-300 and RXD in WIZ550S2E should be connected together.

WIZ550S2E Direction S-300 JIG
RXD <— TXD
VCC(baseboard) <— VCC (5V)
GND GND
  • WIZ550S2E

    WIZ550S2E Pin Maps

  • S-300 JIG

    JIG S-300 Pin Maps

Software

  • WIZ550S2E Side: Sensor Node

    WIZ550S2E Configuration

  • PC tools: Monitoring Server

    • Herdules

      > Hercules SETUP utility is useful serial port terminal (RS-485 or RS-232 terminal) , UDP/IP terminal and TCP/IP Client Server terminal. It was created for HW group internal use only, but today it’s includes many functions in one utility and it’s Freeware! With our original devices (Serial/Ethernet Converter, RS-232/Ethernet Buffer or I/O Controller) it can be used for the UDP Config.

    • Hercules download : version3.2.8

    • Hercules user guide : User Guide

    Hercules

Setting

Excuting

  • UART frame of S-300

    S-300 output frame in UART

  • CO2 Data received from the Sensor node

    C02 Data received form Sensor node

  • CO2 Data shown in text format

    text type

  • CO2 Data shown in Hex format

    Hex type