Skocz do zawartości

Problem z pobieraniem informacji z Openweathermap


Maciokeks

Pomocna odpowiedź

Witam mam problem z pobieraniem temperatury z Openweathermap, gdyż kiedy minie 10s to na ekranie w polu P(ciśnienie) pokazują się zbyt wysokie liczby tak samo na innych polach gdzie są zmienne wstawione do wyświetlania. Ogólnie wszystko się ładnie kompiluje ale występują takie problemy. Wszystko prawidłowo działa jak jest czysty kod do pobierania informacji z OpenWeathermap. Do wemosa D1 mini pro jest podpięty DS18B20, DS1307, 1.8 tft display i pasek 8 diod WS (na razie nie miałem czasu je odpalać)



#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(D4); //Podłączenie do A5
DallasTemperature sensors(&oneWire); //Przekazania informacji do biblioteki


#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#define TFT_CS     D8
#define TFT_RST   -1                   
#define TFT_DC     D3
//Option 1: faster
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS,  TFT_DC, TFT_RST);
// Option 2: use any pins but a little slower!
#define TFT_SCLK D5   // set these to be whatever pins you like!
#define TFT_MOSI D7   // set these to be whatever pins you like!
//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);


#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <JsonListener.h>
#include <time.h>
#include "OpenWeatherMapCurrent.h"

OpenWeatherMapCurrent client;

String OPEN_WEATHER_MAP_APP_ID = "xx";
String OPEN_WEATHER_MAP_LOCATION_ID = "769250";
String OPEN_WEATHER_MAP_LANGUAGE = "pl";
boolean IS_METRIC = true;//true-*C flase-farenheit
const char* ESP_HOST_NAME = "esp-weather_station" + ESP.getFlashChipId();
const char* WIFI_SSID     = "xx";
const char* WIFI_PASSWORD = "xx";
WiFiClient wifiClient;




void setup() {
  Serial.begin(115200);
  delay(1000);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
  rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  tft.initR(INITR_BLACKTAB);
  tft.fillScreen(ST7735_BLACK);
  tft.setTextWrap(false);
  sensors.begin();
  wifiinit();
  delay(5000);
  tft.fillScreen(ST7735_BLACK);
  stext();
  
}

void loop() {
  //tft.fillScreen(ST7735_BLACK);
  
  weather();
  rtcget();
  tempget();
  
 
  

 

if(WiFi.status() == WL_CONNECTED){
 tft.setCursor(26, 143);
 tft.setTextColor(ST7735_GREEN, ST7735_BLACK);
 tft.setTextSize(1);
 tft.println("ON ");
}else{
 Serial.print("ERR.. check your internet connection");
 tft.setCursor(26, 143);
 tft.setTextColor(ST7735_RED, ST7735_BLACK);
 tft.setTextSize(1);
 tft.println("OFF");
}

 
  
 
}
/////////////////////////////////////////////////////////////////////////////////voidy////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void wifiinit() {
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("Connecting to ");
  Serial.println(WIFI_SSID);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  
  Serial.println("");
  Serial.println("WiFi connected!");
  Serial.println(WiFi.localIP());
  Serial.println();

  tft.drawRect(0, 0, 127, 160, ST7735_GREEN);// Draw rectangle (x,y,width,height,color)
  delay(500);
  tft.setCursor(20, 10);  // Set position (x,y)
  tft.setTextColor(ST7735_GREEN);  // Set color of text. First is the color of text and after is color of background
  tft.setTextSize(2);  // Set text size. Goes from 0 (the smallest) to 20 (very big)
  tft.println("Welcome");
  tft.setCursor(20, 30);
  tft.setTextSize(1);
  tft.println("connected to:");
  tft.setCursor(20,40);
  tft.println(WIFI_SSID);
  tft.setCursor(20, 55);
  tft.print("IP address:");
  tft.setCursor(20,65);
  tft.print(WiFi.localIP());

}


  

