diff --git a/src/components/Blockly/blocks/sensebox-web.js b/src/components/Blockly/blocks/sensebox-web.js index 5471e75..b98d33e 100644 --- a/src/components/Blockly/blocks/sensebox-web.js +++ b/src/components/Blockly/blocks/sensebox-web.js @@ -108,3 +108,14 @@ Blockly.Blocks["sensebox_ethernet"] = { } }, }; + +Blockly.Blocks["sensebox_ethernetIp"] = { + init: function () { + this.appendDummyInput().appendField(Blockly.Msg.senseBox_ethernet_ip); + + this.setColour(getColour().sensebox); + this.setHelpUrl(Blockly.Msg.senseBox_ethernetIp_helpurl); + this.setTooltip(Blockly.Msg.senseBox_ethernet_ip_tooltip); + this.setOutput(true, null); + }, +}; diff --git a/src/components/Blockly/generator/sensebox-web.js b/src/components/Blockly/generator/sensebox-web.js index 359cfd4..5f4124c 100644 --- a/src/components/Blockly/generator/sensebox-web.js +++ b/src/components/Blockly/generator/sensebox-web.js @@ -41,36 +41,41 @@ Blockly.Arduino.sensebox_ethernet = function () { Blockly.Arduino.libraries_["library_ethernet"] = "#include "; Blockly.Arduino.definitions_["ethernet_config"] = ` - byte mac[] = { ${mac}};`; +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(".", ",")}); - IPAddress mySubnet(${subnetmask.replaceAll(".", ",")}); +//Configure static IP setup (only needed if DHCP is disabled) +IPAddress myIp(${ip.replaceAll(".", ", ")}); +IPAddress myDns(${dns.replaceAll(".", ",")}); +IPAddress myGateway(${gateway.replaceAll(".", ",")}); +IPAddress mySubnet(${subnetmask.replaceAll(".", ",")}); `; 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); +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); +Ethernet.init(23); +// start the Ethernet connection: +Ethernet.begin(mac); +// give the Ethernet shield a second to initialize: +delay(1000); `; } var code = ""; return code; }; + +Blockly.Arduino.sensebox_ethernetIp = function () { + var code = "Ethernet.localIP()"; + return [code, Blockly.Arduino.ORDER_ATOMIC]; +}; diff --git a/src/components/Blockly/toolbox/Toolbox.js b/src/components/Blockly/toolbox/Toolbox.js index 8f71bbc..961233f 100644 --- a/src/components/Blockly/toolbox/Toolbox.js +++ b/src/components/Blockly/toolbox/Toolbox.js @@ -94,8 +94,9 @@ class Toolbox extends React.Component { - + +