Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ArduinoJson.h>
- #include <Wire.h>
- #include <SPI.h>
- #include <NTPClient.h>
- #include <WiFi101.h>
- #include <WiFiUdp.h>
- #include "Adafruit_LEDBackpack.h"
- #include "Adafruit_GFX.h"
- char *ssid = "DIGI-01094341";
- const char *password = "***";
- String apiKey = "***key***";
- String location = "budapest,HU";
- int status = WL_IDLE_STATUS;
- char server[] = "api.openweathermap.org";
- WiFiClient client;
- String nextWeather[] = {" ", " ", " "};
- WiFiUDP ntpUDP;
- NTPClient timeClient(ntpUDP);
- int fenyero = 5;
- Adafruit_7segment kijelzo = Adafruit_7segment();
- void setup()
- {
- kijelzo.begin(0x70);
- kijelzo.setBrightness(fenyero);
- Serial.begin(115200);
- Serial.print("Connecting to: ");
- Serial.println(ssid);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print("Varakozas a kapcsolodasra...");
- }
- timeClient.begin();
- timeClient.setTimeOffset(7200); //GMT+1 (7200) vagy +0, mert mar a faszom se tudja mibe van MO.
- }
- void loop()
- {
- oraDolgai();
- //idojarasDolgai();
- //kijelzo.writeDigitRaw(3, 0x63); //celsiushoz fog kelleni
- }
- void oraDolgai()
- {
- timeClient.update();
- String masodperc = ((timeClient.getFormattedTime().substring(6)));
- String perc = ((timeClient.getFormattedTime().substring(3)));
- String ora = ((timeClient.getFormattedTime().substring(0)));
- int masodpercc = masodperc.toInt();
- int oraa = ora.toInt();
- int percc = perc.toInt();
- unsigned int oraaa = oraa;
- unsigned int perccc = percc;
- unsigned int masodperccc = masodpercc;
- unsigned int ideiglenes = perccc;
- do
- {
- ideiglenes /= 10;
- oraaa *= 10;
- } while (ideiglenes > 0);
- if (perccc < 10)
- {
- unsigned int kisebb = oraaa * 10;
- unsigned int pontosido = kisebb + perccc;
- kijelzo.print(pontosido);
- }
- else
- {
- unsigned int pontosido2 = oraaa + perccc;
- kijelzo.print(pontosido2);
- }
- if (masodpercc % 2){
- kijelzo.drawColon(false);
- }
- else
- {
- kijelzo.drawColon(true);
- }
- kijelzo.writeDisplay();
- }
- void idojarasDolgai()
- {
- Serial.println("\nStarting connection to server...");
- if (client.connect(server, 80))
- {
- Serial.println("connected to server");
- // Make a HTTP request:
- client.print("GET /data/2.5/forecast?");
- client.print("q=" + location);
- client.print("&appid=" + apiKey);
- client.print("&cnt=3");
- client.println("&units=metric");
- client.println("Host: api.openweathermap.org");
- client.println("Connection: close");
- client.println();
- }
- else
- {
- Serial.println("unable to connect");
- }
- //json adatbazis
- //http://api.openweathermap.org/data/2.5/forecast?q=budapest,HU&cnt=3&appid=***key***
- //delay(1000);
- String line = "";
- while (client.connected())
- {
- line = client.readStringUntil('\n');
- //create a json buffer where to store the json data
- StaticJsonBuffer<5000> jsonBuffer;
- JsonObject& root = jsonBuffer.parseObject(line);
- if (!root.success())
- {
- Serial.println("parseObject() failed");
- return;
- }
- //get the data from the json tree
- String nextWeather0 = root["list"][0]["main"]["temp"];
- nextWeather[0] = nextWeather0;
- int idojaras = nextWeather0.toInt();
- Serial.println(idojaras);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement