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

Advertisements

WIZ Ethernet Library for Arduino IDE-1.6.4

ARM mbed
Download Arduino IDE-1.6.4

WIZ Ethernet Library

The Ethernet library lets you connect to the Internet or a local network.

  • Supported devices
    W5500 : ioShield, WIZ550io, W5500 Ethernet Shield, Arduino Ethernet Shield 2
    W5200 : W5200 Ethernet Shield, WIZ820io
    W5100 : Arduino Ethernet Shield

  • Software

  • Install WIZ Ethernet library IDE-1.6.4
  • Download all files
  • Overwrite “Ethernet” folder onto the “Arduino\libraries\Ethernet” folder in Arduino sketch.

  • Select device(shield)

  • Uncomment device(shiel) you want to use in $/Ethernet/src/utility/w5100.h
//#define W5100_ETHERNET_SHIELD // Arduino Ethenret Shield and Compatibles ...
//#define W5200_ETHERNET_SHIELD // WIZ820io, W5200 Ethernet Shield
#define W5500_ETHERNET_SHIELD // WIZ550io, ioShield series of WIZnet
  • If WIZ550io used, uncommnet “#define WIZ550io_WITH_MACAADDRESS” in $/Ethernet/src/utility/w5100.h
#if defined(W5500_ETHERNET_SHIELD)
//#define WIZ550io_WITH_MACADDRESS // Use assigned MAC address of WIZ550io
#include "w5500.h"
#endif
  • Using the WIZ Ethernet library and evaluate existing Ethernet example.
    All other steps are the same as the steps from the Arduino Ethernet Shield. You can use examples in ./Ethernet/examples folder for the Arduino IDE 1.6.4, go to Files->Examples->Ethernet, open any example, then copy it to your sketch file and change configuration values properly.
    After that, you can check if it is work well. For example, if you choose ‘WebServer’, you should change IP Address first and compile and download it. Then you can access web server page through your web browser of your PC or something.

What is new ?

  • Added new functions
  • sockStatus(SOCKET s) = readSnSR(SOCKET s)
uint8_t socketStatus(SOCKET s)
{
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
uint8_t status = W5100.readSnSR(s);
SPI.endTransaction();
return status;
}
  • reavAvalable(SOCKET s) = getRxReceiveSize(SOCKET s)
int16_t recvAvailable(SOCKET s)
{
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
int16_t ret = W5100.getRXReceivedSize(s);
SPI.endTransaction();
return ret;
}
  • Added SPI Transaction APIs
    To solve conflicts that sometimes occur between multiple SPI devices when using SPI from interrupts and/or different SPI settings, SPI Transcation APIs use between between read and write SPI functions.
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.setIPAddress(_dhcp->getLocalIp().raw_address());
W5100.setGatewayIp(_dhcp->getGatewayIp().raw_address());
W5100.setSubnetMask(_dhcp->getSubnetMask().raw_address());
SPI.endTransaction();
  • Removed Twitter.cpp / Twitter.h

Code on Github

Version History

  • Initial Release : 21 May. 2015

Note1 – Arduino

ArduinoNote List-page

Arduino

Arduino UNO

Arduino는 open-source hardware board를 말한다.

open-source hardware?
open-source hardware는 로 알아보면 아래와 같은 개발에 필요한 Material을
Free로 open하는 open design movement이다. (Free라도 License는 있으니 주의 ^^;)
– mechanical drawings
– schematics
– bills of material
– PCB layout
– Software (driver)

2005년 이탈리아에서 Massimo Banzi를 포함한 5명이 시작한 open-source hardware project이다. 10년이 체한된 지금 59여개의 국가에서 hobbyist, 미술가와 같은 전문지식이 부족한 사람들이 Do-it-Yorrself(DIY)을 할때 주로 쓰이는 대표적인 open-source hardware platform이 되었다. 또한 Arduino Compatible board (아두이노 호환보드), Arduino Shield (Arduino Platform에 plug-in하여 사용할 수 있는 Module), Arduino pin-headers (아두이노 보드의 핀헤더형태), Arduino Clone (Arduino 복제품)와 같은 새로운 단어들이 생겨남과 복잡하고 다양한 Ecosystem를 구축하였다. 최근에는 Intel과 같은 Big업체가 Open-source Hardware에 참여하기 위해 Arduino Certified를 받은 IntelGalileo Board를 출시할 정도이다.
Arduino Team
(*from blog.arduino.cc)

