rate I only get the first few, I guess closest reading a back these are wired where each group of 3 for average purposes are on a pin and I call the function to return the data via serial see below
#include <OneWire.h>
#include <DallasTemperature.h>
const byte numChars = 32;
char receivedChars[numChars];
boolean newData = false;
#define RELAY_OFF 0
#define RELAY_ON 1
void ProcessSerialData()
{
static boolean recieveInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
while(Serial.available() > 0 && newData == false)
{
rc = Serial.read();
if(recieveInProgress == true)
{
if(rc != endMarker)
{
receivedChars[ndx] = rc;
ndx++;
if(ndx >= numChars)
{
ndx = numChars - 1;
}
}
else
{
receivedChars[ndx] = '\0';
recieveInProgress = false;
ndx = 0;
newData = true;
}
}
else if(rc == startMarker)
{
recieveInProgress = true;
}
}
}
void ShowNewData()
{
if(newData == true)
{
ProcessSerialInput(receivedChars);
//Serial.println(receivedChars);
newData = false;
}
}
void ProcessSerialInput(String data)
{
if(data.substring(0, 5) == "relay")
{
if(data.substring(7, 9) == "on")
{
int p = data.substring(5, 7).toInt();
RelayControl(p, RELAY_ON);
}
else if(data.substring(7, 9) == "of")
{
int p = data.substring(5, 7).toInt();
RelayControl(p, RELAY_OFF);
}
}
else if(data.substring(0, 5) == "tstat")
{
if(data.substring(7, 9) == "aa")
{
int p = data.substring(5, 7).toInt();
ProcessTemperature(p);
}
}
}
void RelayControl(int Pin, unsigned char Status)
{
pinMode(Pin, OUTPUT);
digitalWrite(Pin, Status);
Serial.println("RELAY,PIN," + String(Pin) + "," + String(Status));
}
String GetSensorAddress(DeviceAddress device)
{
String address;
address += "[";
for(uint8_t i = 0; i < 8; i++)
{
address += String("0x");
if(device[i] < 0x10)
{
address += String("0");
}
address += String(device[i], HEX);
if(i < 7)
{
address += String(", ");
}
}
address += String("]");
return address;
}
void ProcessTemperature(int Pin)
{
String serialDataTemp = "";
String address = "";
float tempC;
OneWire OneWireBus(Pin);
DallasTemperature Sensor(&OneWireBus);
Sensor.begin();
Sensor.requestTemperatures();
for(int i = 0; i < Sensor.getDeviceCount(); i++)
{
tempC = Sensor.getTempCByIndex(i);
Serial.println("TEMP,PIN," + String(Pin) + "," + String(tempC));
}
}
void setup()
{
Serial.begin(115200);
}
void loop()
{
ProcessSerialData();
ShowNewData();
}
Then I have another issue where when I send another command to turn relays on I either get a working system or nothing happens at all, the relay does not act at all.
With node red I’m sending commands such as
to get the data from a pin with 3 ds18b20 on so that returns 3 messages.
Such as
[ “temp”, 22, 18.0 ]
Which I can then work with, this is working ok except the random missing sensors with certain call intervals
The relays my biggest issue is send
or
Sometimes it works sometimes it doesn’t, not sure what’s happening here. It either works great or completely not at all.
I can’t post the node red code here as it’s too large but I build a string as msg.payload and send it to Arduino via serial.
I’m using serial response for the temperature calls which seems to work well, not sure if that’s relevant
