-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiss.ino
307 lines (251 loc) · 8.78 KB
/
iss.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/*
* ESP8266 JSON Decode of server response
* -Manoj R. Thkuar
* https://circuits4you.com
*/
#include <time.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266HTTPClient.h>
#include <ArduinoJson.h>
#include <Adafruit_GFX.h> // Core graphics library
//#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
#define FS_NO_GLOBALS
#include <FS.h>
// Call up the TFT library
#include <TFT_eSPI.h> // Hardware-specific library for ESP8266
// Invoke TFT library
TFT_eSPI tft = TFT_eSPI();
float p = 3.1415926;
// Variables de travail
unsigned long epoch = 0;
int nujour = 0; //numero jour de la semaine avec 0 pour dimanche
String jour = "mon jour"; // dimanche, lundi, etc.
String heure = "mon heure ..";
char buffer[80]; // Stockage de la date complete
// ST7789 TFT module connections
#define TFT_RST 15 // TFT RST pin is connected to NodeMCU pin D8 (GPIO15)
#define TFT_DC 2 // TFT DC pin is connected to NodeMCU pin D4 (GPIO2)
#define TFT_CS -1 // TFT CS pin is directly connected to GND
// initialize ST7789 TFT library with hardware SPI module
// SCK (CLK) ---> NodeMCU pin D5 (GPIO14)
// MOSI(DIN) ---> NodeMCU pin D7 (GPIO13)
//Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
//Creation objet WIFI UDP puis du client NTP
WiFiUDP ntpUDP;
//Creation objet client NTP avec les parametres suivants :
// - pool de serveurs NTP
// - en option le décalage horaire en secondes, ici 3600 pour GMT+1, pour GMT+8 mettre 28800, etc.
// - en option l intervalle de mise à jour en millisecondes par défaut à 60 secondes
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000);
void setup(void) {
//tft.init(240, 240, SPI_MODE2);
uint16_t time = millis();
time = millis() - time;
tft.begin();
// Demarrage client NTP
timeClient.begin();
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
// it is a good practice to make sure your code sets wifi mode how you want it.
// put your setup code here, to run once:
Serial.begin(115200);
//WiFiManager, Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wm;
// reset settings - wipe stored credentials for testing
// these are stored by the esp library
//wm.resetSettings();
// Automatically connect using saved credentials,
// if connection fails, it starts an access point with the specified name ( "AutoConnectAP"),
// if empty will auto generate SSID, if password is blank it will be anonymous AP (wm.autoConnect())
// then goes into a blocking loop awaiting configuration and will return success result
bool res;
// res = wm.autoConnect(); // auto generated AP name from chipid
res = wm.autoConnect("SPACE CONNECTION"); // anonymous ap
//res = wm.autoConnect("AutoConnectAP","password"); // password protected ap
if(!res) {
tft.fillScreen(TFT_BLACK);
delay(1000);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_WHITE, TFT_BLACK); // set text color to white and black background
tft.setTextSize(3);
tft.setCursor(0,80);
tft.println("wifi:");
tft.setCursor(0,140);
tft.setTextSize(2);
tft.setTextColor(TFT_MAGENTA);
tft.println("SPACE CONNECTION");
}
else {
//if you get here you have connected to the WiFi
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_YELLOW, TFT_BLACK); // set text color to white and black background
tft.setTextSize(3);
tft.setCursor(0,100);
tft.print("Connecté");
delay(1000);
}
}
void loop() {
// Recup heure puis affichage
timeClient.update();
epoch = timeClient.getEpochTime(); // Heure Unix
nujour = timeClient.getDay(); // jour de la semaine
heure = timeClient.getFormattedTime(); // heure
// Calcul de la date en convertissant le temps UNIX epoch
time_t timestamp = epoch;
struct tm * pTime = localtime( & timestamp );
strftime( buffer,80, "%d/%m/%Y", pTime );
//Serial.println(buffer);
switch (nujour) { // on determine le jour
case 0:
jour = "dimanche";
break;
case 1:
jour = "lundi";
break;
case 2:
jour = "mardi";
break;
case 3:
jour = "mercredi";
break;
case 4:
jour = "jeudi";
break;
case 5:
jour = "vendredi";
break;
case 6:
jour = "samedi";
break;
}
tft.fillScreen(TFT_BLACK);
tft.setCursor(20, 0);
tft.setTextColor(TFT_WHITE);
tft.setTextSize(4);
tft.print(jour);
tft.setCursor(20, 50);
tft.setTextColor(TFT_CYAN);
tft.setTextSize(3);
tft.print(buffer);
tft.setTextSize(4);
tft.setCursor(0, 100);
tft.setTextColor(TFT_MAGENTA);
tft.print("----------");
tft.setCursor(0, 160);
tft.setTextColor(TFT_GREEN);
tft.setTextSize(5);
tft.print(heure);
delay(4000); // tempo de 4 sec
tft.fillScreen(TFT_BLACK);
HTTPClient http; //Declare object of class HTTPClient
http.begin("http://api.open-notify.org/astros.json"); //Specify request destination
int httpCode = http.GET(); //Send the request
String payload = http.getString(); //Get the response payload from server
if(httpCode == 200)
{
// Allocate JsonBuffer
// Use arduinojson.org/assistant to compute the capacity.
//const size_t capacity = JSON_OBJECT_SIZE(3) + JSON_ARRAY_SIZE(2) + 1024;
// Stream& input;
StaticJsonDocument<1024> doc;
DeserializationError error = deserializeJson(doc, payload);
if (error) {
tft.print(F("deserializeJson() failed: "));
tft.println(error.f_str());
return;
}
int number = doc["number"]; // 10
tft.fillScreen(TFT_BLACK);
tft.setTextWrap(true);
tft.setTextSize(3);
tft.setTextColor(TFT_WHITE);
tft.setCursor(0,0);
tft.print("-ASTRONAUTES-");
tft.setCursor(0,35);
tft.print("dans l'espace");
tft.setTextColor(TFT_GREEN);
tft.setTextSize(7);
tft.setCursor(80,80);
tft.print(number);
tft.drawRect (1,155,85,240,TFT_BLACK);
//tft.println(payload); //Print request response payload
//delay(6000);
for (JsonObject people_item : doc["people"].as<JsonArray>()) {
const char* people_item_craft = people_item["craft"]; // "Shenzhou 13", "Shenzhou 13", "Shenzhou 13", ...
const char* people_item_name = people_item["name"]; // "Zhai Zhigang", "Wang Yaping", "Ye Guangfu", ...
for ( int j = 0; j < number; ++j ) // output each array element's value {
tft.setTextWrap(true);
tft.setTextColor(TFT_WHITE);
tft.setTextSize(3);
tft.setCursor(0,160);
tft.print (people_item_name) ;
tft.setTextColor(TFT_YELLOW);
tft.setTextSize(2);
tft.setCursor(0,210);
tft.print (people_item_craft);
delay(2500);
tft.fillRect (1, 155, 240, 85, TFT_BLACK);
}
}
http.end(); //Close connection
http.begin("http://api.open-notify.org/iss-now.json"); //Specify request destination
int httpCodeb = http.GET(); //Send the request
String payloadb = http.getString(); //Get the response payload from server
if(httpCodeb == 200)
{
// Allocate JsonBuffer
// Use arduinojson.org/assistant to compute the capacity.
const size_t capacity = JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3)+ 192;
// Stream& input;
// Stream& input;
StaticJsonDocument<192> docb;
DeserializationError error = deserializeJson(docb, payloadb);
if (error) {
tft.print(F("deserializeJson() failed: "));
tft.println(error.f_str());
return;
}
long timestamp = docb["timestamp"]; // 1649869660
const char* messageb = docb["message"]; // "success"
const char* iss_position_longitude = docb["iss_position"]["longitude"]; // "-121.8565"
const char* iss_position_latitude = docb["iss_position"]["latitude"]; // "39.6452"
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_MAGENTA); // set text color to white and black background
tft.setTextSize(3);
tft.setCursor(0,0);
tft.setTextWrap(true);
tft.print("ISS POSITION:");
tft.setTextColor(TFT_WHITE);
tft.setTextSize(3);
tft.print("-------------");
tft.setTextColor(TFT_GREEN);
tft.setTextSize(4);
tft.setCursor(0,60);
tft.print("Longitude:");
tft.setTextSize(3);
tft.setCursor(30,110);
tft.setTextColor(TFT_WHITE);
tft.print(iss_position_longitude);
tft.setTextSize(4);
tft.setCursor(0,160);
tft.setTextColor(TFT_GREEN);
tft.print("Latitude:");
tft.setTextSize(3);
tft.setCursor(30,210);
tft.setTextColor(TFT_WHITE);
tft.print(iss_position_latitude);
delay(4000);
tft.fillScreen(TFT_BLACK);
}
else
{
tft.println("Error in response ISS");
delay(1500);
}
http.end(); //Close connection
}