New to IOT.
I`ve set up a temperature dashboard. The serial monitor reads the value with 2 decimal places, were the one on the chard reads 3 decimal places.
Is there a way so that the dashboard only displays 1 decimal places?
#include <OneWire.h>
#include <DallasTemperature.h>
#include "thingProperties.h"
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float tempCelcius = 0;
int analogPin = A3;
void setup() {
//pinMode(2, INPUT_PULLUP);
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
sensors.begin();
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Your code here
analog = analogRead(analogPin); // read the input pin
//Serial.println(analog); // debug value
sensors.requestTemperatures();
tempCelcius = sensors.getTempCByIndex(0);
Serial.print("T = ");
Serial.print(temp);
Serial.println("ºC");
temp = tempCelcius;
}
/*
Since Analog is READ_WRITE variable, onAnalogChange() is
executed every time a new value is received from IoT Cloud.
*/
void onAnalogChange() {
// Add your code here to act upon Analog change
}
Appologies. I have not copied the top description. The Temp is somehow predefined when you create "thing" hence for me to have it displayed on the chart i had to link "Temp" with the TempCelcius so that the data can be forwarded do dashboard. ( I think)
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/a0c6a2b4-63f4-4586-be40-f0e857368a23
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
int analog;
CloudTemperature temp;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include <OneWire.h>
#include <DallasTemperature.h>
#include "thingProperties.h"
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float tempCelcius = 0;
int analogPin = A3;
void setup() {
//pinMode(2, INPUT_PULLUP);
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
sensors.begin();
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Your code here
analog = analogRead(analogPin); // read the input pin
//Serial.println(analog); // debug value
sensors.requestTemperatures();
tempCelcius = sensors.getTempCByIndex(0);
Serial.print("T = ");
Serial.print(temp);
Serial.println("ºC");
temp = tempCelcius;
}
/*
Since Analog is READ_WRITE variable, onAnalogChange() is
executed every time a new value is received from IoT Cloud.
*/
void onAnalogChange() {
// Add your code here to act upon Analog change
}
the point is that there is predefined temperature on the IOT which seems not to be made for working with tempeature unless someone need such a precise 3 decimal points for temp.
Otherwise, sending the value as float is far more simpler in this case i think.
By the way, the temp = (int) ((tempCelcius + 0.05) * 10) / 10.0; does the trick.