void rtcget(){
    DateTime now = rtc.now();
    delay(1000);
    tft.setCursor(38, 20); 
    tft.setTextColor(ST7735_WHITE, ST7735_BLACK);  
    tft.setTextSize(2);  
    tft.println(now.hour(), DEC);
    
    tft.setCursor(59, 20); 
    tft.setTextColor(ST7735_WHITE);  
    tft.setTextSize(2);  
    tft.print(":");
    
    tft.setCursor(68, 20); 
    tft.setTextColor(ST7735_WHITE, ST7735_BLACK);  
    tft.setTextSize(2);  
    tft.println(now.minute(), DEC);
    //tft.setCursor(95, 26); 
    //tft.setTextColor(ST7735_WHITE, ST7735_BLACK);  
    //tft.setTextSize(1);  
    //tft.print(now.second(), DEC);
    

    tft.setCursor(38, 40); 
    tft.setTextColor(ST7735_WHITE, ST7735_BLACK);  
    tft.setTextSize(1);  
    tft.println(now.day());
    tft.setCursor(50, 40); 
    tft.setTextColor(ST7735_WHITE);  
    tft.setTextSize(1);  
    tft.println(".");
    tft.setCursor(56, 40); 
    tft.setTextColor(ST7735_WHITE, ST7735_BLACK);  
    tft.setTextSize(1);  
    tft.println(now.month());
    tft.setCursor(60, 40); 
    tft.setTextColor(ST7735_WHITE);  
    tft.setTextSize(1);  
    tft.println(".");
    tft.setCursor(66, 40); 
    tft.setTextColor(ST7735_WHITE, ST7735_BLACK);  
    tft.setTextSize(1);  
    tft.println(now.year());
    tft.setCursor(45, 49); 
    tft.setTextColor(ST7735_WHITE, ST7735_BLACK);  
    tft.setTextSize(1);  
    tft.println(daysOfTheWeek[now.dayOfTheWeek()]);
    
    /*
    Serial.println("Current Date & Time: ");
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
    */
    
}
void stext(){
  tft.drawRect(0, 0, 128, 160, ST7735_GREEN); //Draw rectangle (x,y,width,height,color)
  tft.drawLine(0, 135, 159, 135, ST7735_GREEN);  // Draw line (x0,y0,x1,y1,color)
  tft.drawLine(44, 135, 44, 160, ST7735_GREEN);
  tft.drawLine(0, 60, 128, 60, ST7735_GREEN);
  tft.drawLine(0, 95, 128, 95, ST7735_GREEN);

  
  tft.setCursor(47, 140); 
  tft.setTextColor(ST7735_WHITE);  
  tft.setTextSize(2);  
  tft.print("T");
  
  tft.setCursor(56, 5); 
  tft.setTextColor(ST7735_WHITE);  
  tft.setTextSize(1);  
  tft.print("RTC");
  
  tft.setCursor(4, 143); 
  tft.setTextColor(ST7735_WHITE);  
  tft.setTextSize(1);  
  tft.print("0))");
  

  
  tft.setCursor(4, 74);
  tft.setTextColor(ST7735_GREEN);
  tft.setTextSize(1);
  tft.print("T:");
  
  tft.setCursor(4,84);
  tft.setTextColor(ST7735_GREEN);
  tft.setTextSize(1);
  tft.print("H:");

   tft.setCursor(50, 74);
  tft.setTextColor(ST7735_GREEN);
  tft.setTextSize(1);
  tft.print("C");
  
  tft.setCursor(35,84);
  tft.setTextColor(ST7735_GREEN);
  tft.setTextSize(1);
  tft.print("%");
  
  tft.setCursor(65,74);
  tft.setTextColor(ST7735_GREEN);
  tft.setTextSize(1);
  tft.print("P:");

  tft.setCursor(65,84);
  tft.setTextColor(ST7735_GREEN);
  tft.setTextSize(1);
  tft.print("S:");

  tft.setCursor(110,74);
  tft.setTextColor(ST7735_GREEN);
  tft.setTextSize(1);
  tft.println("hPa");

  tft.setCursor(105,84);
  tft.setTextColor(ST7735_GREEN);
  tft.setTextSize(1);
  tft.print("km/s");

 
}
void tempget(){
  sensors.requestTemperatures();
 
  tft.setTextSize(2);
  tft.setCursor(66, 140);
  tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
  tft.print(sensors.getTempCByIndex(0)); 
  
}
void weather(){
  
  OpenWeatherMapCurrentData data;
    client.setLanguage(OPEN_WEATHER_MAP_LANGUAGE);
  client.setMetric(IS_METRIC)
  client.updateCurrentById(&data, OPEN_WEATHER_MAP_APP_ID, OPEN_WEATHER_MAP_LOCATION_ID);
  delay(1000);
  
  tft.setCursor(16, 84);
  tft.setTextColor(ST7735_GREEN, ST7735_BLACK);
  tft.setTextSize(1);
  tft.print(data.humidity);
  
  tft.setCursor(16, 74);
  tft.setTextColor(ST7735_GREEN, ST7735_BLACK);
  tft.setTextSize(1);
  tft.print(data.temp);
  
  tft.setCursor(80,84);
  tft.setTextColor(ST7735_GREEN,ST7735_BLACK);
  tft.setTextSize(1);
  tft.print(data.windSpeed);
  
  tft.setCursor(80,74);
  tft.setTextColor(ST7735_GREEN,ST7735_BLACK);
  tft.setTextSize(1);
  tft.println(data.pressure);
  
  delay(10000);

}

.Będę bardzo wdzięczny za pomoc 🙂. Gdy już będzie wszystko działało opublikuję projekt 🙂

Edytowano przez Maciokeks
Link do komentarza
Share on other sites

Bądź aktywny - zaloguj się lub utwórz konto!

Tylko zarejestrowani użytkownicy mogą komentować zawartość tej strony

Utwórz konto w ~20 sekund!

Zarejestruj nowe konto, to proste!

Zarejestruj się »

Zaloguj się

Posiadasz własne konto? Użyj go!

Zaloguj się »
×
×
  • Utwórz nowe...

Ważne informacje

Ta strona używa ciasteczek (cookies), dzięki którym może działać lepiej. Więcej na ten temat znajdziesz w Polityce Prywatności.