Platform

Arduino는 Sigle-board Microcontroller로 초기에는 8Bit Atmel AVR microcontroller를 시작으로 해서 최근에는 32-Bit Atmel ARM의 microcontroller까지 여러 Platform Board를 계속해서 Release하고 있다.

Evolution of Arduino
(*from blog.arduino.cc)

  • Arduino platforms
    8-Bit MCU 3-Bit IoT 8-Bit EDU 8-Bit Wearable 32-Bit ARM Dev 32-Bit MPU Certified
    UNO BT Esplora Gamma ZERO TRE Galileo x86
    Leonardo Ethernet Robot Lilypad DUE Edison x86
    Mega WiFi
    Xbee/Fio
    GSM
    Yun

Sketch IDE

Arduino의 intergrated development environment (IDE)는 C, C++기반의 Code의 편집이 가능하고, 편집한 Code를 Target Board에 Program할 수 있는 Sketch라고 하는 Software tool을 사용한다. 이 Sketch에는 사용자들의 편의를 위해서 다양한 예제 Code들을 포함하고 있으며 이를software library라고 부르고 있다.

Sketch Library
* Arduino 1.0.x버젼은 8-Bit AVR Microcontroller를 Maintenance함
* Arduino 1.5.x버젼은 최신 Arduino platform을 지원함
* IDE설치 참고 : 네이버 아두이노 교재

Shield

Arduino Shield는 Arduino와 Arduino-compatible board에 plug-in 혹은 Stacking되는 Arduino pin-header를 가진 PCB Circuit를 말한다. 아래의 그림은 Arduino Official Shield이며, Arduino official Shield 이외에도 Display (LCD shield), prototyping (Breadboard)등과 같은 다양한 Shield들이 존재한다.
Arduino Official Shield

Arduino최근 동향

Arduino ZERO : Cortex-M0+ + Debugger

Arduino ZERO

Arduino TRE : TI Cortex-A9 + ATmega32u4 + WEB-IDE

Arduino TRE

ArduinoMateria101 : Arduino 3D priter

ArduinoMateria101

NEXT: Note2 – Blink sketch

Video: Atmel showcases the WINC1500 wireless module at ARM TechCon

  • WINC1500 wireless module
    *The Arduino Wi-Fi Shield 101 is powered by Atmel’s wireless network controller, part of the Atmel SmartConnect family. It also includes the ATECC108 device, from the CryptoAuthentication family, which allows users to easily incorporate hardware authentication capability in their design.

Atmel | Bits & Pieces

Back in September, Atmel expanded its leading SmartConnect wireless portfolio with four new turnkey system-on-chips (SoCs), including the WINC1500. The recently-unveiled WINC1500 is an IEEE 802.11b/g/n network controller optimized for battery-powered Internet of Things (IoT) applications.

atmel_winc1500_fb_tc_1200x1200_091714

The WINC1500 is an ideal add-on to existing MCU solutions bringing Wi-Fi and network capabilities through UART or SPI-to-WiFi interface, and connects to any Atmel AVR or Atmel  | SMART MCU with minimal resource requirements. As a result, the SoC enables Makers and engineers to bring connectivity to any embedded design, ranging from consumer to industrial apps.

As Hackaday’s Adam Fabio recently noted, “The WINC1500 is a nifty little Wi-Fi module in its own right… 72Mbps may not sound like much by today’s standards, but it’s plenty fast for most embedded applications. WINC handles all the heavy lifting of the wireless connection.”

The WINC1500’s most advanced mode is a single stream 1×1 802.11n mode…

View original post 285 more words

ARDUINO with TEMBOO

