The LinkIt ONE development board is an open source board for prototyping IoT projects. We really liked the fact that it already includes built-in connectivity like GSM, GPRS, Wi-Fi, Bluetooth and GPS!

Requirements

To complete this tutorial all you need is the LinkIt ONE board:

Setup

  1. Download Arduino IDE version 1.6.5 or higher, here.
  2. From within the Arduino IDE, go to File -> Preferences dialog box.
  3. Look at the text entry field called “Additional Boards Manager URLs:”.
  4. Just copy/paste the following URL into that text field “http://download.labs.mediatek.com/package_mtk_linkit_index.json”. Then click OK to close.
  5. Now select the Tools -> Board -> Board Manager menu from the Arduino IDE, and it will open up the Boards Manager window. From there, scroll down until you see the LinKIt ONE device.
  6. Now choose a LinKIt ONE board from the Tools -> Board menu and program your LinKIt ONE!

To use this library, put your Ubidots token and variable ID where indicated, as well as the APN settings. After uploading each example to your Arduino, open the Serial monitor to check the results. If no response is seen, try unplugging your Linkit ONE and then plugging it again. Make sure the baud rate of the Serial monitor is set to the same one specified in your code.

Send values to Ubidots

After installing the LinkIt SDK (for Arduino) you need to follow these 2 steps. If you haven’t installed it, then check this page from the manufacturer.

1.- In the Arduino IDE, select the LinkIt ONE as your Board:

2.- Copy and paste the following code:

#include <LGPRS.h>      //include the base GPRS library
#include <LGPRSClient.h>  //include the ability to Post and Get information using HTTP
#include <LGPRSUdp.h>
#include <LWiFi.h>
#include <LWiFiClient.h>

// These are the variables you will want to change based on your IOT data streaming account / provider

#define WEBSITE "things.ubidots.com"
#define URL "/api/v1.6/collections/values/?token=0hib2iZ2QM0crclQxahhN0ELKy2XUi&force=true"
#define idvariable1 "569cfd69762542574c3556c0"
#define idvariable2 "569cfd72762542583473c381"
#define idvariable3 "569cfd847625425574aa5c78"

#define WIFI_AP "SOBIOTECH"
#define WIFI_PASSWORD "BIOTECH007"
#define WIFI_AUTH LWIFI_WPA  // choose from LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP.

const int PACKET_SIZE = 3;
byte packetBuffer[PACKET_SIZE];
LGPRSUDP u;


char payload[180];  // Reserve a char to store the Ubidots data. Account for 60 bytes per variable.
char le[4];
String response;
int temp;

void setup()
{
  Serial.begin(115200);             // setup Serial port
  pinMode(13, OUTPUT);
 /* Serial.println("Attach to GPRS network");   // Attach to GPRS network - need to add timeout
  while (!LGPRS.attachGPRS("internet.comcel.com.co","","")) {
    delay(500);
  }
  Serial.println("GPRS attached!");
  delay(10000);
*/
  LWiFi.begin();
  // keep retrying until connected to AP
  Serial.println("Connecting to AP");
  while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD)))
  {
    delay(1000);
  }
  Serial.println("Connected to WiFi");
}

void loop(){
  int temp = analogRead(A0);
  int ph = analogRead(A1);
  int orp = analogRead(A2);
  save_values(temp, ph, orp);
  //save_values2(temp, ph, orp);
  delay(1000);
}

void save_values(int val1, int val2, int val3){

  //LGPRSClient client;
  LWiFiClient client;

  sprintf(payload,"%s", "[");
  sprintf(payload,"%s%s", payload, "{\"variable\":\"" idvariable1 "\",\"value\":");
  sprintf(payload,"%s%d", payload, val1);
  sprintf(payload,"%s%s", payload, "},{\"variable\":\"" idvariable2 "\",\"value\":");
  sprintf(payload,"%s%d", payload, val2);
  sprintf(payload,"%s%s", payload, "},{\"variable\":\"" idvariable3 "\",\"value\":");
  sprintf(payload,"%s%d", payload, val3);
  sprintf(payload,"%s%s", payload, "}]");

  // Get length of the entire payload
  sprintf(le,"%d", strlen(payload));

  Serial.println("Sending: ");  
  Serial.println(payload);

  // Connect to Ubidots...

  if (client.connect(WEBSITE, 80)){  
    Serial.println("Connected!");  // Console monitoring

    client.print(F("POST "));
    client.print(URL);
    client.print(F(" HTTP/1.1\r\n"));
    client.print(F("Content-Type: application/json\r\n"));
    //client.print(F("Connection: close\r\n"));
    client.print(F("Host: "));
    client.print(WEBSITE);
    client.print(F("\r\n"));
    client.print(F("Content-Length: "));
    client.print(le);
    client.print(F("\r\n"));
    client.print(F("\r\n"));
    client.print(payload);
    client.println();

  } else {
    Serial.println(F("Connection failed"));
  }

  client.stop();
}

void save_values2(uint8_t val1, uint8_t val2, uint8_t val3){

  Serial.println(val1);
  Serial.println(val2);
  Serial.println(val3);

  memset(packetBuffer, 0, PACKET_SIZE);
  packetBuffer[0] = val1;
  packetBuffer[1] = val2;
  packetBuffer[2] = val3;

  u.beginPacket(IPAddress(50,23,124,66), 1234);  
  u.write(packetBuffer, 3);
  u.endPacket();  // actually send the packet
  Serial.println("Sent");
}
Did this answer your question?