1

I'm prototyping my Weather Station on Wemos D1 mini pro (ESP8266) with BME280 sensor and Nextion Display. The problem is that my display doesn't show data from the sensor and from the internet (openweathermap.org), it's only showing the static numbers which I assigned in Nextion Editor. Here's my code (I hid the ssid, password, apikey and CityID):

#include "Wire.h"
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include "SparkFunBME280.h"
BME280 mySensor;
float hums;
float temps;
float pres;

float tempitod;
float humitod;
float pressitod;
String data;
String result;

char ssid[] = "";
char pass[] = "";
String APIKEY = "";
String CityID = "";

WiFiClient client;
char servername[] = "api.openweathermap.org";

void setup() {
  Serial.begin(9600);
  Serial.print("restart");
  Wire.begin();
  Wire.setClock(400000);
  mySensor.setI2CAddress(0x76);
  mySensor.beginI2C();
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }
}

void loop() {
  hums = mySensor.readFloatHumidity();
  temps = mySensor.readTempC();
  pres = mySensor.readFloatPressure();
  getWeatherData();
  NextionData();
  Serial.print("Humidity: ");
  Serial.print(hums, 2);
  Serial.print(" Temp: ");
  Serial.print(temps, 2);
  Serial.print(" Pressure: ");
  Serial.print(pres, 2);
  Serial.println();
  delay(3000); 
  }

void getWeatherData()
{
  if (client.connect(servername, 80)) { 
    client.println("GET /data/2.5/weather?id=" + CityID + "&units=metric&APPID=" + APIKEY);
    client.println("Host: api.openweathermap.org");
    client.println("User-Agent: ArduinoWiFi/1.1");
    client.println("Connection: close");
    client.println();
  }
  while (client.connected() && !client.available()) delay(1); 
  while (client.connected() || client.available()) { 
    char c = client.read();
    result = result + c;
  }
  client.stop();
  result.replace('[', ' ');
  result.replace(']', ' ');
  char jsonArray [result.length() + 1];
  result.toCharArray(jsonArray, sizeof(jsonArray));
  jsonArray[result.length() + 1] = '\0';
  StaticJsonBuffer<1024> json_buf;
  JsonObject &root = json_buf.parseObject(jsonArray);
  String location = root["name"];
  String country = root["sys"]["country"];
  float temperature = root["main"]["temp"];
  float humidity = root["main"]["humidity"];
  String weather = root["weather"]["main"];
  String description = root["weather"]["description"];
  float pressure = root["main"]["pressure"];
  Serial.println(temperature);
  Serial.println(humidity);
  Serial.println(pressure);
  
  tempitod = temperature;
  humitod = humidity;
  pressitod = pressure;
}

void NextionData() {
  data = "tempitod.txt=\"" + String(tempitod, 1) + "\"";
  Serial.print(data);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  delay(500);
  data = "humitod.txt=\"" + String(humitod, 1) + "\"";
  Serial.print(data);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  delay(500);
  data = "pressitod.txt=\"" + String(pressitod, 1) + "\"";
  Serial.print(data);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  delay(500);
  data = "temps.txt=\"" + String(temps, 1) + "\"";
  Serial.print(data);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  delay(500);
  data = "hums.txt=\"" + String(hums, 1) + "\"";
  Serial.print(data);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  delay(500);
  data = "pres.txt=\"" + String(pres, 1) + "\"";
  Serial.print(data);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  delay(500);
}

The screen seems to be working fine, but it but doesn't gather data from the Wemos (and BME280). Could the problem be with bauds? I set the bauds in my code for 9600 but I don't know whether it changes anything. The strangest part is that, the debugger in Nextion Editor shows correct measurements.

Nxtion display looks like this right now (it doesn't gather data)

enter image description here

And the view from debugger looks like this (it gathers data correctly from the internet and BME280 sensor):

enter image description here

I don't know why Nextion doesn't display measurements.

Here's also photo from connecting Nextion to Wemos D1 mini. Maybe something is bad connected?:

enter image description here

enter image description here

I connected D7 pin from Wemos to RX on Nextion, and D4 pin from Wemos to TX on Nextion.

3
  • 1
    In NextionData() you appear to be writing Nextion commands using Serial. How is that possibly going to work? – romkey Aug 26 '20 at 22:51
  • @romkey It's a modified code from GreatScott: youtube.com/watch?v=daS2CE-zFNo&t=478s He uses exactly the same Wemos and Nextion. I thought it would work as good as he did. What should be there instead of "Serial"? – JimPanse Aug 27 '20 at 0:32
  • Why do you think Serial will communicate with the Nextion when you've connected the Nextion on D7 and D4, which are not the serial port lines? – romkey Aug 27 '20 at 2:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.