-www.temboo.com
템부(Temboo)는 기업들은 API 관리 전문업체 중 하나이다. 보안 API 접속 서비스는 물론이고 일부는 API 호환 서비스를, 또 일부는 클라우드 기반의 API 접근경로를 제공한다.
 
-Program hardware for the Internet of Things
위의 그림처럼 IoT의 hardware 들을 위한 API (Agent+SDK), Cloud service까지 그 영역을 넓혀가는 중이며 Open Hardware의 선두주가 Arduino와 LaunchPad를 중심으로한 Texas Instruments사의 Platform을 현재 지원중이다.
글보단 한편의 동영상으로 Temboo를 이해해 보자
IoT Hardware을 위한 API를 살펴보면서 그 막강한 기능을 체험해보자.
Yahoo Weather를 Temboo와 Arduino를 이용한다.
*Preparation materials
-Arduino board : Arduino Due
-Ethernet Shield : WIZ550io (W5500 with MAC address)
-IDE : IDE 1.5.7
-Lib. : Ethernet Lib. and Temboo Lib
1. 먼저 Temboo에 로그인 한뒤 아래의 페이지에서 “Arudino” 클릭 
-Select Arduino on Program hardware for the Internet of Things
2. ARDUINO+TEMBOO에서 자신이 사용하려는 Hardware선택 
– Select Device: Arduino Yun or Other Arduino Boards + Internet Shield
3. 이제 Temboo Arduino Library의 설치를 위해 아래의 그림에서 우측상단의 “Download”클릭 
– ARDUINO+TEMBOO
4. Installing에 관한 대용은 아래의 사이트를 참고하며 간단하게 download된 Temboo Arduino Library를 “C:\Program Files\Arduino\libraries” 에 압축을 푼다. IDE1.5.7기준! 
– Installing the Temboo Arduino Library
5. 이제 예제를 선택한다 여기서는 GetWeatherByAddress! 
– Select GetWeatherByAddress with Temboo Arduino Library
6. 이제 몇가지 설정으로 GetWeatherByAddress.ino를 생성 시키자
-우측상단의 “IoT Mode”를 “ON”으로 활성화
-GetWeatherByAddress란에서 “The address to be searched”밑의 박스에 “Seoul”를 입력 뒤 코드의 생성을 위해 Run을 클릭
-CODE란에 생성된 코드 확인 및 복사 
– Configuration and Generation of CODE
7. IDE에서 Compile 및 다운로드
-“C:\Program Files\Arduino\libraries\Temboo\”폴더 밑에 아래와 같이 examples\YahooWeather폴더를 생성한다.
-“C:\Program Files\Arduino\libraries\Temboo\examples\YahooWeather”에 복사한 코드를 폴더명과 같은 이름으로 복사한다.
– 컴파일 후 다운로드
8. Demo: Serial Monitoring
아래와 같이 Seoul의 날씨를 HTTP Get을 통해 해당 웹페이지를 다운받아 Serial로 출력시키는 것을 볼 수 있다.
-Get Seoul Weather http message on Serial Monitoring

MicroLink is like a tiny Arduino with GSM

  • more smaller and more compact
  • Arduino Compatible
  • for M2M

Atmel | Bits & Pieces

Sydney-based  has officially launched a Kickstarter campaign for its new development board, MicroLink. Equipped with an Atmel ATmega328 MCU, the Arduino-compatible board is capable of automation, alerts, cellular data, phone calls, SMS messages and more.

photo-main-3

The MicroLink as more than just a tiny Arduino with GSM; in fact, its on-board USB and battery charging capabilities provide Makers with the capacity to implement professional quality wireless remote-monitoring and control. An ATmega328 allows for constant control, while a SIM800H quad band GSM module makes communication with wireless devices simple. Measuring just 50x32mm, there truly isn’t a place where the MicroLink couldn’t fit!

c5c6416038de2f30a4921d825d26553e_large

One of the most unique features of the MicroLink is that it comes ready to use out of the box with a true plug-and-play dynamic. “Each MicroLink comes with an SMS sketch pre-loaded – so you get the capacity to do remote monitoring and remote control, using SMS text messages, out of the box, a company rep explains on…

View original post 275 more words