Cloud Blink works, my own sketch doesn't

RP2040 with bmp280 over I2C

Temperature and pressure should be displayed in the cloud.
Sketch is uploaded, but dashboard always shows 0. Both values ​​are displayed correctly in the serial monitor. What am I doing wrong?

#include "thingProperties.h"

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>

Adafruit_BMP280 bmp;                  // I2C





void setup() {

  Serial.begin(9600);
  Serial.println(F("BMP280 test"));

  if (!bmp.begin()) {
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
    while (1);
  }
  delay(1500);

  initProperties();

  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}



void loop() {
  ArduinoCloud.update();

  float myTemp = 0;
  myTemp = bmp.readTemperature();
  Serial.print(F("Temperature = "));
  Serial.print(myTemp);
  Serial.println(" *C");

  float myPress = 0;
  myPress = bmp.readPressure();
  Serial.print(F("Pressure = "));
  Serial.print(myPress / 100);
  Serial.println(" mbar");

  Serial.print(F("Approx altitude = "));
  Serial.print(bmp.readAltitude(1001.1)); // this should be adjusted to your local forcase
  Serial.println(" m");

  Serial.println();
  delay(2000);
}


myTemp
Declaration
float
myTemp
Type
Floating point number
Variable Permission
Read Only
Send Values
On change
threshold: 0
ID
12c231e2-a188-4090-8ed9-c142dc4b0a88
Last Value
0
Last Update
31 Mar 2023 15:01:25
EDIT VARIABLE
// 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 myPress;
float myTemp;

void initProperties(){

  ArduinoCloud.addProperty(myPress, READ, ON_CHANGE, NULL);
  ArduinoCloud.addProperty(myTemp, READ, ON_CHANGE, NULL);

}

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

Hi!
The first thing that I would try is to remove the delay() from the loop(). That can interfere with the ArduinoCloud.update(). Using blocking delays inside the loop() should always be avoided when using the ArduinoIoTCloud library.

If what you want is to read the sensor every 2 seconds, you can use this alternative code:

Declare the following global variables:

unsigned long previousMillis = 0;  // variable to store the previous time
const long interval = 2000;       // interval at which to run the command (milliseconds)

and include this code in the loop()

  // put your main code here, to run repeatedly:
  unsigned long currentMillis = millis();  // get the current time

  if (currentMillis - previousMillis >= interval) { // if the interval has passed
    previousMillis = currentMillis;  // reset the previous time

    // put your commands to read the sensor here:
    // ...
  }

I hope this helps!

it works now:

doesn't work again :sweat_smile::

As soon as I change something in the cloud, the cloud overwrites the thingProperties.h and then I don't get any new values.

functions:

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

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

const char THING_ID[] = "0914cf4a-f48b-4c65-bd9d-72d578e73b7b";

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 myPress;
float myTemp;

void initProperties(){
  
  ArduinoCloud.setThingId(THING_ID);
  ArduinoCloud.addProperty(myPress, READ, ON_CHANGE, NULL, 1.000000);
  ArduinoCloud.addProperty(myTemp, READ, 5 * SECONDS, NULL, 1.000000);

}

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

it does not work:

// 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 myPress;
float myTemp;

void initProperties(){
  
  ArduinoCloud.addProperty(myPress, READ, ON_CHANGE, NULL);
  ArduinoCloud.addProperty(myTemp, READ, 5 * SECONDS, NULL);

}

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

I added the millis anyway... :+1:

Hey!
You shouldn't edit yourself directly the thingProperties.h file. It is autogenerated.

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