Go Down

Topic: Sending a float seems to be a no go... int and bool ok though! (Read 346 times) previous topic - next topic



I suspect I'm missing something really obvious here so I'll appreciate a nudge in the right direction please!

I'm using a MKR1010 and have no issues at all sending and receiving bool and int type values to and from the device and web dashboard... but floats seem to be a no go!  Whether defined in the dashboard as a float, or a percentage or a temperate.

In the below, the int and the bool return data fine, but nothing from the floats.  What am I missing please?

Thanks in advance,

-- Chirs

thingproperties.h snipped
Code: [Select]

void onAmbientHumidityChange();

float ambientTemperature;
int inttest;
bool boolTest;
float ambientHumidity;

void initProperties(){
  ArduinoCloud.addProperty(ambientTemperature, READ, ON_CHANGE, NULL);
  ArduinoCloud.addProperty(inttest, READ, ON_CHANGE, NULL);
  ArduinoCloud.addProperty(boolTest, READ, ON_CHANGE, NULL);
  ArduinoCloud.addProperty(ambientHumidity, READWRITE, ON_CHANGE, onAmbientHumidityChange);

ConnectionManager *ArduinoIoTPreferredConnection = new WiFiConnectionManager(SSID, PASS);

.ino snippet
Code: [Select]
#include "thingProperties.h"

void setup() {
  // Initialize serial and wait for port to open:
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found

  // Defined in thingProperties.h

  // Connect to Arduino IoT Cloud
     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
  //initialise variables
  boolTest = true;
  inttest = 0;
  ambientTemperature = 15;
  ambientHumidity = 50;

void loop() {
  // Your code here
  boolTest = !boolTest;




hi @homegeek

I've been running your code successfully today for a while and float variables get updated correctly.
I would anyway advise not to change their values in a loop.

ArduinoCloud.update() synchronises the board data with the Cloud properties and because there's a number of maximum allowed calls per second many of your updates will be bounced.

Also we advise against using delay() in the loop because that will effectively delay the execution of the update call hence preventing you from receiving the update from IoT Cloud until the loop is started again.

Using time tracking is a better way to perform operations in a scheduled way, or use a timing library (there's quite a few out there which allow you to perform timed tasks).

It would be interesting if you could paste the first output you get from the Serial Monitor.
It should be something like this

Code: [Select]

***** Arduino IoT Cloud - configuration info *****
Device ID: 40916e87-af4b-44e6-b9a8-1995462b901a
Thing ID: f20c41d0-0f8a-4c59-b33b-0f024a0818a2
MQTT Broker: mqtts-sa.iot.arduino.cc:8883
WiFi.status(): 0
Current WiFi Firmware: 1.0.0
Connecting to...

if you are using Create, the first time this output is received it might be flushed, in that case reset the board without closing the Serial Monitor.

Let me know what comes out of that :)



Hi Ubi,

Thanks ever so much for trying it.  I've tried again this morning - setting up some straightforward properties in the web interface then setting initial values in setup(), all seems to be working now, I wonder whether there was a transient issue of some sort.  I was definitely getting some weird behaviour.

Thanks again

ps Agree with poor use of delay!

Go Up