Soohwan Kim
Published © Apache-2.0

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.

AdvancedFull instructions provided1,922
How to collect and analyze sensing data of IoT platform

Things used in this project

Hardware components

WIZwiki-W7500
WIZnet WIZwiki-W7500
×1
ywrobot easy module shield v1
×1

Story

Read more

Code

Code

Plain text
/*
*Input Pins, Misc
* D4 - Temp. and Hum. Sensor
* D3 - Push buttom
*/
DHT sensor(D4, DHT11);
DigitalIn  triggerPin(D3);

Code

Plain text
/*
* 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";

Code

Plain text
 // 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());

Code

Plain text
/*
*    - 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);
  }

Code

Plain text
 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

Code

Plain text
/*
*Input Pins, Misc
* D4 - Temp. and Hum. Sensor
* D3 - Push buttom
*/
DHT sensor(D4, DHT11);
DigitalIn  triggerPin(D3);

Code

Plain text
/*
* 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";

Code

Plain text
 // 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());

Code

Plain text
/*
*    - 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);
  }

Code

Plain text
 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

Credits

Soohwan Kim

Soohwan Kim

6 projects • 7 followers
Embedded System, ARM mbed, Arduino, TCP/IP, SoC, Open Source Hardware

Comments