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.