This repository was archived by the owner on Jan 6, 2023. It is now read-only.
File tree 6 files changed +22
-24
lines changed
6 files changed +22
-24
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,9 @@ const char *private_key_str =
45
45
"63:38:b0:90:57:57:e0:c0:9a:e8:6f:06:0c:d9:ee:"
46
46
"31:41" ;
47
47
48
+ // Time (seconds) to expire token += 20 minutes for drift
49
+ const int jwt_exp_secs = 3600 ; // Maximum 24H (3600*24)
50
+
48
51
// To get the certificate for your region run:
49
52
// openssl s_client -showcerts -connect mqtt.googleapis.com:8883
50
53
// Copy the certificate (all lines between and including ---BEGIN CERTIFICATE---
Original file line number Diff line number Diff line change @@ -50,13 +50,9 @@ String getDefaultSensor() {
50
50
}
51
51
52
52
String getJwt () {
53
- if (iss == 0 || time (nullptr ) - iss > 3600 ) { // TODO: exp in device
54
- iss = time (nullptr );
55
- Serial .println ("Refreshing JWT" );
56
- jwt = device -> createJWT (iss );
57
- } else {
58
- Serial .println ("Reusing still-valid JWT" );
59
- }
53
+ iss = time (nullptr );
54
+ Serial .println ("Refreshing JWT" );
55
+ jwt = device -> createJWT (iss , jwt_exp_secs );
60
56
return jwt ;
61
57
}
62
58
Original file line number Diff line number Diff line change @@ -41,6 +41,9 @@ const char* private_key_str =
41
41
"07:fd:ed:22:0d:03:2b:a6:b1:b6:04:0b:d5:9b:49:"
42
42
"7d:ca" ;
43
43
44
+ // Time (seconds) to expire token += 20 minutes for drift
45
+ const int jwt_exp_secs = 3600 ; // Maximum 24H (3600*24)
46
+
44
47
// Use the root certificate to verify tls connection rather than
45
48
// using a fingerprint.
46
49
//
Original file line number Diff line number Diff line change @@ -50,14 +50,12 @@ String getDefaultSensor() {
50
50
}
51
51
52
52
String getJwt () {
53
- if (iss == 0 || time (nullptr ) - iss > 3600 ) { // TODO: exp in device
54
- // Disable software watchdog as these operations can take a while.
55
- ESP .wdtDisable ();
56
- iss = time (nullptr );
57
- Serial .println ("Refreshing JWT" );
58
- jwt = device -> createJWT (iss );
59
- ESP .wdtEnable (0 );
60
- }
53
+ // Disable software watchdog as these operations can take a while.
54
+ ESP .wdtDisable ();
55
+ iss = time (nullptr );
56
+ Serial .println ("Refreshing JWT" );
57
+ jwt = device -> createJWT (iss , jwt_exp_secs );
58
+ ESP .wdtEnable (0 );
61
59
return jwt ;
62
60
}
63
61
@@ -142,9 +140,6 @@ void setupCloudIoT() {
142
140
netClient = new WiFiClientSecure ();
143
141
setupWifi ();
144
142
145
- // Device/Time OK, ESP8266 refresh JWT
146
- Serial .println (getJwt ());
147
-
148
143
// ESP8266 WiFi secure initialization
149
144
setupCert ();
150
145
Original file line number Diff line number Diff line change @@ -41,6 +41,9 @@ const char* private_key_str =
41
41
"07:fd:ed:22:0d:03:2b:a6:b1:b6:04:0b:d5:9b:49:"
42
42
"7d:ca" ;
43
43
44
+ // Time (seconds) to expire token += 20 minutes for drift
45
+ const int jwt_exp_secs = 3600 ; // Maximum 24H (3600*24)
46
+
44
47
// In case we ever need extra topics
45
48
const int ex_num_topics = 0 ;
46
49
const char * ex_topics [ex_num_topics ];
Original file line number Diff line number Diff line change @@ -48,12 +48,10 @@ String getDefaultSensor() {
48
48
}
49
49
50
50
String getJwt () {
51
- if (iss == 0 || WiFi .getTime () - iss > 3600 ) { // TODO: exp in device
52
- // Disable software watchdog as these operations can take a while.
53
- Serial .println ("Refreshing JWT" );
54
- iss = WiFi .getTime ();
55
- jwt = device -> createJWT (iss );
56
- }
51
+ // Disable software watchdog as these operations can take a while.
52
+ Serial .println ("Refreshing JWT" );
53
+ iss = WiFi .getTime ();
54
+ jwt = device -> createJWT (iss , jwt_exp_secs );
57
55
return jwt ;
58
56
}
59
57
You can’t perform that action at this time.
0 commit comments