Wpis z mikrobloga

Mam takie pytanko do mirków od #esp32 #esp32 #arduino #programowanie spotkał się ktoś z was kiedyś z czymś takim jak EPOCH? stronka openweather.com zwraca mi wartości w tym formacie i chciałbym je przetłuymaczyć na język ludzki ale za bardzo nie umiem znaleść informacjii jak zrobić to w arduinoCC

tu mój kodzik, jest dużo śmiecia, ale składam projekt z kilku gotowych skryptów bo jestem noobem, wartości to sunset i sunshine, będę wdzięczby za sugestie.


#include
#include
#include

#include
#include
#include
#include
#include
#include

const char* ssid = "pamparam";
const char* password = "cykcykcyk";
String CityID = "3143244"; // Oslo, Nowray
String APIKEY = "dabudibudabudaj";
char servername[] = "api.openweathermap.org";
String result;

int counter = 60;

String Sunrise;
String Sunset;

int redPin = 13;
int greenPin = 12;
int bluePin = 14;

int valueR;
int valueG;
int valueB;

int SENSOR = 15;
float temp, humedad;

DHT dht (SENSOR, DHT11);
WiFiClient client;

void setup() {
Serial.begin(115200);
Serial.println("Connecting");
WiFi.begin(ssid, password);

while (WiFi.status() != WLCONNECTED) {
delay(500);
}
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}


void setColor(int red, int green, int blue)
{

digitalWrite(redPin, red);
digitalWrite(greenPin, green);
digitalWrite(bluePin, blue);
}

void loop()
{
humedad = dht.readHumidity();
temp = dht.readTemperature();


Serial.print("Temperatura: ");
Serial.print(temp);
Serial.print("℃ Wilgotność: ");
Serial.print(humedad);
Serial.println("%");
Serial.print("Sunrise: ");
Serial.print(Sunrise);
Serial.print("Sunset: ");
Serial.print(Sunset);


if(counter == 60) //Get new data every 10 minutes
{
counter = 0;
delay(1000);
getWeatherData();
}else
{
counter++;

}


checkTemp();
delay(500);
}

void getWeatherData() //client function to send/receive GET request data.
{
if (client.connect(servername, 80)) { //starts client connection, checks for connection
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();
}
else {
Serial.println("connection failed"); //error message if no client connect
Serial.println();
}

while(client.connected() && !client.available()) delay(1); //waits for data
while (client.connected() || client.available()) { //connected or data available
char c = client.read(); //gets byte from ethernet buffer
result = result+c;
}

client.stop(); //stop client
result.replace('[', ' ');
result.replace(']', ' ');
Serial.println(result);

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);
if (!root.success())
{
Serial.println("parseObject() failed");
}

String sunrise = root["sys"]["sunrise"];
String sunset = root["sys"]["sunset"];

Sunrise = sunrise;
Sunset = sunset;
  • 9
@Kotel_: Dzięki, > > "bo jestem noobem" < < poczytałem o tym znalazłem kilka skryptów opisujące zjawisko, tylko nie wiem jak to zastosować: Obecnie wgryzam się w to https://www.eevblog.com/forum/microcontrollers/arduino-converting-epoch-to-year-month-day-weekday/ ale nie umiem znaleść epocha ( trzeci komentarz to interesuący fragment kodu ) może to jest to - 2208988800UL ? ja dostaje wartości bez liter na końcu, ale jeśli rekomendujecie to rozwiązanie to spróbuje
@Borsuk69: to w ogóle działa? bo jsonArray wygląda jak VLA, a root jest referencją, co wskazuje, że to jest C++. VLA nie są częścią C++ i zwykle nie kompilują się nawet. co więcej, dalej jest sizeof od VLA, a to jest undefined behavior w C.
@MamCieNaHita: > > " jestem noobem" < < ale działa jakimś cudem, warości są zwracane na ten przykład otrzymuje 1519884894 na dziś dzień, co internetowy konwerter tłumaczy na czwartek, 1 marca 2018 07:14:54 GMT+01:00 i to się zgadza. Chce zrobić termometr, który będzie mi pokazywał wschód i zachód słońca na wyświetlaczu. Być może część kodu jest bezużyteczna i będę go czyścił, gdy osiągnę zamierzone cele, "czas pokaże co ważne a co