-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimpressora-termica.ino
executable file
·65 lines (52 loc) · 1.4 KB
/
impressora-termica.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
#include "imp_common.h"
#include "imp_wifi.h"
#include "spiffs_utils.h"
#define WDT_TIMEOUT 6000
void setup(void) {
Serial.begin(115200);
Serial.println();
Serial.println("Booting Sketch...");
spiffsSetup();
commonSetup();
setupWifi();
}
bool bounce = false;
HTTPClient http;
void loop(void) {
handleWifi();
// apenas OTA
if(wifi_ap_mode) return;
if(digitalRead(BUTTON) == LOW && !bounce) {
bounce = true;
//print from endpoint
http.begin(loadDefault("/endpoint"));
int httpCode = http.GET();
//impSerial.printf("[HTTP] GET... code: %d\n", httpCode);
if(httpCode == HTTP_CODE_OK) {
// get length of document (is -1 when Server sends no Content-Length header)
int len = http.getSize();
// create buffer for read
uint8_t buff;
// get tcp stream
WiFiClient * stream = http.getStreamPtr();
// read all data from server
while(http.connected()) {
while(stream->available()) {
// read a byte
int c = stream->readBytes(&buff, 1);
// write it to printer
wdt_disable();
impPrinter.writeBytes(buff);
wdt_enable(WDT_TIMEOUT);
}
}
} else {
// http fail
impSerial.print("falha HTTP: ");
impSerial.println(http.errorToString(httpCode));
}
http.end();
}
if(digitalRead(BUTTON) == HIGH && bounce)
bounce = false;
}