Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. #include <ArduinoJson.h>
  2. #include <Wire.h>
  3. #include <SPI.h>
  4. #include <NTPClient.h>
  5. #include <WiFi101.h>
  6. #include <WiFiUdp.h>
  7. #include "Adafruit_LEDBackpack.h"
  8. #include "Adafruit_GFX.h"
  9.  
  10. char *ssid = "DIGI-01094341";
  11. const char *password = "***";
  12.  
  13. String apiKey = "***key***";
  14. String location = "budapest,HU";
  15. int status = WL_IDLE_STATUS;
  16. char server[] = "api.openweathermap.org";
  17. WiFiClient client;
  18.  
  19. String nextWeather[] = {" ", " ", " "};
  20.  
  21.  
  22. WiFiUDP ntpUDP;
  23. NTPClient timeClient(ntpUDP);
  24.  
  25. int fenyero = 5;
  26.  
  27. Adafruit_7segment kijelzo = Adafruit_7segment();
  28.  
  29. void setup()
  30. {
  31. kijelzo.begin(0x70);
  32. kijelzo.setBrightness(fenyero);
  33. Serial.begin(115200);
  34. Serial.print("Connecting to: ");
  35. Serial.println(ssid);
  36. WiFi.begin(ssid, password);
  37.  
  38. while (WiFi.status() != WL_CONNECTED) {
  39. delay(500);
  40. Serial.print("Varakozas a kapcsolodasra...");
  41. }
  42. timeClient.begin();
  43. timeClient.setTimeOffset(7200); //GMT+1 (7200) vagy +0, mert mar a faszom se tudja mibe van MO.
  44. }
  45.  
  46.  
  47. void loop()
  48. {
  49. oraDolgai();
  50. //idojarasDolgai();
  51. //kijelzo.writeDigitRaw(3, 0x63); //celsiushoz fog kelleni
  52. }
  53.  
  54.  
  55. void oraDolgai()
  56. {
  57. timeClient.update();
  58. String masodperc = ((timeClient.getFormattedTime().substring(6)));
  59. String perc = ((timeClient.getFormattedTime().substring(3)));
  60. String ora = ((timeClient.getFormattedTime().substring(0)));
  61. int masodpercc = masodperc.toInt();
  62. int oraa = ora.toInt();
  63. int percc = perc.toInt();
  64.  
  65. unsigned int oraaa = oraa;
  66. unsigned int perccc = percc;
  67. unsigned int masodperccc = masodpercc;
  68.  
  69. unsigned int ideiglenes = perccc;
  70. do
  71. {
  72. ideiglenes /= 10;
  73. oraaa *= 10;
  74. } while (ideiglenes > 0);
  75.  
  76. if (perccc < 10)
  77. {
  78. unsigned int kisebb = oraaa * 10;
  79. unsigned int pontosido = kisebb + perccc;
  80. kijelzo.print(pontosido);
  81. }
  82. else
  83. {
  84. unsigned int pontosido2 = oraaa + perccc;
  85. kijelzo.print(pontosido2);
  86. }
  87.  
  88. if (masodpercc % 2){
  89. kijelzo.drawColon(false);
  90. }
  91. else
  92. {
  93. kijelzo.drawColon(true);
  94. }
  95. kijelzo.writeDisplay();
  96. }
  97.  
  98. void idojarasDolgai()
  99. {
  100. Serial.println("\nStarting connection to server...");
  101. if (client.connect(server, 80))
  102. {
  103. Serial.println("connected to server");
  104. // Make a HTTP request:
  105. client.print("GET /data/2.5/forecast?");
  106. client.print("q=" + location);
  107. client.print("&appid=" + apiKey);
  108. client.print("&cnt=3");
  109. client.println("&units=metric");
  110. client.println("Host: api.openweathermap.org");
  111. client.println("Connection: close");
  112. client.println();
  113. }
  114. else
  115. {
  116. Serial.println("unable to connect");
  117. }
  118.  
  119. //json adatbazis
  120. //http://api.openweathermap.org/data/2.5/forecast?q=budapest,HU&cnt=3&appid=***key***
  121.  
  122. //delay(1000);
  123. String line = "";
  124.  
  125. while (client.connected())
  126. {
  127. line = client.readStringUntil('\n');
  128.  
  129. //create a json buffer where to store the json data
  130. StaticJsonBuffer<5000> jsonBuffer;
  131. JsonObject& root = jsonBuffer.parseObject(line);
  132. if (!root.success())
  133. {
  134. Serial.println("parseObject() failed");
  135. return;
  136. }
  137.  
  138. //get the data from the json tree
  139. String nextWeather0 = root["list"][0]["main"]["temp"];
  140.  
  141. nextWeather[0] = nextWeather0;
  142.  
  143. int idojaras = nextWeather0.toInt();
  144.  
  145. Serial.println(idojaras);
  146. }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement