This is most likely a basic question but I'm used to Python, PHP and JS where strings and other data types are really easy to work with.
For some reason this bit of code produces the output below where all three char values output as intended but, when added to JSON via the ArduinoJson library, the three values always present as the last temp_3 value-. What did I do wrong?
char fValue[16];
char *temp_1 = dtostrf(sensors.getTempC(sensor1) + temp_offset_1, 3, 2, fValue);
TelnetStream.print("Outgoing Temp(*C): ");
TelnetStream.println(temp_1);
char *temp_2 = dtostrf(sensors.getTempC(sensor2) + temp_offset_2, 3, 2, fValue);
TelnetStream.print("Incoming Temp(*C): ");
TelnetStream.println(temp_2);
char *temp_3 = dtostrf(sensors.getTempC(sensor3) + temp_offset_3, 3, 2, fValue);
TelnetStream.print("Outside Temp(*C): ");
TelnetStream.println(temp_3);
// publish stuff
StaticJsonBuffer<300> JSONbuffer;
JsonObject& JSONencoder = JSONbuffer.createObject();
JSONencoder["outgoing_temp"] = temp_1;
JSONencoder["incoming_temp"] = temp_2;
JSONencoder["outside_temp"] = temp_3;
char JSONmessageBuffer[108];
JSONencoder.printTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
TelnetStream.print("Publishing to MQTT: ");
TelnetStream.println(JSONmessageBuffer);
char *topic = "heat_exchange"; // Topic to subcribe to
client.publish(topic, JSONmessageBuffer);
Outputs this. Sensor values are unique. JSON values all use the last sensor value.:
Requesting temperatures ...... DONE
Outgoing Temp(*C): 18.78
Incoming Temp(*C): 18.75
Outside Temp(*C): 18.69
Publishing to MQTT: {"outgoing_temp":"18.69","incoming_temp":"18.69","outside_temp":"18.69"}