Skip to content

Commit 03c48bd

Browse files
committed
Various tweaks for spot heater; version now as deployed in test unit; ready to be mounted. Assumes pin 25/26 to be corrected on the PCB during final install.
1 parent 0a15b59 commit 03c48bd

File tree

6 files changed

+113
-25
lines changed

6 files changed

+113
-25
lines changed

TelnetSerialStream.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void TelnetSerialStream::stop() {
3535
for (int i = 0; i < MAX_SERIAL_TELNET_CLIENTS; i++) {
3636
if (_serverClients[i]) {
3737
_serverClients[i].println("Connection closed from remote end");
38+
_serverClients[i].flush(); // appears to just flush the input buffer ???
3839
_serverClients[i].stop();
3940
}
4041
}

enclosure.scad

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@ QUAD7_H_ASSYM=1;
1717

1818
showdev=0;
1919
studs=0;
20-
version="v1.04";
20+
version="v1.05";
21+
22+
// Two sizes possible -- outside dimensions
23+
//
24+
box_h= 98; box_w = 68; // 98 x 68 x 48mm
25+
// box_h=115; box_w = 90; // 115 x 90 x 55mm
26+
27+
box_t=2; // thickness walls
28+
box_space=1.5; // space between the walls; as they are not that straight.
29+
30+
2131
/*
2232
v1.01 white print 15/10/2021 for box with transparant cover.
2333
v1.02 scanner 1mm lower, whole plate 2mm lower, rfid pillars narrower
@@ -28,6 +38,7 @@ version="v1.04";
2838
v1.04 Lowered main board by 2mm to prevent shorting 7x4 display
2939
pins (Issue #2). Removed unused mid studs. Wider tiewrap
3040
holes for stud (Issue #3).
41+
v1.05 flag for the 'larger' boxes; not yet correct.
3142
*/
3243
module quad_holes(r=QUAD7_HD/2,h=10,top=1) {
3344
r2=r; r1=r*top;
@@ -132,8 +143,8 @@ translate([-WR_W/2,-WR_H/2,-WR_T]) {
132143
};
133144

134145

135-
MB_W=61;
136-
MB_H=91;
146+
MB_W=box_w-box_t*2-box_space*2;
147+
MB_H=box_h-box_t*2-box_space*2;
137148
MB_T=2;
138149
MB_P=45;
139150
MB_V=80;
@@ -154,6 +165,7 @@ module mb_pins(r=MB_HH/2,h=MB_T+0.01) {
154165
};
155166
};
156167

168+
// Mounting board
157169
module mb(h=10) {
158170
difference() {
159171
union() {
@@ -187,6 +199,7 @@ module mb(h=10) {
187199
linear_extrude(height = 0.5)
188200
text("2021-10-15 / paymentnode",halign="center", valign="center",
189201
size=2.5, font="Gill Sans:style=Bold");
202+
190203
if (studs == 0) {
191204
translate([-70,0,0]) {
192205
difference() {

log.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ static double coreTemp() {
6868
}
6969
#endif
7070

71+
void log_stop() {
72+
Log.stop();
73+
Debug.stop();
74+
}
75+
7176
void log_loop() {
7277
static unsigned long last_report = millis();
7378
static unsigned long cntr;

log.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,5 @@ extern TLog Debug;
6060

6161
void setupLog();
6262
void log_loop();
63+
void log_stop();
6364
#endif

makerspaceleiden-payment-node-7seg.ino

Lines changed: 67 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
// MFRC522 (https://www.tinytronics.nl/shop/nl/communicatie-en-signalen/draadloos/rfid/rfid-kit-mfrc522-s50-mifare-met-kaart-en-key-tag)
1010
// 7 segment display ( https://www.hobbyelectronica.nl/product/4-digit-klok-display-module)
1111
//
12+
// Heater module
13+
// ESP32 Dev Module
14+
// MFRC522
15+
// 7 segment display
16+
// NPN transistor, 10k, 1k resistor
17+
// 25Ampere, 5volt relay
18+
//
1219
// Additional Librariries (via Sketch -> library manager):
1320
// MFRC522-spi-i2c-uart-async
1421
// TM1637TinyDisplay
@@ -45,11 +52,14 @@
4552
// two wires. See https://www.mcielectronics.cl/website_MCI/static/documents/Datasheet_TM1637.pdf
4653
// and https://create.arduino.cc/projecthub/ryanchan/tm1637-digit-display-arduino-quick-tutorial-ca8a93
4754
//
48-
#define DISPLAY_CLK 25
49-
#define DISPLAY_DIO 26
55+
#define DISPLAY_CLK (25)
56+
#define DISPLAY_DIO (26)
5057

5158
TM1637TinyDisplay display(DISPLAY_CLK, DISPLAY_DIO);
5259

60+
// For the heater
61+
#define RELAY (12)
62+
5363
// Very ugly global vars - used to communicate between the REST call and the rest.
5464
//
5565
char terminalName[64] = TERMINAL_NAME;
@@ -75,6 +85,21 @@ void setupDisplay() {
7585
Log.println("Display set to " VERSION);
7686
}
7787

88+
void setupRelay() {
89+
// relay is high-active; but there is a 10k
90+
// pulldown past the 1k driving resistor to
91+
// not let HiZ engage the relay.
92+
//
93+
digitalWrite(RELAY, 0);
94+
pinMode(RELAY, OUTPUT);
95+
digitalWrite(RELAY, 0);
96+
}
97+
98+
99+
void heatingOnOff(bool onOff) {
100+
digitalWrite(RELAY, onOff ? HIGH : LOW);
101+
}
102+
78103
void setup()
79104
{
80105
const char * p = (const char*) __FILE__;
@@ -91,6 +116,7 @@ void setup()
91116
Serial.print("\n\nBuild: " __DATE__ " " __TIME__ "\nUnit: ");
92117
Serial.println(terminalName);
93118

119+
setupRelay();
94120
setupDisplay();
95121
setupAuth(terminalName);
96122

@@ -151,10 +177,13 @@ void setup()
151177
Log.println("OTA started");
152178
})
153179
.onEnd([]() {
180+
Log.println("OTA completed");
154181
// prevent a cleversod uplading a special binary. ignore the hardware/serial angle
155182
Log.println("OTA completed OK - need to wipe keystore before rebooting into new code.");
156183
wipekeys();
157184
display.showString("Done");
185+
log_stop();
186+
heatingOnOff(false);
158187
})
159188
.onProgress([](unsigned int progress, unsigned int total) {
160189
static int l = -100;
@@ -168,15 +197,18 @@ void setup()
168197
})
169198
.onError([](ota_error_t error) {
170199
const char * label;
171-
if (error == OTA_AUTH_ERROR) label = (const char*) "Auth Failed";
172-
else if (error == OTA_BEGIN_ERROR) label = (const char*) "Begin Failed";
173-
else if (error == OTA_CONNECT_ERROR) label = (const char*) "Connect Failed";
174-
else if (error == OTA_RECEIVE_ERROR) label = (const char*) "Receive Failed";
175-
else if (error == OTA_END_ERROR) label = (const char*) "End Failed";
176-
else label = "Uknown error";
200+
if (error == OTA_AUTH_ERROR) label = (const char*) "FO:AF";
201+
else if (error == OTA_BEGIN_ERROR) label = (const char*) "FO:BF";
202+
else if (error == OTA_CONNECT_ERROR) label = (const char*) "FO:CF";
203+
else if (error == OTA_RECEIVE_ERROR) label = (const char*) "FO:RF";
204+
else if (error == OTA_END_ERROR) label = (const char*) "FO:EF";
205+
else label = "FO:OF";
177206
display.showString(label);
178-
Log.print("OTA error");
207+
Log.print("OTA error: E=");
208+
Log.print(error);
209+
Log.print(" - ");
179210
Log.println(label);
211+
delay(10 * 1000);
180212
});
181213

182214
Debug.println("Starting loop");
@@ -205,10 +237,10 @@ static void loop_RebootAtMidnight() {
205237
// "Thu Nov 4 09:47:43\n\0" -> 09:47\0
206238
p += 11;
207239
p[5] = 0;
208-
Debug.printf("strncmp(\"%s\",\"%s\",%d), %ld, %lu\n", p, AUTO_REBOOT_TIME, strlen(AUTO_REBOOT_TIME), now, millis());
209240

210-
if (strncmp(p, AUTO_REBOOT_TIME, strlen(AUTO_REBOOT_TIME)) == 0 && millis() > 3600 ) {
211-
Log.println("Nightly reboot - also to fetch new pricelist and fix any memory eaks.");
241+
if (strncmp(p, AUTO_REBOOT_TIME, strlen(AUTO_REBOOT_TIME)) == 0 && millis() > 3600 * 1000 ) {
242+
Log.println("Nightly reboot - also to fetch new pricelist and fix any memory leaks.");
243+
heatingOnOff(false);
212244
ESP.restart();
213245
}
214246
#endif
@@ -265,6 +297,16 @@ void loop()
265297
ArduinoOTA.handle();
266298
loop_RebootAtMidnight();
267299

300+
// flap relay every 5 seconds for testing.
301+
//
302+
if (0) {
303+
static unsigned long t = millis();
304+
if (millis() - t > 5000) {
305+
digitalWrite(RELAY, !digitalRead(RELAY));
306+
t = millis();
307+
}
308+
}
309+
268310
switch (md) {
269311
case WAITING_FOR_NTP:
270312
display.showString("ntp");
@@ -315,20 +357,23 @@ void loop()
315357
lst += 1000;
316358
}
317359

318-
// flash display 1.5 times a second in last minute.
319-
if (countdown < 60) {
320-
display.setBrightness(((millis() / 300) & 1) ? BRIGHT_HIGH : BRIGHT_HIGH / 2);
360+
// flash display 1.5 times towards the end
361+
if (countdown <= 60) {
362+
display.setBrightness(((millis() / 300) & 1) ? BRIGHT_HIGH : BRIGHT_1 );
321363
};
322364

323365
if (countdown <= 0) {
366+
heatingOnOff(false);
324367
countdown = 0;
325-
display.showString("00:00");
326368

327369
// flash aggressivily once time is up.
328370
//
329-
for (int i = 0; i < 20; i++) {
330-
display.setBrightness((i & 1) ? BRIGHT_HIGH : 0);
331-
delay(200);
371+
for (int i = 0; i < 30; i++) {
372+
display.setBrightness((i & 1) ? BRIGHT_HIGH : BRIGHT_LOW);
373+
display.showString("0000");
374+
delay(100);
375+
display.showString("----");
376+
delay(100);
332377
};
333378

334379
// go back to normal
@@ -340,8 +385,9 @@ void loop()
340385
countdown += checkcardswipe();
341386

342387
char timeleft[32];
343-
snprintf(timeleft, sizeof(timeleft) - 1, "%02d:%02d", countdown / 60, countdown % 60);
344-
display.showString(timeleft);
388+
snprintf(timeleft, sizeof(timeleft) - 1, "%02d%02d", countdown / 60, countdown % 60);
389+
display.showString(timeleft, 4, 0 /*pos*/, 0b01000000 /* dots */);
390+
heatingOnOff(true);
345391
break;
346392
}
347393
case WIFI_FAIL_REBOOT:

rest.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ bool registerDevice() {
251251

252252
if (md == WAIT_FOR_REGISTER_SWIPE) {
253253
updateDisplay_progressText("sending credentials");
254+
Log.println(nonce);
255+
Log.println(tag);
254256

255257
// Create the reply; SHA256(nonce, tag(secret), client, server);
256258
//
@@ -268,8 +270,24 @@ bool registerDevice() {
268270
sha256toHEX(sha256, (char*)tmp);
269271
mbedtls_sha256_free(&sha_ctx);
270272

273+
271274
snprintf((char *) buff, sizeof(buff), PAY_URL REGISTER_PATH "?response=%s", (char *)tmp);
272275

276+
if (0) {
277+
Debug.print("nonce=");
278+
Debug.println(nonce);
279+
Debug.print("tag=");
280+
Debug.println(tag);
281+
Debug.print("client=");
282+
sha256toHEX(sha256_client, (char*)tmp);
283+
Debug.println((char *)tmp);
284+
Debug.print("server=");
285+
sha256toHEX(sha256_server, (char*)tmp);
286+
Debug.println((char *)tmp);
287+
Debug.print("Result=");
288+
Debug.println((char *)tmp);
289+
};
290+
273291
if (!https.begin(client, (char *)buff )) {
274292
Log.println("Failed to begin https");
275293
goto exit;
@@ -286,6 +304,9 @@ bool registerDevice() {
286304

287305
if (httpCode != 200) {
288306
Log.println("Failed to register");
307+
// make sure we get a fresh nonce. So it cannot be a nonce timeout.
308+
//
309+
md = REGISTER;
289310
goto exit;
290311
}
291312

@@ -342,7 +363,8 @@ bool registerDevice() {
342363

343364
Debug.printf("version: 0x%x\n", keystore.getUShort(KS_KEY_VERSION, -1));
344365
Debug.printf("client_cert_as_pem: 0x%x (len)\n", keystore.getBytesLength(KS_KEY_CLIENT_CRT));
345-
Debug.printf("client_key_as_pem: 0x%x (len)\n", keystore.getBytesLength(KS_KEY_CLIENT_KEY));
366+
if (0)
367+
Debug.printf("client_key_as_pem: 0x%x (len)\n", keystore.getBytesLength(KS_KEY_CLIENT_KEY));
346368
Debug.printf("sha256_server_key: 0x%x (len)\n", keystore.getBytesLength(KS_KEY_SERVER_KEY));
347369

348370
keystore.end();

0 commit comments

Comments
 (0)