I have beat myself up forever trying to figure out why when I run some test code this works…
int value = 65;
String command = "setLevel";
request.path = subfolder + "/" + oathubid + "/" + command + "/" + String(value) + "?access_token=" + hubitataToken;
http.get(request, response, headers);
however when I implement it here in my actual code sending real data from a ds18b20 temp probe it doesnt work…
// this is basically the ds18b20 sample code to obtain a temperature reading until the very bottom
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
if ( !ds.search(addr)) {
ds.reset_search();
delay(250);
return;
}
switch (addr[0]) {
case 0x10:
type_s = 1;
break;
case 0x28:
type_s = 0;
break;
case 0x22:
type_s = 0;
break;
case 0x26:
type_s = 2;
break;
default:
return;
}
ds.reset();
ds.select(addr);
ds.write(0x44, 0);
delay(1000);
present = ds.reset();
ds.select(addr);
ds.write(0xB8,0);
ds.write(0x00,0);
present = ds.reset();
ds.select(addr);
ds.write(0xBE,0);
if (type_s == 2) {
ds.write(0x00,0);
}
for ( i = 0; i < 9; i++) {
data[i] = ds.read();
}
int16_t raw = (data[1] << 8) | data[0];
if (type_s == 2) raw = (data[2] << 8) | data[1];
byte cfg = (data[4] & 0x60);
switch (type_s) {
case 1:
raw = raw << 3;
if (data[7] == 0x10) {
raw = (raw & 0xFFF0) + 12 - data[6];
}
celsius = (float)raw * 0.0625;
break;
case 0:
if (cfg == 0x00) raw = raw & ~7;
if (cfg == 0x20) raw = raw & ~3;
if (cfg == 0x40) raw = raw & ~1;
celsius = (float)raw * 0.0625;
break;
case 2:
data[1] = (data[1] >> 3) & 0x1f;
if (data[2] > 127) {
celsius = (float)data[2] - ((float)data[1] * .03125);
}else{
celsius = (float)data[2] + ((float)data[1] * .03125);
}
}
if((((celsius <= 0 && celsius > -1) && lastTemp > 5)) || celsius > 125) {
celsius = lastTemp;
}
fahrenheit = celsius * 1.8 + 32.0;
lastTemp = celsius;
//------------------------------------------------------------------------------
// my additions to round and handle the data
//----------------------------------------------------------------------------
float roatf = (fahrenheit + 0.5); // add .5 so that when you convert it to an interger value it rounds appropriately
String roat(roatf, 0); // string of rounded with zero decimal points
ioat = atoi(roat); // int of rounded data
String oat = String(fahrenheit); // raw data string
// make http refresh command to hubitat
String command = "setLevel"; // command to send
request.path = subfolder + "/" + oathubid + "/" + command + "/" + roat + "?access_token=" + hubitataToken; // parse the path as needed
http.get(request, response, headers); // send the whole request off
// and particle publish
if (cloudconnected == true){
Particle.publish("OAT", roat, PRIVATE);
}
I cant figure out why whatever its sending off in this example would be any different then the test sample where I manually set an interger to send off. but it definitely doesnt like something with the ds18b20 data vs my manual sending of an interger. when I check the console that particle publish says 65