I am trying to publish data from 2 one wire temp sensors.I can print data to the serial port but am having trouble doing a particle.publish in the code. I am kind of a newb at this and would appreciate any help.Can someone show me code to publish temp 1 and temp 2.
thanks
Dennis Mitchell
// This #include statement was automatically added by the Particle IDE.
#include <OneWire.h>
//#include "OneWire/OneWire.h"
OneWire ds = OneWire(D2); // 1-wire signal on pin D4
byte addrs[3][8] = {{0x28, 0xDE, 0x4F, 0x7, 0xD6, 0x1, 0x3C, 0xD8}, {0x28, 0x9F, 0x7, 0x79, 0xA2, 0x1, 0x3, 0x7E}};
float temps[3];
float celsius, fahrenheit;
void setup() {
Serial.begin(9600);
delay(3000);
}
void loop() {
ds.reset();
ds.skip(); // Make all devices start the temperature conversion
ds.write(0x44, 0); // tell it to start a conversion, with parasite power on at the end
//ds.write(0x44, 0); // or start conversion in powered mode (bus finishes low)
delay(1000); // wait 1 sec for conversion
ds.reset();
for (int i=0; i<3; i++) {
ds.select(addrs[i]);
ds.write(0xBE,0); // Read Scratchpad
byte data0 = ds.read();
byte data1 = ds.read();
ds.reset();
int16_t raw = (data1 << 8) | data0;
celsius = (float)raw * 0.0625;
fahrenheit = celsius * 1.8 + 32.0;
temps[i] = fahrenheit;
}
Serial.printlnf("Temp 1: %.1f Temp 2: %.1f", temps[0], temps[1]);
delay(10000);
}