fix ssl problems 🚒
This commit is contained in:
parent
c525127a9b
commit
d3ca85d2e4
@ -14,11 +14,6 @@ var selectedBox = "";
|
|||||||
Blockly.Blocks["sensebox_osem_connection"] = {
|
Blockly.Blocks["sensebox_osem_connection"] = {
|
||||||
init: function () {
|
init: function () {
|
||||||
var ssl = "TRUE";
|
var ssl = "TRUE";
|
||||||
var workspace = Blockly.getMainWorkspace();
|
|
||||||
if (workspace.getBlocksByType("sensebox_ethernet").length > 0) {
|
|
||||||
ssl = "FALSE";
|
|
||||||
console.log("ethernet");
|
|
||||||
}
|
|
||||||
this.setTooltip(Blockly.Msg.senseBox_osem_connection_tip);
|
this.setTooltip(Blockly.Msg.senseBox_osem_connection_tip);
|
||||||
this.setHelpUrl("");
|
this.setHelpUrl("");
|
||||||
this.setColour(getColour().sensebox);
|
this.setColour(getColour().sensebox);
|
||||||
|
@ -75,7 +75,25 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) {
|
|||||||
"#include <ArduinoBearSSL.h>";
|
"#include <ArduinoBearSSL.h>";
|
||||||
Blockly.Arduino.libraries_["library_arduinoECC08"] =
|
Blockly.Arduino.libraries_["library_arduinoECC08"] =
|
||||||
"#include <ArduinoECCX08.h>";
|
"#include <ArduinoECCX08.h>";
|
||||||
Blockly.Arduino.definitions_["WiFiSSLClient"] = "WiFiSSLClient client;";
|
Blockly.Arduino.libraries_["library_ethernetUdp"] =
|
||||||
|
"#include <EthernetUdp.h>";
|
||||||
|
Blockly.Arduino.libraries_["library_NTPClient"] =
|
||||||
|
"#include <NTPClient.h>";
|
||||||
|
Blockly.Arduino.definitions_["EthernetClient"] =
|
||||||
|
"EthernetClient eclient;";
|
||||||
|
Blockly.Arduino.definitions_["BearSSLClient"] =
|
||||||
|
"BearSSLClient client(eclient);";
|
||||||
|
Blockly.Arduino.definitions_["EthernetUDP"] = "EthernetUDP Udp;";
|
||||||
|
Blockly.Arduino.definitions_["NTPClient"] = "NTPClient timeClient(Udp);";
|
||||||
|
Blockly.Arduino.functionNames_["getTime"] = `
|
||||||
|
unsigned long getTime() {
|
||||||
|
timeClient.update();
|
||||||
|
return timeClient.getEpochTime();
|
||||||
|
}`;
|
||||||
|
|
||||||
|
Blockly.Arduino.setupCode_["timeClient_begin"] = "timeClient.begin();";
|
||||||
|
Blockly.Arduino.setupCode_["initBearSSL"] =
|
||||||
|
"ArduinoBearSSL.onGetTime(getTime);";
|
||||||
port = 443;
|
port = 443;
|
||||||
} else if (ssl === "FALSE") {
|
} else if (ssl === "FALSE") {
|
||||||
Blockly.Arduino.definitions_["EthernetClient"] = "EthernetClient client;";
|
Blockly.Arduino.definitions_["EthernetClient"] = "EthernetClient client;";
|
||||||
@ -115,9 +133,14 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) {
|
|||||||
Blockly.Arduino.functionNames_["submitValues"] =
|
Blockly.Arduino.functionNames_["submitValues"] =
|
||||||
`
|
`
|
||||||
void submitValues() {
|
void submitValues() {
|
||||||
|
${
|
||||||
|
wifi === true
|
||||||
|
? "if (WiFi.status() != WL_CONNECTED) {\nWiFi.disconnect();\ndelay(1000); // wait 1s\nWiFi.begin(ssid, pass);\ndelay(5000); // wait 5s\n}"
|
||||||
|
: ""
|
||||||
|
}
|
||||||
if (client.connected()) {
|
if (client.connected()) {
|
||||||
client.stop();
|
client.stop();
|
||||||
delay(10);
|
delay(1000);
|
||||||
}
|
}
|
||||||
bool connected = false;
|
bool connected = false;
|
||||||
char _server[strlen_P(server)];
|
char _server[strlen_P(server)];
|
||||||
@ -148,9 +171,20 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (client.available()) {
|
||||||
|
char c = client.read();
|
||||||
|
// if the server's disconnected, stop the client:
|
||||||
|
if (!client.connected()) {
|
||||||
|
client.stop();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
num_measurements = 0;
|
num_measurements = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
delay(1000);
|
||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
@ -230,6 +264,14 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
while (client.available()) {
|
||||||
|
char c = client.read();
|
||||||
|
// if the server's disconnected, stop the client:
|
||||||
|
if (!client.connected()) {
|
||||||
|
client.stop();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
num_measurements = 0;
|
num_measurements = 0;
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user