Cannot send real values to the cloud (Asksensors)

Hello,

I am struggling with getting real values instead of random values, when I try to send values to a cloud-base called Asksensors. Those real values would be measured by my ESP32-attached BMP280 sensor. So I am using ESP32 (wroom-32D), BMP280 for temperature and pressure measurement, and Arduino IDE.

For experiment, I am trying to send only pressure values from the BMP280. I have already tested that the pressure sending to a local website works. But now, when I try to send the BMP280 pressure values to the cloud instead of the local website, I get confused on how to edit a provided source code template (available at 3- Connect ESP32 over HTTPS | AskSensors Documentation ).

Firstly, I downloaded an identical code http_get.ino from a Github repository as instructed in https://www.instructables.com/How-to-Connect-an-ESP32-to-the-IoT-Cloud/. I managed to upload the code and to get it to update random values (between 10 and 100) to the Asksensors website.

Now while I try to edit the source code above, I end up with the Serial monitor going bizarre. But all I actually did was that I edited url += random(10, 100); to be url += pressure; so that I declared earlier the BMP280 pressure to be pressure = bmp.readPressure();

Here is my edition of the source code template. I have bolded my amendments to the source code.

/*
  Connect ESP32 to AskSensors
 * Description:  This sketch connects to a website (https://asksensors.com) using an ESP32 Wifi module.
 *  Author: https://asksensors.com, 2018
 *  github: https://github.com/asksensors
 */
 
#include <WiFi.h>
#include <WiFiMulti.h>
#include <Wire.h>
**#include <Adafruit_BMP280.h>**
#include <HTTPClient.h>

**Adafruit_BMP280 bmp; // I2C

float pressure = bmp.readPressure(); **

WiFiMulti WiFiMulti;
HTTPClient ask;
// TODO: user config
const char* ssid     = "mokkula_351164"; //Wifi SSID
const char* password = "XXXXXXXXXXX"; //Wifi Password
const char* apiKeyIn = "9DhBkKau7Mdx1P6JizFtyvFvGzxcP8le";      // API KEY IN
const unsigned int writeInterval = 25000;   // write interval (in ms)

// ASKSENSORS API host config
const char* host = "api.asksensors.com";  // API host name
const int httpPort = 80;      // port
  
void setup(){ 
  
  // open serial
  Serial.begin(115200);
  Serial.println("*****************************************************");
  Serial.println("********** Program Start : Connect ESP32 to AskSensors.");
  Serial.println("Wait for WiFi... ");

  // connecting to the WiFi network
  WiFiMulti.addAP(ssid, password);
  while (WiFiMulti.run() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  // connected
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}


void loop(){  

  // Use WiFiClient class to create TCP connections
  WiFiClient client;


  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }else {
// Create a URL for updating module 1 and module2 request 
String url = "http://api.asksensors.com/write/"; 
url += apiKeyIn;
url += "?module1=";
url += **pressure; **
**//**url += "&module2=";   
**//**url += random(10, 100);
Serial.print("********** requesting URL: ");
Serial.println(url);

ask.begin(url); //Specify the URL
//Check for the returning code
int httpCode = ask.GET();
if (httpCode > 0) {
String payload = ask.getString();
Serial.println(httpCode);
Serial.println(payload);
} else {
Serial.println("Error on HTTP request");
}
ask.end(); //End
Serial.println("********** End ");
Serial.println("*****************************************************");
}
client.stop(); // stop client
delay(writeInterval); // delay
}

What is more, that code gives me a serial monitor screen that flickers with the following message every half seconds: https://i.ibb.co/NrbV6yh/serial-monitor-bizarre.jpg

Thanks for any advice! :face_with_raised_eyebrow:

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