-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathePaper_BusTag.ino
More file actions
130 lines (119 loc) · 3.1 KB
/
ePaper_BusTag.ino
File metadata and controls
130 lines (119 loc) · 3.1 KB
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
#include <ArduinoJson.h>
#include <GxEPD.h>
#include <GxGDEH029A1/GxGDEH029A1.h> // 2.9" b/w
#include <Fonts/FreeSans9pt7b.h>
#define DEFAULT_FONT FreeSans9pt7b
#include <Fonts/FreeSansBold9pt7b.h>
#define BOLD_FONT FreeSansBold9pt7b
#include <GxIO/GxIO_SPI/GxIO_SPI.h>
#include <GxIO/GxIO.h>
#define ELINK_BUSY 4
#define ELINK_RESET 12
#define ELINK_DC 19
#define ELINK_SS 5
#define SPI_MOSI 23
#define SPI_MISO 2
#define SPI_CLK 18
#define SDCARD_SS 13
#define BUTTON_1 38
#define BUTTON_2 37
#define BUTTON_3 39
GxIO_Class io(SPI, ELINK_SS, ELINK_DC, ELINK_RESET);
GxEPD_Class display(io, ELINK_RESET, ELINK_BUSY);
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "";
const char* password = "";
HTTPClient client;
struct busTable{
String line;
String hour;
bool realtime;
};
void setup()
{
WiFi.begin(ssid, password);
int i = 0;
while (WiFi.status() != WL_CONNECTED && i < 5) {
delay(1000);
i++;
}
SPI.begin(SPI_CLK, SPI_MISO, SPI_MOSI, -1);
display.init();
display.setRotation(3);
display.eraseDisplay();
display.setTextColor(GxEPD_BLACK);
if(i >= 5){
display.setFont(&BOLD_FONT);
display.setCursor(52,67);
display.print("No Wi-Fi Connection!");
PowerOff();
}
busTable stop_1841[9];
busTable stop_1842[9];
busTable stop_2622[9];
requestTo("1841",stop_1841);
requestTo("1842",stop_1842);
requestTo("2622",stop_2622);
display.fillScreen(GxEPD_WHITE);
printBusLine("62","SOFIA",16,stop_1841);
printBusLine("62","CAIO MARIO",38,stop_1842);
printBusLine("32","TASSONI",60,stop_2622);
printBusLine("59","SOLFERINO",82,stop_2622);
printBusLine("VE1","MASSAUA",104,stop_1842);
printBusLine("VE1","VENARIA",126,stop_1841);
PowerOff();
}
void loop(){}
void PowerOff(){
display.update();
display.powerDown();
esp_sleep_enable_timer_wakeup(6e8);
delay(10);
esp_deep_sleep_start();
}
void printBusLine(String line, String endstop, int pos, busTable* table){
display.setFont(&BOLD_FONT);
display.setCursor(2,pos);
display.print(endstop);
display.setCursor(150,pos);
int bus_n = 0;
for(int i = 0; i < 9; i++){
if(table[i].line == line){
bus_n ++;
if(table[i].realtime){
display.setFont(&BOLD_FONT);
}else{
display.setFont(&DEFAULT_FONT);
}
if(bus_n < 4) display.print(table[i].hour+" ");
}
}
if(bus_n ==0){
display.setFont(&DEFAULT_FONT);
display.print("NO SERVIZIO");
}
}
void requestTo(String stopN, busTable *table){
client.begin("https://gpa.madbob.org/query.php?stop="+stopN);
if(client.GET()>0){
String payload = client.getString();
DynamicJsonDocument doc(1500);
deserializeJson(doc, payload);
uint8_t arraySize = doc.size();
for(uint8_t i = 0; i<arraySize; i++){
String line = doc[i]["line"];
String hour = doc[i]["hour"];
bool realtime = doc[i]["realtime"]=="true"?1:0;
table[i].line = line;
table[i].hour = hour;
table[i].realtime = realtime;
/*Serial.print(line);
Serial.print("\t|\t");
Serial.print(hour);
Serial.print("\t|\t");
Serial.println(realtime);*/
}
}
client.end();
}