-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
64 lines (54 loc) · 1.32 KB
/
main.cpp
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
#include <Arduino.h>
#include <WiFi.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
WiFiUDP ntpUDP;
IPAddress printer(10,42,8,10);
IPAddress myip(10,42,8,9);
IPAddress mymask(255,255,0,0);
IPAddress gw(10,42,42,1);
IPAddress ntp(10,42,42,1);
IPAddress dns(10,42,42,1);
NTPClient ntpclient(ntpUDP, ntp);
void setup() {
Serial.begin(115200);
Serial.println("Hallo wereld!");
WiFi.config(myip, dns, gw, mymask);
WiFi.begin("revspace-pub", "");
setenv("TZ","CET-1CEST,M3.5.0/2,M10.5.0/3",1);
tzset();
}
void loop() {
while (WiFi.status() != WL_CONNECTED ) {
Serial.println("Connecting to WiFi...");
delay(10);
}
ntpclient.update();
unsigned long time = ntpclient.getEpochTime();
struct tm *ptm = localtime((time_t *) &time);
char date[11];
snprintf(date, sizeof(date), "%04d-%02d-%02d",
ptm->tm_year + 1900,
ptm->tm_mon + 1,
ptm->tm_mday
);
Serial.println("Connecting to printer...");
WiFiClient client;
if (client.connect(printer, 9100)) {
client.print("\eia"); client.write('\0');
client.print(
"\e@"
"\ea\x01"
"\ek\x0b"
);
client.print("\eX0\x43"); client.write('\0');
client.print("gratis meuk\n");
client.print("\eX0\x64"); client.write('\0');
client.print(date);
client.print("\f");
client.stop();
Serial.println("Date sent to printer.");
}
Serial.println("Halting.");
for(;;);
}