Reporting Sensor Data on IoT

Hey All! I'm using sensors that don't come with a library so I had to convert a c string into a float using the atof() function. When I print the float of the atof function on the serial monitor, I'm getting good values. However, when I try to link an IoT variable to the float, I just get zero. I've attached the code here. Is there anyway to show what's on the serial monitor on my dashboard?

const unsigned int MAX_MESSAGE_LENGTH = 13;

#include "thingProperties.h"

void setup() {
  Serial.begin(9600); //start serial communication with PC
  Serial4.begin(9600); //setting communication rate with R1 Gigia (serial port 4) at 9600 baud rate
  initProperties(); //defined in thingProperties library 
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);// connect to iot cloud  
  setDebugMessageLevel(2); 
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  
  while (Serial4.available() > 0) 
    {
      static char dissolvedoxygen[MAX_MESSAGE_LENGTH];
      static unsigned int domessage_pos = 0;
      char doinByte = Serial4.read();
  
  if ( doinByte != '\r' && (domessage_pos < MAX_MESSAGE_LENGTH - 1) )
    {
      dissolvedoxygen[domessage_pos] = doinByte;
      domessage_pos++;
    }
  
  else 
    {
      dissolvedoxygen[domessage_pos] = '\0';
      float dissolved_oxygen = atof(dissolvedoxygen);//store value as float
      Serial.println(dissolved_oxygen);
      domessage_pos = 0;
    }
    }
  
}

Hi!

Can you share the full sketch (with the comments at the beginning), so that we can see which ones are your Cloud variables?

Yes! Thank you!

I deleted the comments at the top but have pasted the things.h header file here so you can see my cloud variables:

// Code generated by Arduino IoT Cloud, DO NOT EDIT.

#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>

const char SSID[]     = SECRET_SSID;    // Network SSID (name)
const char PASS[]     = SECRET_OPTIONAL_PASS;    // Network password (use for WPA, or use as key for WEP)



float dissolved_oxygen;

void initProperties(){

  ArduinoCloud.addProperty(dissolved_oxygen, READ, 1 * SECONDS, NULL);

}

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

Probably this declaration of dissolved_oxygen is overwriting the one defined in the header file.
Please try to remove float here so that it's using the "cloud" variable.

dissolved_oxygen = atof(dissolvedoxygen);

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.