[SOLVED] Contiki OS - Cannot send temperature values to the Ubidots Cloud

Hello everyone!

I am trying to send data to the cloud (Ubidots) without having to enter manually the values of temperature and humidity on the linux console using curl like in step #7 of this tutorial: http://ubidots.com/docs/get_started/quickstart/tutorial-collections.html

This method works on real time without any delay but, for instance, if I want to record data of temperature and humidity of a house for 1 week, I won’t be able to do so as a user would have to be continously enter the values on the linux terminal using this command:
curl -XPOST -H ‘Content-Type: application/json;’ -H ‘X-Auth-Token: ENTER_TOKEN_HERE’ -d ‘[{“variable”: “ID_TEMPERATURE”, “value”: 23}, {“variable”: “ID_HUMIDITY”, “value”: 43.97}]’ http://things.ubidots.com/api/v1.6/collections/values

I am using Contiki OS and I receive values of temperature and humidity in real time using a temperature and humidity sensor. I’m running a program (test-sht25.c) where its output are the values of temperature and humidity. The code of my program is this one:

 
#include < stdio.h >
#include "contiki.h"
#include "dev/sht25.h"

PROCESS(test_sht25_process, "SHT25 test");
AUTOSTART_PROCESSES(&test_sht25_process);

static struct etimer et;

PROCESS_THREAD(test_sht25_process, ev, data)
{
  int16_t temperature, humidity;

  PROCESS_BEGIN();
  SENSORS_ACTIVATE(sht25);

  while(1) {
    etimer_set(&et, CLOCK_SECOND * 15);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
    temperature = sht25.value(SHT25_VAL_TEMP);
    printf("Temperature %d.%d ºC\n", temperature / 100, temperature % 100);
    humidity = sht25.value(SHT25_VAL_HUM);
    printf("Humidity %d.%d %%RH\n", humidity / 100, humidity % 100);
  }
  PROCESS_END();
}

So basically I want the output of my program to be the input of the curl command line on linux (I want to replace the values of temperature (23) and humidity (43.97) with the values I get on my program).

Hi!

Understood. Ubidots offers a REST API, which means you need to setup an HTTP request to talk to its API. Now, there are different options to do this:

  • Using pure C
  • Invoking curl from a shell script
  • Using Lua
  • Using a Contiki

If you are an advanced Contiki user, I’d go for the last option; there’s actually a Contiki+Ubidots example done by George Oikonomou, one of the main Contiki contributors: https://github.com/g-oikonomou/contiki/tree/ubidots-demo/examples/ipv6/ubidots

If you use something simpler, let us know your choice and we’ll take it from there.

Why dont you:

  • modify the C code to output the results in the Ubidots JSON format
  • schedule the C script to run every 5 minutes
  • schedule a curl -d @filename -h etc. etc. to post the file rather than a string. Schedule it every 5 minutes too.

it doesnt matter so much if the two scripts dont quite line up - when you look at monthly temperature data it doesnt need to be accurate to the minute - so schedule one at 02 and one at 04 past etc.