init adding ethernet bee

This commit is contained in:
Mario Pesch
2022-01-24 14:48:35 +01:00
parent 1519a7f58b
commit 405b7fd465
5 changed files with 208 additions and 81 deletions
@@ -17,6 +17,16 @@ Blockly.Arduino.sensebox_send_to_osem = function (block) {
};
Blockly.Arduino.sensebox_osem_connection = function (Block) {
var workspace = Blockly.getMainWorkspace();
var wifi = false;
var ethernet = false;
if (workspace.getBlocksByType("sensebox_wifi").length > 0) {
wifi = true;
ethernet = false;
} else if (workspace.getBlocksByType("sensebox_ethernet").length > 0) {
ethernet = true;
wifi = false;
}
var box_id = this.getFieldValue("BoxID");
var host = this.getFieldValue("host");
var branch = Blockly.Arduino.statementToCode(Block, "DO");
@@ -42,12 +52,22 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) {
'const char SENSEBOX_ID [] PROGMEM = "' + box_id + '";';
Blockly.Arduino.definitions_["host"] =
"const char server [] PROGMEM =" + host + ";";
if (ssl === "TRUE") {
Blockly.Arduino.definitions_["WiFiSSLClient"] = "WiFiSSLClient client;";
port = 443;
} else if (ssl === "FALSE") {
Blockly.Arduino.definitions_["WiFiClient"] = "WiFiClient client;";
port = 80;
if (wifi === true) {
if (ssl === "TRUE") {
Blockly.Arduino.definitions_["WiFiSSLClient"] = "WiFiSSLClient client;";
port = 443;
} else if (ssl === "FALSE") {
Blockly.Arduino.definitions_["WiFiClient"] = "WiFiClient client;";
port = 80;
}
} else if (ethernet === true) {
if (ssl === "TRUE") {
Blockly.Arduino.definitions_["WiFiSSLClient"] = "WiFiSSLClient client;";
port = 443;
} else if (ssl === "FALSE") {
Blockly.Arduino.definitions_["EthernetClient"] = "EthernetClient client;";
port = 80;
}
}
Blockly.Arduino.definitions_["measurement"] = `typedef struct measurement {
@@ -1,25 +1,76 @@
import Blockly from 'blockly';
import Blockly from "blockly";
/* Wifi connection and openSenseMap Blocks*/
Blockly.Arduino.sensebox_wifi = function (block) {
var pw = this.getFieldValue('Password');
var ssid = this.getFieldValue('SSID');
Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"';
Blockly.Arduino.definitions_['define_network'] = 'Bee* b = new Bee();';
if (pw === "") {
Blockly.Arduino.setupCode_['sensebox_network'] = 'b->connectToWifi("' + ssid + '");\ndelay(1000);';
} else
Blockly.Arduino.setupCode_['sensebox_network'] = 'b->connectToWifi("' + ssid + '","' + pw + '");\ndelay(1000);';
var code = '';
return code;
var pw = this.getFieldValue("Password");
var ssid = this.getFieldValue("SSID");
Blockly.Arduino.libraries_["library_senseBoxMCU"] =
'#include "SenseBoxMCU.h"';
Blockly.Arduino.definitions_["define_network"] = "Bee* b = new Bee();";
if (pw === "") {
Blockly.Arduino.setupCode_["sensebox_network"] =
'b->connectToWifi("' + ssid + '");\ndelay(1000);';
} else
Blockly.Arduino.setupCode_["sensebox_network"] =
'b->connectToWifi("' + ssid + '","' + pw + '");\ndelay(1000);';
var code = "";
return code;
};
Blockly.Arduino.sensebox_startap = function (block) {
var ssid = this.getFieldValue('SSID');
Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"';
Blockly.Arduino.definitions_['define_network'] = 'Bee* b = new Bee();';
Blockly.Arduino.setupCode_['sensebox_network'] = 'b->startAP("' + ssid + '");'
var code = '';
return code;
};
var ssid = this.getFieldValue("SSID");
Blockly.Arduino.libraries_["library_senseBoxMCU"] =
'#include "SenseBoxMCU.h"';
Blockly.Arduino.definitions_["define_network"] = "Bee* b = new Bee();";
Blockly.Arduino.setupCode_["sensebox_network"] =
'b->startAP("' + ssid + '");';
var code = "";
return code;
};
Blockly.Arduino.sensebox_ethernet = function () {
var ip = this.getFieldValue("ip");
var gateway = this.getFieldValue("gateway");
var subnetmask = this.getFieldValue("subnetmask");
var dns = this.getFieldValue("dns");
var mac = this.getFieldValue("mac");
var dhcp = this.getFieldValue("dhcp");
Blockly.Arduino.libraries_["library_senseBoxMCU"] =
'#include "SenseBoxMCU.h"';
Blockly.Arduino.libraries_["library_ethernet"] = "#include <Ethernet.h>";
Blockly.Arduino.definitions_["ethernet_config"] = `
byte mac[] = { ${mac}};`;
if (dhcp === "Manual") {
Blockly.Arduino.definitions_["ethernet_manual_config"] = `
//Configure static IP setup (only needed if DHCP is disabled)
IPAddress myIp(${ip.replaceAll(".", ", ")});
IPAddress myDns(${dns.replaceAll(".", ",")});
IPAddress myGateway(${gateway.replaceAll(".", ",")}192, 168, 0, 177);
IPAddress mySubnet(${subnetmask.replaceAll(".", ",")}255, 255, 255, 0);
`;
Blockly.Arduino.setupCode_["ethernet_setup"] = `
Ethernet.init(23);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
// no point in carrying on, so do nothing forevermore:
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, myIp);
}
// give the Ethernet shield a second to initialize:
delay(1000);
`;
} else {
Blockly.Arduino.setupCode_["ethernet_setup"] = `
Ethernet.init(23);
// start the Ethernet connection:
Ethernet.begin(mac);
// give the Ethernet shield a second to initialize:
delay(1000);
`;
}
var code = "";
return code;
};