[SOLVED] Oak device sends temp values to Ubidots

Hi,

I’m connecting several devices to ubidots, I checked it out with arduino uno sending every 3 seconds through ethernet module and after changing the library it works perfectly.
When I say after changing the library I mean that before I wanted to send those information and after 3 or 4 hours the connection was out and arduino couldn’t send more information but with a new library of this community I was able to make it works well.

My problem now is with oak device of digistump ( ESP8266 ), I’am having the same problem with one code I use:

#include <OneWire.h>
#include <DallasTemperature.h>
#include <WiFiClient.h>
#include <ESP8266WiFi.h>

/*-----( Declare Constants and Pin Numbers )-----*/
#define ONE_WIRE_BUS_PIN 2

/*-----( Declare objects )-----*/
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS_PIN);
// Pass our oneWire reference to Dallas Temperature.p,
DallasTemperature sensors(&oneWire);
int status = WL_IDLE_STATUS;     // the Wifi radio's status
WiFiClient client;

/*-----( Declare Variables )-----*/
DeviceAddress Probe01 = { 0x28, 0xFF, 0xA4, 0xD9, 0x62, 0X16, 0x04, 0x3B }; 
DeviceAddress Probe02 = { 0x28, 0xFF, 0xA9, 0xD9, 0x62, 0x16, 0x04, 0xD7 };
double temp1,temp2;
String tubi1 = "xx";
String tubi2 = "xx";
String token = "xx";


void setup()   /****** SETUP: RUNS ONCE ******/
{
  // start serial port to show results
  Serial.begin(9600);
  Serial.print("Initializing Temperature Control Library Version ");
  Serial.println(DALLASTEMPLIBVERSION);
  
  // Initialize the Temperature measurement library
  sensors.begin();
  
  // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
  sensors.setResolution(Probe01, 10);
  sensors.setResolution(Probe02, 10);

  Particle.variable("temp1", temp1);
  Particle.variable("temp2", temp2);
  
  if (Particle.connected() == false)
  {
    Particle.connect();
  }

}//--(end setup )---

void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
   WiFiClient client;
   if (Particle.connected() == false)
  {
    Particle.connect();
  } if (Particle.connected() == false)
  {
    Particle.connect();
  }
  delay(60000);
   // Command all devices on bus to read temperature  
  sensors.requestTemperatures();  
  
  Serial.print("Probe 01 temperature is:   ");
  temp1 = sensors.getTempC(Probe01);
  Serial.println(temp1);
  updateUnidots(temp1,tubi1);
  

  Serial.print("Probe 02 temperature is:   ");
  temp2 = sensors.getTempC(Probe02);
  Serial.println(temp2);
  updateUnidots(temp2,tubi2);
 
}//--(end main loop )---

boolean updateUnidots(double value,String idvariable)
{
// if you get a connection, report back via serial:
  int num=0;
  String var = "{\"value\": " + String(value)+"}";
  num = var.length();
  if (client.connect("things.ubidots.com", 80)) {
    delay(100);
    client.println("POST /api/v1.6/variables/"+idvariable+"/values HTTP/1.1");
    client.println("Content-Type: application/json");
    client.println("Content-Length: "+String(num));
    client.println("X-Auth-Token: "+token);
    client.println("Host: things.ubidots.com\n");
    client.print(var);
    }
        }

//*********( THE END )***********

I tried to use the ESP8266 code of tutorials but It doesn’t send anything:

#include <UbidotsESP8266.h>
#include <SoftwareSerial.h> 

#define SSID "xx"
#define PASS "xx"

#define TOKEN "xx"
#define ID "xx"

Ubidots client(TOKEN);

void setup() {
  Serial.begin(9600);
  client.wifiConnection(SSID,PASS);
}

void loop() {
  float value = analogRead(A0);
  client.add(ID,value);
  client.sendAll();
}

I don’t know how to use this code properly or adjust the first one code to work as arduino uno is doing during hours and hours…

Thanks.

Hi @lluis,

We recommend you to take a look at our MQTT ESP library, where you’ll find examples you can follow and use for your project. Also, you can check this video tutorial

Regards.

Hi maria,

I have compilation problems with it ( I’ve installed the MQTT library and the PubSubClient )
And those are the errors and warnings when I try to compile with my board.

C:\Users\iMAC4L\Documents\Arduino\publish_example\publish_example.ino:15:37: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

Ubidots client(TOKEN, MQTTCLIENTNAME);

                                 ^

C:\Users\iMAC4L\Documents\Arduino\publish_example\publish_example.ino:15:37: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

C:\Users\iMAC4L\Documents\Arduino\publish_example\publish_example.ino: In function ‘void loop()’:

C:\Users\iMAC4L\Documents\Arduino\publish_example\publish_example.ino:50:26: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

client.add(“test”, 10.2); //Insert your variable Labels and the value to be sent

                      ^

C:\Users\iMAC4L\Documents\Arduino\publish_example\publish_example.ino:51:28: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

client.ubidotsPublish(“1”);

                        ^

C:\Users\iMAC4L\Documents\Arduino\libraries\ubidots-mqtt-esp-master\UbidotsESPMQTT.cpp: In member function ‘bool Ubidots::add(char*, float)’:

C:\Users\iMAC4L\Documents\Arduino\libraries\ubidots-mqtt-esp-master\UbidotsESPMQTT.cpp:46:52: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

 return add(variableLabel, value, "NULL", "NULL");

                                                ^

C:\Users\iMAC4L\Documents\Arduino\libraries\ubidots-mqtt-esp-master\UbidotsESPMQTT.cpp:46:52: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

C:\Users\iMAC4L\Documents\Arduino\libraries\ubidots-mqtt-esp-master\UbidotsESPMQTT.cpp: In member function ‘bool Ubidots::add(char*, float, char*)’:

C:\Users\iMAC4L\Documents\Arduino\libraries\ubidots-mqtt-esp-master\UbidotsESPMQTT.cpp:51:53: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

 return add(variableLabel, value, context, "NULL");

                                                 ^

C:\Users\iMAC4L\Documents\Arduino\libraries\ubidots-mqtt-esp-master\UbidotsESPMQTT.cpp: In member function ‘bool Ubidots::wifiConnection(char*, char*)’:

C:\Users\iMAC4L\Documents\Arduino\libraries\ubidots-mqtt-esp-master\UbidotsESPMQTT.cpp:142:27: error: call to ‘ESP8266WiFiClass::begin’ declared with attribute error: You must use the WiFi config mode to change the Oaks network info.

 WiFi.begin(ssid, pass);

                       ^

exit status 1
Error al compilar per a la placa Oak by Digistump (Pin 1 Safe Mode, Manual Config Only).

Hi @lluis,

Our library is based on the “PubSubClient library”, so we recommend you follow a basic example from these library. Once you have done the example and it works as it should be, tell us and we can send you an already structured code for you to follow as an example.

At the moment we doesn’t support the Oak Board.