Code issue, with sensors not being able to upload data

#include "DHT.h"
#include "PMS.h"
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266HTTPClient.h>
#include <SoftwareSerial.h>
#define DHTPIN D1
#define DHTTYPE DHT11

SoftwareSerial pmsSerial(D4, D3);

const char *ssid = "";
const char *password = "";
const char *serverName = "http://192.168.0.35:5000/upload-data";

// String apiKeyValue = "tPmAT5Ab3j7F9";

String sensorName = "PMTL_Sensor1";
String sensorLocation = "55108";
String httpRequestData;

DHT dht(DHTPIN, DHTTYPE);
WiFiClient wifi;

PMS pms(pmsSerial);
PMS::DATA data;

void setup()
{
    Serial.begin(9600);
    pmsSerial.begin(9600);
    dht.begin();
    WiFi.enableInsecureWEP(true);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED)
    {
        Serial.println("Waiting");
        delay(500);
    }
    Serial.println("Connected!!");
}

void loop() {
    Serial.println("Output!!");
    float h = dht.readHumidity();
    float t = dht.readTemperature();
    if (WiFi.status() == WL_CONNECTED) {
        Serial.println("Output123!!");
        if (pms.read(data)) {
            HTTPClient http;
            http.begin(wifi, serverName);
            http.addHeader("Content-Type", "application/json");
            String payload = "{";
            payload += "\"SensorID\":\"" + sensorName + "\",";
            payload += "\"location\":\"" + sensorLocation + "\",";
            payload += "\"temp\":" + String(t) + ",";
            payload += "\"humidity\":" + String(h) + ",";
            payload += "\"pm10\":" + String(data.PM_AE_UG_1_0) + ",";
            payload += "\"pm25\":" + String(data.PM_AE_UG_2_5) + ",";
            payload += "\"pm100\":" + String(data.PM_AE_UG_10_0) + ",";
            payload += "\"particles03\":" + String(data.P_03);
            payload += "}";
            
            int httpResponseCode = http.POST(payload);
            Serial.println("HTTP Response code: " + String(httpResponseCode));
            http.end();
        }
    }
}

The serial monitor is showing waiting on this code, what would be the issue here? the code compiles and uploads but the serial monitor shows waiting as the result

Well, if it's stuck at "Waiting", then the while condition is still satisfied, which would mean WiFi isn't connected, wouldn't it?

I double-checked and everything is connected I even made sure nothing is connected with the ethernet just in case.

What pins are your serial TX and RX on?(IDK, don't have time to look it up)

Post an annotated schematic showing exactly how you have wired it.

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