레이블이 IoT인 게시물을 표시합니다. 모든 게시물 표시
레이블이 IoT인 게시물을 표시합니다. 모든 게시물 표시

2015년 9월 22일 화요일

How to collect and analyze sensing data of IoT platform

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.

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/[publicKey]?private_key=[privateKey]&[field1]=[value]&[field2]=[value]
      
  • 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

Prepare materials

  • Hardware
    IMG_20150922_195307

    • 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

  • Registrations

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

      • Create a Data Stream

        2015-09-22_20-06-54

          * 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
        
      • New Stream example: After creating a data Stream, you will confirm URL, Keys for accessing for your data stream.
        E_New Stream1

Software

2015-09-22_20-28-32

  • Used Lib
    • WIZnetInterface Lib. : for Ethernet connectivity of W7500
    • DHT Lib. : for DHT11 sensor

Codes flow

  • mbed.org repositories : https://developer.mbed.org/users/embeddist/code/Data_Sparkfun_io/

  • Configuration Arduino’s I/O pins

    /*
    *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 Ethernet\r\n");
      // initializing MAC address
      eth.init(mac_addr);
    
      // 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)    printf("Fail - Ethernet Connecing");
    
      // Print your local IP address:
      printf("IP=%s\n\r",eth.getIPAddress());
      printf("MASK=%s\n\r",eth.getNetworkMask());
      printf("GW=%s\n\r",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.2f\n", 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.1\r\nHost: data.sparkfun.com\r\nConection: close\r\n\r\n", 
                                              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] = '\0';
                printf("Received %d chars from server:\n\r%s\n", returnCode, buffer);
            }
    
            sock.close();         
          }
    
          wait(2);
      }
    
  • Make Query string over HTTP

      http://data.sparkfun.com/input/[publicKey]?private_key=[privateKey]&hum=[value]&temp=[value]
    
      snprintf(http_cmd, http_cmd_sz,  "GET /input/%s?private_key=%s&%s=%2.2f&%s=%3.3f HTTP/1.1\r\nHost: data.sparkfun.com\r\nConection: close\r\n\r\n", publicKey, privateKey, fieldNames1, h, fieldNames2, c);
      sock.send_all(http_cmd, http_cmd_sz-1);
    

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

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

  • How to Import Stream

    1. Click ‘+Import Stream’ button on menu
      2015-09-04_16-38-19

    2. Select ‘Sparkfun’ on Host drop box and input Public key of data.sparkfun.com
      2015-09-04_16-38-36

    3. Confirm your Stream
      2015-09-04_16-36-04

2015년 3월 4일 수요일

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
  • make dashboard on Axeda

    1. Click "AXEDA REDY"
      mbed LPC1114FN28

    2. Select mbed LPC1768 and enter device name
      mbed LPC1114FN28

    3. Copy serial number
      mbed LPC1114FN28

    4. input serial number in code(main.cc)

      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/

2015년 2월 16일 월요일

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.

2014년 12월 22일 월요일

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


2014년 9월 23일 화요일

Arduino Client for MQTT « knolleary

Arduino Client for MQTT « knolleary.

MQTT is one protocol for Machine-to-machine (M2M) / Internet of Things.
Many Cloud Service company support MQTT as follows server
Mosquitto (mosuitto.org -> Eclipse)
RSMB (IBM developerWorks)
ActiveMQ (Apache)
Apollo (Apache)
Mosca (node.js)
RabbiMQ (vmWare)
mqtt.jx (github)

2014년 7월 16일 수요일