Merge branch 'remove-senseboxmcu-lib' into block/add-ethernet-bee
This commit is contained in:
@@ -62,9 +62,7 @@ Blockly["Arduino"].addReservedWords(
|
||||
"pulseIn,millis,micros,delay,delayMicroseconds,min,max,abs,constrain," +
|
||||
"map,pow,sqrt,sin,cos,tan,randomSeed,random,lowByte,highByte,bitRead," +
|
||||
"bitWrite,bitSet,bitClear,ultraSonicDistance,parseDouble,setNeoPixelColor," +
|
||||
"bit,attachInterrupt,detachInterrupt,interrupts,noInterrupts",
|
||||
"short",
|
||||
"isBtnPressed"
|
||||
"bit,attachInterrupt,detachInterrupt,interrupts,noInterrupts,short,isBtnPressed"
|
||||
);
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,6 +19,7 @@ import "./map";
|
||||
import "./io";
|
||||
import "./audio";
|
||||
import "./procedures";
|
||||
import "./serial";
|
||||
import "./time";
|
||||
import "./variables";
|
||||
import "./lists";
|
||||
|
||||
@@ -1,52 +1,77 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
import * as Blockly from "blockly/core";
|
||||
/**
|
||||
* MQTT Blocks
|
||||
*/
|
||||
* MQTT Blocks
|
||||
*/
|
||||
|
||||
let service;
|
||||
|
||||
Blockly.Arduino.sensebox_mqtt_setup = function () {
|
||||
var server = this.getFieldValue('server');
|
||||
var port = this.getFieldValue('port');
|
||||
var username = this.getFieldValue('username');
|
||||
var pass = this.getFieldValue('password');
|
||||
service = this.getFieldValue('service');
|
||||
Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"';
|
||||
Blockly.Arduino.libraries_['library_adafruitmqtt'] = '#include "Adafruit_MQTT.h"';
|
||||
Blockly.Arduino.libraries_['library_adafruitmqttclient'] = '#include "Adafruit_MQTT_Client.h"';
|
||||
Blockly.Arduino.definitions_['mqtt_server'] = '#define SERVER "' + server + '"';
|
||||
Blockly.Arduino.definitions_['mqtt_port'] = '#define SERVERPORT ' + port + '';
|
||||
Blockly.Arduino.definitions_['mqtt_username'] = '#define USERNAME "' + username + '"';
|
||||
Blockly.Arduino.definitions_['mqtt_pass'] = '#define PASS "' + pass + '"';
|
||||
Blockly.Arduino.definitions_['wifi_client'] = 'WiFiClient client;';
|
||||
Blockly.Arduino.definitions_['mqtt_client'] = 'Adafruit_MQTT_Client mqtt(&client, SERVER, SERVERPORT, USERNAME, PASS);'
|
||||
var code = '';
|
||||
return code;
|
||||
var server = this.getFieldValue("server");
|
||||
var port = this.getFieldValue("port");
|
||||
var username = this.getFieldValue("username");
|
||||
var pass = this.getFieldValue("password");
|
||||
service = this.getFieldValue("service");
|
||||
Blockly.Arduino.libraries_["library_senseBoxIO"] = "#include <senseBoxIO.h>";
|
||||
Blockly.Arduino.libraries_["library_adafruitmqtt"] =
|
||||
'#include "Adafruit_MQTT.h"';
|
||||
Blockly.Arduino.libraries_["library_adafruitmqttclient"] =
|
||||
'#include "Adafruit_MQTT_Client.h"';
|
||||
Blockly.Arduino.definitions_["mqtt_server"] =
|
||||
'#define SERVER "' + server + '"';
|
||||
Blockly.Arduino.definitions_["mqtt_port"] =
|
||||
"#define SERVERPORT " + port + "";
|
||||
Blockly.Arduino.definitions_["mqtt_username"] =
|
||||
'#define USERNAME "' + username + '"';
|
||||
Blockly.Arduino.definitions_["mqtt_pass"] =
|
||||
'#define PASS "' + pass + '"';
|
||||
Blockly.Arduino.definitions_["wifi_client"] = "WiFiClient client;";
|
||||
Blockly.Arduino.definitions_["mqtt_client"] =
|
||||
"Adafruit_MQTT_Client mqtt(&client, SERVER, SERVERPORT, USERNAME, PASS);";
|
||||
var code = "";
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_mqtt_publish = function (block) {
|
||||
var feedname = this.getFieldValue('publishfeed');
|
||||
var res = feedname.split("/");
|
||||
var feed_client = res[res.length - 1];
|
||||
var value = Blockly.Arduino.valueToCode(this, 'value', Blockly.Arduino.ORDER_ATOMIC) || '"No Block connected"';
|
||||
var feedname = this.getFieldValue("publishfeed");
|
||||
var res = feedname.split("/");
|
||||
var feed_client = res[res.length - 1];
|
||||
var value =
|
||||
Blockly.Arduino.valueToCode(this, "value", Blockly.Arduino.ORDER_ATOMIC) ||
|
||||
'"No Block connected"';
|
||||
|
||||
switch (service) {
|
||||
case 'adafruitio':
|
||||
Blockly.Arduino.definitions_['mqtt_' + feed_client + ''] = 'Adafruit_MQTT_Publish ' + feed_client + ' = Adafruit_MQTT_Publish(&mqtt, USERNAME "/feeds/' + feedname + '");'
|
||||
break;
|
||||
case 'dioty':
|
||||
Blockly.Arduino.definitions_['mqtt_' + feed_client + ''] = 'Adafruit_MQTT_Publish ' + feed_client + ' = Adafruit_MQTT_Publish(&mqtt, "/"USERNAME"/' + feedname + '");'
|
||||
break;
|
||||
case 'custom':
|
||||
Blockly.Arduino.definitions_['mqtt_' + feed_client + ''] = 'Adafruit_MQTT_Publish ' + feed_client + ' = Adafruit_MQTT_Publish(&mqtt, "' + feedname + '");'
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
switch (service) {
|
||||
case "adafruitio":
|
||||
Blockly.Arduino.definitions_["mqtt_" + feed_client + ""] =
|
||||
"Adafruit_MQTT_Publish " +
|
||||
feed_client +
|
||||
' = Adafruit_MQTT_Publish(&mqtt, USERNAME "/feeds/' +
|
||||
feedname +
|
||||
'");';
|
||||
break;
|
||||
case "dioty":
|
||||
Blockly.Arduino.definitions_["mqtt_" + feed_client + ""] =
|
||||
"Adafruit_MQTT_Publish " +
|
||||
feed_client +
|
||||
' = Adafruit_MQTT_Publish(&mqtt, "/"USERNAME"/' +
|
||||
feedname +
|
||||
'");';
|
||||
break;
|
||||
case "custom":
|
||||
Blockly.Arduino.definitions_["mqtt_" + feed_client + ""] =
|
||||
"Adafruit_MQTT_Publish " +
|
||||
feed_client +
|
||||
' = Adafruit_MQTT_Publish(&mqtt, "' +
|
||||
feedname +
|
||||
'");';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Blockly.Arduino.definitions_['mqtt_' + feed_client + ''] = 'Adafruit_MQTT_Publish ' + feed_client + ' = Adafruit_MQTT_Publish(&mqtt, USERNAME "/feeds/' + feedname + '");'
|
||||
Blockly.Arduino.codeFunctions_['mqtt_connect_function'] = `// Function to connect and reconnect as necessary to the MQTT server.
|
||||
//Blockly.Arduino.definitions_['mqtt_' + feed_client + ''] = 'Adafruit_MQTT_Publish ' + feed_client + ' = Adafruit_MQTT_Publish(&mqtt, USERNAME "/feeds/' + feedname + '");'
|
||||
Blockly.Arduino.codeFunctions_[
|
||||
"mqtt_connect_function"
|
||||
] = `// Function to connect and reconnect as necessary to the MQTT server.
|
||||
// Should be called in the loop function and it will take care if connecting.
|
||||
void MQTT_connect() {
|
||||
int8_t ret;
|
||||
@@ -59,23 +84,34 @@ void MQTT_connect() {
|
||||
delay(5000); // wait 5 seconds
|
||||
}
|
||||
}`;
|
||||
Blockly.Arduino.loopCodeOnce_['mqtt_connect'] = 'MQTT_connect();';
|
||||
var code = '' + feed_client + '.publish(' + value + ');';
|
||||
return code
|
||||
Blockly.Arduino.loopCodeOnce_["mqtt_connect"] = "MQTT_connect();";
|
||||
var code = "" + feed_client + ".publish(" + value + ");";
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_mqtt_subscribe = function (block) {
|
||||
var feedname = this.getFieldValue('subscribefeed');
|
||||
var x = 5, feed_client;
|
||||
feed_client = feedname.substr(feedname.length - x, x);
|
||||
Blockly.Arduino.definitions_['mqtt_' + feed_client + ''] = 'Adafruit_MQTT_Subscribe ' + feed_client + '= Adafruit_MQTT_Subscribe(&mqtt,' + feedname + ');';
|
||||
Blockly.Arduino.codeFunctions_['mqtt_' + feed_client + 'callbackFunction'] = `void ` + feed_client + `Callback (double x){
|
||||
var feedname = this.getFieldValue("subscribefeed");
|
||||
var x = 5,
|
||||
feed_client;
|
||||
feed_client = feedname.substr(feedname.length - x, x);
|
||||
Blockly.Arduino.definitions_["mqtt_" + feed_client + ""] =
|
||||
"Adafruit_MQTT_Subscribe " +
|
||||
feed_client +
|
||||
"= Adafruit_MQTT_Subscribe(&mqtt," +
|
||||
feedname +
|
||||
");";
|
||||
Blockly.Arduino.codeFunctions_["mqtt_" + feed_client + "callbackFunction"] =
|
||||
`void ` +
|
||||
feed_client +
|
||||
`Callback (double x){
|
||||
Serial.println(x);
|
||||
}`;
|
||||
Blockly.Arduino.setupCode_['mqtt_' + feed_client + '_callback'] = '' + feed_client + '.setCallback(' + feed_client + 'Callback);';
|
||||
Blockly.Arduino.setupCode_['mqtt_' + feed_client + '_subscribe'] = 'mqtt.subscribe(&' + feed_client + ');';
|
||||
Blockly.Arduino.loopCodeOnce_['mqtt_processPackages'] = 'mqtt.processPackets(10);';
|
||||
var code = '';
|
||||
return code;
|
||||
Blockly.Arduino.setupCode_["mqtt_" + feed_client + "_callback"] =
|
||||
"" + feed_client + ".setCallback(" + feed_client + "Callback);";
|
||||
Blockly.Arduino.setupCode_["mqtt_" + feed_client + "_subscribe"] =
|
||||
"mqtt.subscribe(&" + feed_client + ");";
|
||||
Blockly.Arduino.loopCodeOnce_["mqtt_processPackages"] =
|
||||
"mqtt.processPackets(10);";
|
||||
var code = "";
|
||||
return code;
|
||||
};
|
||||
|
||||
|
||||
@@ -2,9 +2,8 @@ import * as Blockly from "blockly/core";
|
||||
|
||||
Blockly.Arduino.sensebox_phyphox_init = function () {
|
||||
var name = this.getFieldValue("devicename");
|
||||
Blockly.Arduino.libraries_["library_senseBoxIO"] = "#include <senseBoxIO.h>";
|
||||
Blockly.Arduino.libraries_["phyphox_library"] = `#include <phyphoxBle.h>`;
|
||||
Blockly.Arduino.libraries_["library_senseBoxMCU"] =
|
||||
'#include "SenseBoxMCU.h"';
|
||||
Blockly.Arduino.phyphoxSetupCode_[
|
||||
"phyphox_start"
|
||||
] = `PhyphoxBLE::start("${name}");`;
|
||||
|
||||
@@ -1,45 +1,75 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
import * as Blockly from "blockly/core";
|
||||
|
||||
/*Display Blocks*/
|
||||
Blockly.Arduino.sensebox_display_beginDisplay = function () {
|
||||
Blockly.Arduino.libraries_['library_spi'] = '#include <SPI.h>';
|
||||
Blockly.Arduino.libraries_['library_wire'] = '#include <Wire.h>';
|
||||
Blockly.Arduino.libraries_['library_AdafruitGFX'] = '#include <Adafruit_GFX.h>';
|
||||
Blockly.Arduino.libraries_['library_AdafruitSSD1306'] = '#include <Adafruit_SSD1306.h>';
|
||||
Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"';
|
||||
Blockly.Arduino.definitions_['define_display'] = '#define OLED_RESET 4\nAdafruit_SSD1306 display(OLED_RESET);';
|
||||
Blockly.Arduino.setupCode_['sensebox_display_begin'] = 'senseBoxIO.powerI2C(true);\ndelay(2000);\ndisplay.begin(SSD1306_SWITCHCAPVCC, 0x3D);\ndisplay.display();\ndelay(100);\ndisplay.clearDisplay();';
|
||||
var code = '';
|
||||
return code;
|
||||
Blockly.Arduino.libraries_["library_spi"] = "#include <SPI.h>";
|
||||
Blockly.Arduino.libraries_["library_wire"] = "#include <Wire.h>";
|
||||
Blockly.Arduino.libraries_["library_AdafruitGFX"] =
|
||||
"#include <Adafruit_GFX.h>";
|
||||
Blockly.Arduino.libraries_["library_AdafruitSSD1306"] =
|
||||
"#include <Adafruit_SSD1306.h>";
|
||||
Blockly.Arduino.libraries_["library_senseBoxIO"] = "#include <senseBoxIO.h>";
|
||||
Blockly.Arduino.definitions_["define_display"] =
|
||||
"#define OLED_RESET 4\nAdafruit_SSD1306 display(OLED_RESET);";
|
||||
Blockly.Arduino.setupCode_["sensebox_display_begin"] =
|
||||
"senseBoxIO.powerI2C(true);\ndelay(2000);\ndisplay.begin(SSD1306_SWITCHCAPVCC, 0x3D);\ndisplay.display();\ndelay(100);\ndisplay.clearDisplay();";
|
||||
var code = "";
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_display_clearDisplay = function () {
|
||||
var code = 'display.clearDisplay();\n';
|
||||
return code;
|
||||
var code = "display.clearDisplay();\n";
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_display_printDisplay = function () {
|
||||
var x = this.getFieldValue('X');
|
||||
var y = this.getFieldValue('Y');
|
||||
var printDisplay = Blockly.Arduino.valueToCode(this, 'printDisplay', Blockly.Arduino.ORDER_ATOMIC) || '"Keine Eingabe"';
|
||||
var size = this.getFieldValue('SIZE');
|
||||
var color = this.getFieldValue('COLOR');
|
||||
var code = 'display.setCursor(' + x + ',' + y + ');\n';
|
||||
code += 'display.setTextSize(' + size + ');\n';
|
||||
code += 'display.setTextColor(' + color + ');\n';
|
||||
code += 'display.println(' + printDisplay + ');\n';
|
||||
return code;
|
||||
var x = this.getFieldValue("X");
|
||||
var y = this.getFieldValue("Y");
|
||||
var printDisplay =
|
||||
Blockly.Arduino.valueToCode(
|
||||
this,
|
||||
"printDisplay",
|
||||
Blockly.Arduino.ORDER_ATOMIC
|
||||
) || '"Keine Eingabe"';
|
||||
var size = this.getFieldValue("SIZE");
|
||||
var color = this.getFieldValue("COLOR");
|
||||
var code = "display.setCursor(" + x + "," + y + ");\n";
|
||||
code += "display.setTextSize(" + size + ");\n";
|
||||
code += "display.setTextColor(" + color + ");\n";
|
||||
code += "display.println(" + printDisplay + ");\n";
|
||||
return code;
|
||||
};
|
||||
|
||||
|
||||
Blockly.Arduino.sensebox_display_fastPrint = function () {
|
||||
var title1 = Blockly.Arduino.valueToCode(this, 'Title1', Blockly.Arduino.ORDER_ATOMIC) || '0'
|
||||
var value1 = Blockly.Arduino.valueToCode(this, 'Value1', Blockly.Arduino.ORDER_ATOMIC);
|
||||
var dimension1 = Blockly.Arduino.valueToCode(this, 'Dimension1', Blockly.Arduino.ORDER_ATOMIC) || '0'
|
||||
var title2 = Blockly.Arduino.valueToCode(this, 'Title2', Blockly.Arduino.ORDER_ATOMIC) || '0'
|
||||
var value2 = Blockly.Arduino.valueToCode(this, 'Value2', Blockly.Arduino.ORDER_ATOMIC);
|
||||
var dimension2 = Blockly.Arduino.valueToCode(this, 'Dimension2', Blockly.Arduino.ORDER_ATOMIC) || '0'
|
||||
Blockly.Arduino.codeFunctions_['sensebox_fastPrint'] = `
|
||||
var title1 =
|
||||
Blockly.Arduino.valueToCode(this, "Title1", Blockly.Arduino.ORDER_ATOMIC) ||
|
||||
"0";
|
||||
var value1 = Blockly.Arduino.valueToCode(
|
||||
this,
|
||||
"Value1",
|
||||
Blockly.Arduino.ORDER_ATOMIC
|
||||
);
|
||||
var dimension1 =
|
||||
Blockly.Arduino.valueToCode(
|
||||
this,
|
||||
"Dimension1",
|
||||
Blockly.Arduino.ORDER_ATOMIC
|
||||
) || "0";
|
||||
var title2 =
|
||||
Blockly.Arduino.valueToCode(this, "Title2", Blockly.Arduino.ORDER_ATOMIC) ||
|
||||
"0";
|
||||
var value2 = Blockly.Arduino.valueToCode(
|
||||
this,
|
||||
"Value2",
|
||||
Blockly.Arduino.ORDER_ATOMIC
|
||||
);
|
||||
var dimension2 =
|
||||
Blockly.Arduino.valueToCode(
|
||||
this,
|
||||
"Dimension2",
|
||||
Blockly.Arduino.ORDER_ATOMIC
|
||||
) || "0";
|
||||
Blockly.Arduino.codeFunctions_["sensebox_fastPrint"] = `
|
||||
void printOnDisplay(String title1, String measurement1, String unit1, String title2, String measurement2, String unit2) {
|
||||
|
||||
display.setCursor(0, 0);
|
||||
@@ -62,67 +92,141 @@ Blockly.Arduino.sensebox_display_fastPrint = function () {
|
||||
display.setTextSize(1);
|
||||
display.println(unit2);
|
||||
}
|
||||
`
|
||||
var code = ` printOnDisplay(${title1}, String(${value1}), ${dimension1}, ${title2}, String(${value2}), ${dimension2});\n`;
|
||||
return code;
|
||||
`;
|
||||
var code = ` printOnDisplay(${title1}, String(${value1}), ${dimension1}, ${title2}, String(${value2}), ${dimension2});\n`;
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_display_show = function (block) {
|
||||
var show = Blockly.Arduino.statementToCode(block, 'SHOW');
|
||||
var code = '';
|
||||
code += show;
|
||||
code += 'display.display();\n';
|
||||
return code;
|
||||
var show = Blockly.Arduino.statementToCode(block, "SHOW");
|
||||
var code = "";
|
||||
code += show;
|
||||
code += "display.display();\n";
|
||||
return code;
|
||||
};
|
||||
Blockly.Arduino.sensebox_display_plotDisplay = function () {
|
||||
var YLabel = Blockly.Arduino.valueToCode(this, 'YLabel', Blockly.Arduino.ORDER_ATOMIC) || 'Y'
|
||||
var XLabel = Blockly.Arduino.valueToCode(this, 'XLabel', Blockly.Arduino.ORDER_ATOMIC) || 'X'
|
||||
var Title = Blockly.Arduino.valueToCode(this, 'Title', Blockly.Arduino.ORDER_ATOMIC) || 'Title'
|
||||
var XRange1 = Blockly.Arduino.valueToCode(this, 'XRange1', Blockly.Arduino.ORDER_ATOMIC) || '0'
|
||||
var XRange2 = Blockly.Arduino.valueToCode(this, 'XRange2', Blockly.Arduino.ORDER_ATOMIC) || '0'
|
||||
var YRange1 = Blockly.Arduino.valueToCode(this, 'YRange1', Blockly.Arduino.ORDER_ATOMIC) || '0'
|
||||
var YRange2 = Blockly.Arduino.valueToCode(this, 'YRange2', Blockly.Arduino.ORDER_ATOMIC) || '0'
|
||||
var XTick = Blockly.Arduino.valueToCode(this, 'XTick', Blockly.Arduino.ORDER_ATOMIC) || '0'
|
||||
var YTick = Blockly.Arduino.valueToCode(this, 'YTick', Blockly.Arduino.ORDER_ATOMIC) || '0'
|
||||
var TimeFrame = Blockly.Arduino.valueToCode(this, 'TimeFrame', Blockly.Arduino.ORDER_ATOMIC) || '0'
|
||||
var plotDisplay = Blockly.Arduino.valueToCode(this, 'plotDisplay', Blockly.Arduino.ORDER_ATOMIC) || '"Keine Eingabe"';
|
||||
Blockly.Arduino.libraries_['library_plot'] = '#include <Plot.h>';
|
||||
Blockly.Arduino.definitions_['define_plot_class'] = 'Plot DataPlot(&display);\n';
|
||||
Blockly.Arduino.variables_['define_plot_class'] = 'const double TIMEFRAME = ' + TimeFrame + ';\n';
|
||||
Blockly.Arduino.setupCode_['sensebox_plot_setup'] = 'DataPlot.setTitle(' + Title + ');\nDataPlot.setXLabel(' + XLabel + ');\nDataPlot.setYLabel(' + YLabel + ');\nDataPlot.setXRange(' + XRange1 + ',' + XRange2 + ');\nDataPlot.setYRange(' + YRange1 + ',' + YRange2 + ');\nDataPlot.setXTick(' + XTick + ');\nDataPlot.setYTick(' + YTick + ');\nDataPlot.setXPrecision(0);\nDataPlot.setYPrecision(0);\n';
|
||||
var code = 'DataPlot.clear();'
|
||||
code += 'double starttime = millis();\ndouble t = 0;\nwhile (t <= TIMEFRAME) {\nt = (millis() - starttime) / 1000.0;\nfloat value = ' + plotDisplay + ';\n';
|
||||
code += 'DataPlot.addDataPoint(t,value);\n}\n';
|
||||
return code;
|
||||
var YLabel =
|
||||
Blockly.Arduino.valueToCode(this, "YLabel", Blockly.Arduino.ORDER_ATOMIC) ||
|
||||
"Y";
|
||||
var XLabel =
|
||||
Blockly.Arduino.valueToCode(this, "XLabel", Blockly.Arduino.ORDER_ATOMIC) ||
|
||||
"X";
|
||||
var Title =
|
||||
Blockly.Arduino.valueToCode(this, "Title", Blockly.Arduino.ORDER_ATOMIC) ||
|
||||
"Title";
|
||||
var XRange1 =
|
||||
Blockly.Arduino.valueToCode(
|
||||
this,
|
||||
"XRange1",
|
||||
Blockly.Arduino.ORDER_ATOMIC
|
||||
) || "0";
|
||||
var XRange2 =
|
||||
Blockly.Arduino.valueToCode(
|
||||
this,
|
||||
"XRange2",
|
||||
Blockly.Arduino.ORDER_ATOMIC
|
||||
) || "0";
|
||||
var YRange1 =
|
||||
Blockly.Arduino.valueToCode(
|
||||
this,
|
||||
"YRange1",
|
||||
Blockly.Arduino.ORDER_ATOMIC
|
||||
) || "0";
|
||||
var YRange2 =
|
||||
Blockly.Arduino.valueToCode(
|
||||
this,
|
||||
"YRange2",
|
||||
Blockly.Arduino.ORDER_ATOMIC
|
||||
) || "0";
|
||||
var XTick =
|
||||
Blockly.Arduino.valueToCode(this, "XTick", Blockly.Arduino.ORDER_ATOMIC) ||
|
||||
"0";
|
||||
var YTick =
|
||||
Blockly.Arduino.valueToCode(this, "YTick", Blockly.Arduino.ORDER_ATOMIC) ||
|
||||
"0";
|
||||
var TimeFrame =
|
||||
Blockly.Arduino.valueToCode(
|
||||
this,
|
||||
"TimeFrame",
|
||||
Blockly.Arduino.ORDER_ATOMIC
|
||||
) || "0";
|
||||
var plotDisplay =
|
||||
Blockly.Arduino.valueToCode(
|
||||
this,
|
||||
"plotDisplay",
|
||||
Blockly.Arduino.ORDER_ATOMIC
|
||||
) || '"Keine Eingabe"';
|
||||
Blockly.Arduino.libraries_["library_plot"] = "#include <Plot.h>";
|
||||
Blockly.Arduino.definitions_["define_plot_class"] =
|
||||
"Plot DataPlot(&display);\n";
|
||||
Blockly.Arduino.variables_["define_plot_class"] =
|
||||
"const double TIMEFRAME = " + TimeFrame + ";\n";
|
||||
Blockly.Arduino.setupCode_["sensebox_plot_setup"] =
|
||||
"DataPlot.setTitle(" +
|
||||
Title +
|
||||
");\nDataPlot.setXLabel(" +
|
||||
XLabel +
|
||||
");\nDataPlot.setYLabel(" +
|
||||
YLabel +
|
||||
");\nDataPlot.setXRange(" +
|
||||
XRange1 +
|
||||
"," +
|
||||
XRange2 +
|
||||
");\nDataPlot.setYRange(" +
|
||||
YRange1 +
|
||||
"," +
|
||||
YRange2 +
|
||||
");\nDataPlot.setXTick(" +
|
||||
XTick +
|
||||
");\nDataPlot.setYTick(" +
|
||||
YTick +
|
||||
");\nDataPlot.setXPrecision(0);\nDataPlot.setYPrecision(0);\n";
|
||||
var code = "DataPlot.clear();";
|
||||
code +=
|
||||
"double starttime = millis();\ndouble t = 0;\nwhile (t <= TIMEFRAME) {\nt = (millis() - starttime) / 1000.0;\nfloat value = " +
|
||||
plotDisplay +
|
||||
";\n";
|
||||
code += "DataPlot.addDataPoint(t,value);\n}\n";
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_display_fillCircle = function () {
|
||||
let code = '';
|
||||
var x = Blockly.Arduino.valueToCode(this, 'X', Blockly.Arduino.ORDER_ATOMIC) || '0'
|
||||
var y = Blockly.Arduino.valueToCode(this, 'Y', Blockly.Arduino.ORDER_ATOMIC) || '0'
|
||||
var radius = Blockly.Arduino.valueToCode(this, 'Radius', Blockly.Arduino.ORDER_ATOMIC) || '0'
|
||||
var fill = this.getFieldValue('FILL');
|
||||
if (fill === 'TRUE') {
|
||||
code = 'display.fillCircle(' + x + ',' + y + ',' + radius + ',1);\n';
|
||||
}
|
||||
else {
|
||||
code = 'display.drawCircle(' + x + ',' + y + ',' + radius + ',1);\n';
|
||||
}
|
||||
return code;
|
||||
}
|
||||
let code = "";
|
||||
var x =
|
||||
Blockly.Arduino.valueToCode(this, "X", Blockly.Arduino.ORDER_ATOMIC) || "0";
|
||||
var y =
|
||||
Blockly.Arduino.valueToCode(this, "Y", Blockly.Arduino.ORDER_ATOMIC) || "0";
|
||||
var radius =
|
||||
Blockly.Arduino.valueToCode(this, "Radius", Blockly.Arduino.ORDER_ATOMIC) ||
|
||||
"0";
|
||||
var fill = this.getFieldValue("FILL");
|
||||
if (fill === "TRUE") {
|
||||
code = "display.fillCircle(" + x + "," + y + "," + radius + ",1);\n";
|
||||
} else {
|
||||
code = "display.drawCircle(" + x + "," + y + "," + radius + ",1);\n";
|
||||
}
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_display_drawRectangle = function () {
|
||||
let code = '';
|
||||
var x = Blockly.Arduino.valueToCode(this, 'X', Blockly.Arduino.ORDER_ATOMIC) || '0'
|
||||
var y = Blockly.Arduino.valueToCode(this, 'Y', Blockly.Arduino.ORDER_ATOMIC) || '0'
|
||||
var width = Blockly.Arduino.valueToCode(this, 'width', Blockly.Arduino.ORDER_ATOMIC) || '0'
|
||||
var height = Blockly.Arduino.valueToCode(this, 'height', Blockly.Arduino.ORDER_ATOMIC) || '0'
|
||||
var fill = this.getFieldValue('FILL');
|
||||
if (fill === 'TRUE') {
|
||||
code = 'display.fillRect(' + x + ',' + y + ',' + width + ',' + height + ',1);\n';
|
||||
}
|
||||
else {
|
||||
code = 'display.drawRect(' + x + ',' + y + ',' + width + ',' + height + ',1);\n';
|
||||
}
|
||||
return code;
|
||||
}
|
||||
let code = "";
|
||||
var x =
|
||||
Blockly.Arduino.valueToCode(this, "X", Blockly.Arduino.ORDER_ATOMIC) || "0";
|
||||
var y =
|
||||
Blockly.Arduino.valueToCode(this, "Y", Blockly.Arduino.ORDER_ATOMIC) || "0";
|
||||
var width =
|
||||
Blockly.Arduino.valueToCode(this, "width", Blockly.Arduino.ORDER_ATOMIC) ||
|
||||
"0";
|
||||
var height =
|
||||
Blockly.Arduino.valueToCode(this, "height", Blockly.Arduino.ORDER_ATOMIC) ||
|
||||
"0";
|
||||
var fill = this.getFieldValue("FILL");
|
||||
if (fill === "TRUE") {
|
||||
code =
|
||||
"display.fillRect(" + x + "," + y + "," + width + "," + height + ",1);\n";
|
||||
} else {
|
||||
code =
|
||||
"display.drawRect(" + x + "," + y + "," + width + "," + height + ",1);\n";
|
||||
}
|
||||
return code;
|
||||
};
|
||||
|
||||
@@ -5,8 +5,7 @@ Blockly.Arduino.sensebox_lora_initialize_otaa = function (block) {
|
||||
var appID = this.getFieldValue("APPID");
|
||||
var appKey = this.getFieldValue("APPKEY");
|
||||
var interval = this.getFieldValue("INTERVAL");
|
||||
Blockly.Arduino.libraries_["library_senseBoxMCU"] =
|
||||
'#include "SenseBoxMCU.h"';
|
||||
Blockly.Arduino.libraries_["library_senseBoxIO"] = "#include <senseBoxIO.h>";
|
||||
Blockly.Arduino.libraries_["library_spi"] = "#include <SPI.h>";
|
||||
Blockly.Arduino.libraries_["library_lmic"] = "#include <lmic.h>";
|
||||
Blockly.Arduino.libraries_["library_hal"] = "#include <hal/hal.h>";
|
||||
@@ -278,8 +277,7 @@ Blockly.Arduino.sensebox_lora_initialize_abp = function (block) {
|
||||
var appskey = this.getFieldValue("APPSKEY");
|
||||
var devaddr = this.getFieldValue("DEVADDR");
|
||||
var interval = this.getFieldValue("INTERVAL");
|
||||
Blockly.Arduino.libraries_["library_senseBoxMCU"] =
|
||||
'#include "SenseBoxMCU.h"';
|
||||
Blockly.Arduino.libraries_["library_senseBoxIO"] = "#include <senseBoxIO.h>";
|
||||
Blockly.Arduino.libraries_["library_spi"] = "#include <SPI.h>";
|
||||
Blockly.Arduino.libraries_["library_lmic"] = "#include <lmic.h>";
|
||||
Blockly.Arduino.libraries_["library_hal"] = "#include <hal/hal.h>";
|
||||
|
||||
@@ -28,7 +28,6 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) {
|
||||
wifi = false;
|
||||
}
|
||||
var box_id = this.getFieldValue("BoxID");
|
||||
var host = this.getFieldValue("host");
|
||||
var branch = Blockly.Arduino.statementToCode(Block, "DO");
|
||||
var access_token = this.getFieldValue("access_token");
|
||||
var blocks = this.getDescendants();
|
||||
@@ -44,8 +43,9 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) {
|
||||
}
|
||||
}
|
||||
var num_sensors = count;
|
||||
Blockly.Arduino.libraries_["library_senseBoxMCU"] =
|
||||
'#include "SenseBoxMCU.h"';
|
||||
Blockly.Arduino.libraries_["library_senseBoxIO"] = "#include <senseBoxIO.h>";
|
||||
Blockly.Arduino.setupCode_["initBearSSL"] =
|
||||
"ArduinoBearSSL.onGetTime(getTime);";
|
||||
Blockly.Arduino.definitions_["num_sensors"] =
|
||||
"static const uint8_t NUM_SENSORS = " + num_sensors + ";";
|
||||
Blockly.Arduino.definitions_["SenseBoxID"] =
|
||||
@@ -68,6 +68,22 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) {
|
||||
Blockly.Arduino.definitions_["EthernetClient"] = "EthernetClient client;";
|
||||
port = 80;
|
||||
}
|
||||
'const char server [] PROGMEM ="ingress.opensensemap.org";';
|
||||
if (ssl === "TRUE") {
|
||||
Blockly.Arduino.libraries_["library_bearSSL"] =
|
||||
"#include <ArduinoBearSSL.h>";
|
||||
Blockly.Arduino.libraries_["library_arduinoECC08"] =
|
||||
"#include <ArduinoECCX08.h>";
|
||||
Blockly.Arduino.definitions_["WiFiClient"] = "WiFiClient wifiClient;";
|
||||
Blockly.Arduino.definitions_["BearSSLClient"] =
|
||||
"BearSSLClient client(wifiClient);";
|
||||
Blockly.Arduino.functionNames_["getTime"] = `unsigned long getTime() {
|
||||
return WiFi.getTime();
|
||||
}`;
|
||||
port = 443;
|
||||
} else if (ssl === "FALSE") {
|
||||
Blockly.Arduino.definitions_["WiFiClient"] = "WiFiClient client;";
|
||||
port = 80;
|
||||
}
|
||||
|
||||
Blockly.Arduino.definitions_["measurement"] = `typedef struct measurement {
|
||||
@@ -141,6 +157,7 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) {
|
||||
}
|
||||
}
|
||||
}`;
|
||||
|
||||
var code = "";
|
||||
code += branch;
|
||||
code += "submitValues();\n";
|
||||
|
||||
@@ -3,8 +3,7 @@ import Blockly from "blockly";
|
||||
Blockly.Arduino.sensebox_rtc_init = function () {
|
||||
Blockly.Arduino.libraries_["RV8523"] = `#include <RV8523.h>`;
|
||||
Blockly.Arduino.definitions_["RTC"] = `RV8523 rtc;`;
|
||||
Blockly.Arduino.libraries_["library_senseBoxMCU"] =
|
||||
'#include "SenseBoxMCU.h"';
|
||||
Blockly.Arduino.libraries_["library_senseBoxIO"] = "#include <senseBoxIO.h>";
|
||||
Blockly.Arduino.setupCode_["rtc.begin"] = `rtc.begin();`;
|
||||
var code = ``;
|
||||
return code;
|
||||
|
||||
@@ -7,11 +7,13 @@ import Blockly from "blockly";
|
||||
|
||||
Blockly.Arduino.sensebox_sensor_temp_hum = function () {
|
||||
var dropdown_name = this.getFieldValue("NAME");
|
||||
Blockly.Arduino.libraries_["library_senseBoxMCU"] =
|
||||
'#include "SenseBoxMCU.h"';
|
||||
Blockly.Arduino.definitions_["define_hdc"] = "HDC1080 hdc;";
|
||||
|
||||
Blockly.Arduino.libraries_["library_adafruithdc1000"] =
|
||||
"#include <Adafruit_HDC1000.h>";
|
||||
Blockly.Arduino.definitions_["define_hdc"] =
|
||||
"Adafruit_HDC1000 hdc = Adafruit_HDC1000();";
|
||||
Blockly.Arduino.setupCode_["sensebox_sensor_temp_hum"] = "hdc.begin();";
|
||||
var code = "hdc.get" + dropdown_name + "()";
|
||||
var code = `hdc.read${dropdown_name}()`;
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
@@ -23,24 +25,102 @@ Blockly.Arduino.sensebox_sensor_temp_hum = function () {
|
||||
Blockly.Arduino.sensebox_sensor_uv_light = function () {
|
||||
var dropdown_name = this.getFieldValue("NAME");
|
||||
let code = "";
|
||||
Blockly.Arduino.libraries_["library_senseBoxMCU"] =
|
||||
'#include "SenseBoxMCU.h"';
|
||||
Blockly.Arduino.libraries_["library_senseBoxIO"] = "#include <senseBoxIO.h>";
|
||||
Blockly.Arduino.libraries_["library_ltr329"] = `#include <LTR329.h>`;
|
||||
if (dropdown_name === "UvIntensity") {
|
||||
Blockly.Arduino.definitions_["define_veml"] = "VEML6070 veml;";
|
||||
Blockly.Arduino.libraries_["library_veml6070"] = "#include <VEML6070.h>";
|
||||
Blockly.Arduino.definitions_["define_veml"] = "VEML6070 veml;;";
|
||||
Blockly.Arduino.setupCode_["sensebox_sensor_uv_light"] = "veml.begin();";
|
||||
code = "veml.get" + dropdown_name + "()";
|
||||
}
|
||||
// if (dropdown_name === 'Illuminance') {
|
||||
// Blockly.Arduino.definitions_['define_tsl'] = 'TSL45315 tsl;'
|
||||
// Blockly.Arduino.setupCode_['sensebox_sensor_illuminance'] = 'tsl.begin();'
|
||||
// code = 'tsl.get' + dropdown_name + '()';
|
||||
// }
|
||||
if (dropdown_name === "Illuminance") {
|
||||
Blockly.Arduino.definitions_["define_lightsensor"] =
|
||||
"Lightsensor lightsensor;";
|
||||
Blockly.Arduino.codeFunctions_["read_reg"] = `
|
||||
int read_reg(byte address, uint8_t reg)
|
||||
{
|
||||
int i = 0;
|
||||
Wire.beginTransmission(address);
|
||||
Wire.write(reg);
|
||||
Wire.endTransmission();
|
||||
Wire.requestFrom((uint8_t)address, (uint8_t)1);
|
||||
delay(1);
|
||||
if(Wire.available())
|
||||
i = Wire.read();
|
||||
return i;
|
||||
}
|
||||
`;
|
||||
Blockly.Arduino.codeFunctions_["write_reg"] = `
|
||||
void write_reg(byte address, uint8_t reg, uint8_t val)
|
||||
{
|
||||
Wire.beginTransmission(address);
|
||||
Wire.write(reg);
|
||||
Wire.write(val);
|
||||
Wire.endTransmission();
|
||||
}`;
|
||||
|
||||
Blockly.Arduino.codeFunctions_["Lightsensor_begin"] = `
|
||||
void Lightsensor_begin()
|
||||
{
|
||||
Wire.begin();
|
||||
unsigned int u = 0;
|
||||
u = read_reg(0x29, 0x80 | 0x0A); //id register
|
||||
if ((u & 0xF0) == 0xA0) // TSL45315
|
||||
{
|
||||
write_reg(0x29, 0x80 | 0x00, 0x03); //control: power on
|
||||
write_reg(0x29, 0x80 | 0x01, 0x02); //config: M=4 T=100ms
|
||||
delay(120);
|
||||
lightsensortype = 0; //TSL45315
|
||||
}
|
||||
else
|
||||
{
|
||||
LTR.begin();
|
||||
LTR.setControl(gain, false, false);
|
||||
LTR.setMeasurementRate(integrationTime, measurementRate);
|
||||
LTR.setPowerUp(); //power on with default settings
|
||||
delay(10); //Wait 10 ms (max) - wakeup time from standby
|
||||
lightsensortype = 1; //
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
Blockly.Arduino.codeFunctions_["Lightsensor_getIlluminance"] = `
|
||||
unsigned int Lightsensor_getIlluminance()
|
||||
{
|
||||
unsigned int lux = 0;
|
||||
if (lightsensortype == 0) // TSL45315
|
||||
{
|
||||
unsigned int u = (read_reg(0x29, 0x80 | 0x04) << 0); //data low
|
||||
u |= (read_reg(0x29, 0x80 | 0x05) << 8); //data high
|
||||
lux = u * 4; // calc lux with M=4 and T=100ms
|
||||
}
|
||||
else if (lightsensortype == 1) //LTR-329ALS-01
|
||||
{
|
||||
delay(100);
|
||||
unsigned int data0, data1;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (LTR.getData(data0, data1)) {
|
||||
if(LTR.getLux(gain, integrationTime, data0, data1, lux));
|
||||
if(lux > 0) break;
|
||||
else delay(10);
|
||||
}
|
||||
else {
|
||||
byte error = LTR.getError();
|
||||
}
|
||||
}
|
||||
}
|
||||
return lux;
|
||||
}
|
||||
`;
|
||||
Blockly.Arduino.definitions_["define_lightsensor"] = `
|
||||
bool lightsensortype = 0; //0 for tsl - 1 for ltr
|
||||
//settings for LTR sensor
|
||||
LTR329 LTR;
|
||||
unsigned char gain = 1;
|
||||
unsigned char integrationTime = 0;
|
||||
unsigned char measurementRate = 3;
|
||||
`;
|
||||
Blockly.Arduino.setupCode_["sensebox_sensor_illuminance"] =
|
||||
"lightsensor.begin();";
|
||||
code = "lightsensor.get" + dropdown_name + "()";
|
||||
"Lightsensor_begin();";
|
||||
code = "Lightsensor_getIlluminance()";
|
||||
}
|
||||
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
@@ -54,8 +134,8 @@ Blockly.Arduino.sensebox_sensor_uv_light = function () {
|
||||
Blockly.Arduino.sensebox_sensor_bmx055_accelerometer = function () {
|
||||
var dropdown_value = this.getFieldValue("VALUE");
|
||||
var range = this.getFieldValue("RANGE");
|
||||
Blockly.Arduino.libraries_["library_senseBoxMCU"] =
|
||||
'#include "SenseBoxMCU.h"';
|
||||
Blockly.Arduino.libraries_["library_senseBoxIO"] = "#include <senseBoxIO.h>";
|
||||
Blockly.Arduino.libraries_["library_bmx055"] = `#include <BMX055.h>`;
|
||||
Blockly.Arduino.definitions_["define_bmx"] = "BMX055 bmx;";
|
||||
Blockly.Arduino.setupCode_["sensebox_sensor_bmx055"] =
|
||||
"bmx.beginAcc(" + range + ");";
|
||||
@@ -71,14 +151,17 @@ Blockly.Arduino.sensebox_sensor_bmx055_accelerometer = function () {
|
||||
Blockly.Arduino.sensebox_sensor_sds011 = function () {
|
||||
var dropdown_name = this.getFieldValue("NAME");
|
||||
var serial_name = this.getFieldValue("SERIAL");
|
||||
Blockly.Arduino.libraries_["library_senseBoxMCU"] =
|
||||
'#include "SenseBoxMCU.h"';
|
||||
Blockly.Arduino.codeFunctions_["define_sds011"] =
|
||||
"SDS011 my_sds(" + serial_name + ");";
|
||||
Blockly.Arduino.variables_["variables_sds011"] = "float p10,p25;\n";
|
||||
Blockly.Arduino.setupCode_["sensebox_sensor_sds011"] =
|
||||
serial_name + ".begin(9600);";
|
||||
var code = "my_sds.get" + dropdown_name + "()";
|
||||
Blockly.Arduino.libraries_["library_senseBoxIO"] = "#include <senseBoxIO.h>";
|
||||
Blockly.Arduino.libraries_["SdsDustSensor"] = `#include "SdsDustSensor.h"`;
|
||||
Blockly.Arduino.definitions_["define_sds011"] =
|
||||
"SdsDustSensor sds(" + serial_name + ");";
|
||||
Blockly.Arduino.setupCode_["sds011_begin"] = "sds.begin();";
|
||||
Blockly.Arduino.setupCode_["sds011_setActiveReporting"] =
|
||||
"sds.setActiveReportingMode();";
|
||||
Blockly.Arduino.loopCodeOnce_[
|
||||
"sds011_getData"
|
||||
] = `PmResult pm = sds.readPm();`;
|
||||
var code = `pm.${dropdown_name}`;
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
@@ -91,14 +174,31 @@ Blockly.Arduino.sensebox_sensor_pressure = function () {
|
||||
var dropdown_name = this.getFieldValue("NAME");
|
||||
var code = "";
|
||||
var referencePressure = this.getFieldValue("referencePressure");
|
||||
Blockly.Arduino.libraries_["library_senseBoxMCU"] =
|
||||
'#include "SenseBoxMCU.h"';
|
||||
Blockly.Arduino.definitions_["define_pressure"] = "BMP280 bmp_sensor;";
|
||||
Blockly.Arduino.setupCode_["sensebox_bmp_sensor"] = "bmp_sensor.begin();";
|
||||
if (dropdown_name === "Pressure" || dropdown_name === "Temperature") {
|
||||
code = "bmp_sensor.get" + dropdown_name + "()";
|
||||
} else if (dropdown_name === "Altitude") {
|
||||
code = "bmp_sensor.getAltitude(" + referencePressure + ")";
|
||||
Blockly.Arduino.libraries_["library_senseBoxIO"] = "#include <senseBoxIO.h>";
|
||||
Blockly.Arduino.libraries_[
|
||||
"adafruit_bmp280"
|
||||
] = `#include <Adafruit_BMP280.h>`;
|
||||
Blockly.Arduino.definitions_["define_pressure"] = "Adafruit_BMP280 bmp;";
|
||||
Blockly.Arduino.setupCode_["sensebox_bmp_sensor"] = "bmp.begin();";
|
||||
Blockly.Arduino.setupCode_["bmp_setSampling"] = `
|
||||
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,
|
||||
Adafruit_BMP280::SAMPLING_X2,
|
||||
Adafruit_BMP280::SAMPLING_X16,
|
||||
Adafruit_BMP280::FILTER_X16,
|
||||
Adafruit_BMP280::STANDBY_MS_500);
|
||||
`;
|
||||
switch (dropdown_name) {
|
||||
case "Temperature":
|
||||
code = "bmp.readTemperature()";
|
||||
break;
|
||||
case "Pressure":
|
||||
code = "bmp.readPressure()/100";
|
||||
break;
|
||||
case "Altitude":
|
||||
code = "bmp.readAltitude(" + referencePressure + ")";
|
||||
break;
|
||||
default:
|
||||
code = "";
|
||||
}
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
};
|
||||
@@ -222,18 +322,19 @@ Blockly.Arduino.sensebox_sensor_ultrasonic_ranger = function () {
|
||||
var dropdown_pin_RX = this.getFieldValue("ultrasonic_trigger");
|
||||
var dropdown_pin_TX = this.getFieldValue("ultrasonic_echo");
|
||||
var port = this.getFieldValue("port");
|
||||
Blockly.Arduino.libraries_["library_senseBoxMCU"] =
|
||||
'#include "SenseBoxMCU.h"';
|
||||
Blockly.Arduino.definitions_["var_ultrasonic" + port] =
|
||||
"Ultrasonic Ultrasonic" +
|
||||
port +
|
||||
"(" +
|
||||
dropdown_pin_RX +
|
||||
"," +
|
||||
dropdown_pin_TX +
|
||||
");";
|
||||
var maxDistance = this.getFieldValue("maxDistance");
|
||||
Blockly.Arduino.libraries_["library_senseBoxIO"] = "#include <senseBoxIO.h>";
|
||||
Blockly.Arduino.libraries_["library_newPing"] = `#include <NewPing.h>`;
|
||||
Blockly.Arduino.variables_["define_newPingVariables" + port] = `
|
||||
#define TRIGGER_PIN_${port} ${dropdown_pin_RX}
|
||||
#define ECHO_PIN_${port} ${dropdown_pin_TX}
|
||||
#define MAX_DISTANCE_${port} ${maxDistance}
|
||||
`;
|
||||
Blockly.Arduino.definitions_[
|
||||
"define_newPing" + port
|
||||
] = `NewPing sonar${port}(TRIGGER_PIN_${port}, ECHO_PIN_${port}, MAX_DISTANCE_${port})`;
|
||||
var code;
|
||||
code = "Ultrasonic" + port + ".getDistance()";
|
||||
code = `sonar${port}.ping_cm()`;
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
@@ -244,11 +345,37 @@ Blockly.Arduino.sensebox_sensor_ultrasonic_ranger = function () {
|
||||
|
||||
Blockly.Arduino.sensebox_sensor_sound = function () {
|
||||
var dropdown_pin = this.getFieldValue("PIN");
|
||||
Blockly.Arduino.libraries_["library_senseBoxMCU"] =
|
||||
'#include "SenseBoxMCU.h"';
|
||||
Blockly.Arduino.definitions_["define_microphone"] =
|
||||
"Microphone microphone(" + dropdown_pin + ");";
|
||||
var code = "microphone.getValue()";
|
||||
Blockly.Arduino.libraries_["library_senseBoxIO"] = "#include <senseBoxIO.h>";
|
||||
Blockly.Arduino.codeFunctions_["define_sound"] = `
|
||||
float getSoundValue(int pin) {
|
||||
unsigned long start = millis(); // Start des Messintervalls
|
||||
unsigned int peakToPeak = 0; // Abstand von maximalem zu minimalem Amplitudenausschlag
|
||||
unsigned int signalMax = 0;
|
||||
unsigned int signalMin = 1023;
|
||||
const int sampleTime = 100;
|
||||
unsigned int micValue;
|
||||
|
||||
// Sammle Daten für 100 Millisekunden
|
||||
while (millis() - start < sampleTime)
|
||||
{
|
||||
micValue = analogRead(pin); // Messe den aktuellen Wert
|
||||
if (micValue < 1023) // sortiere Fehlmessungen aus, deren Werte über dem max Wert 1024 liegen
|
||||
{
|
||||
if (micValue > signalMax)
|
||||
{
|
||||
signalMax = micValue; // speichere den maximal gemessenen Wert
|
||||
}
|
||||
else if (micValue < signalMin)
|
||||
{
|
||||
signalMin = micValue; // speichere den minimal gemessenen Wert
|
||||
}
|
||||
}
|
||||
}
|
||||
peakToPeak = signalMax - signalMin; // max - min = Abstand von maximalem zu minimalem Amplitudenausschlag
|
||||
double volts = (peakToPeak * 5.0) / 1023; // wandle in Volt um
|
||||
return volts;
|
||||
}`;
|
||||
var code = "getSoundValue(" + dropdown_pin + ")";
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
@@ -260,12 +387,14 @@ Blockly.Arduino.sensebox_sensor_sound = function () {
|
||||
Blockly.Arduino.sensebox_button = function () {
|
||||
var dropdown_pin = this.getFieldValue("PIN");
|
||||
var dropown_function = this.getFieldValue("FUNCTION");
|
||||
Blockly.Arduino.libraries_["library_senseBoxMCU"] =
|
||||
'#include "SenseBoxMCU.h"';
|
||||
Blockly.Arduino.libraries_["library_senseBoxIO"] = "#include <senseBoxIO.h>";
|
||||
Blockly.Arduino.libraries_["library_jcButtons"] = `#include <JC_Button.h>`;
|
||||
Blockly.Arduino.definitions_["define_button" + dropdown_pin + ""] =
|
||||
"Button button_" + dropdown_pin + "(" + dropdown_pin + ");";
|
||||
Blockly.Arduino.setupCode_["setup_button" + dropdown_pin + ""] =
|
||||
"button_" + dropdown_pin + ".begin();";
|
||||
Blockly.Arduino.loopCodeOnce_["loop_button" + dropdown_pin + ""] =
|
||||
"button_" + dropdown_pin + ".read();";
|
||||
var code = "";
|
||||
if (dropown_function === "isPressed") {
|
||||
code = "button_" + dropdown_pin + ".isPressed()";
|
||||
@@ -273,6 +402,9 @@ Blockly.Arduino.sensebox_button = function () {
|
||||
code = "button_" + dropdown_pin + ".getSwitch()";
|
||||
} else if (dropown_function === "wasPressed") {
|
||||
code = "button_" + dropdown_pin + ".wasPressed()";
|
||||
} else if (dropown_function === "longPress") {
|
||||
var time = this.getFieldValue("time");
|
||||
code = "button_" + dropdown_pin + ".pressedFor(" + time + ")";
|
||||
}
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
};
|
||||
@@ -284,10 +416,9 @@ Blockly.Arduino.sensebox_button = function () {
|
||||
|
||||
Blockly.Arduino.sensebox_scd30 = function () {
|
||||
var dropdown = this.getFieldValue("dropdown");
|
||||
Blockly.Arduino.libraries_["library_senseBoxIO"] = "#include <senseBoxIO.h>";
|
||||
Blockly.Arduino.libraries_["scd30_library"] =
|
||||
'#include "SparkFun_SCD30_Arduino_Library.h"';
|
||||
Blockly.Arduino.libraries_["library_senseBoxMCU"] =
|
||||
'#include "SenseBoxMCU.h"';
|
||||
Blockly.Arduino.definitions_["SCD30"] = "SCD30 airSensor;";
|
||||
Blockly.Arduino.setupCode_["init_scd30"] = ` Wire.begin();
|
||||
if (airSensor.begin() == false)
|
||||
@@ -319,11 +450,10 @@ Blockly.Arduino.sensebox_scd30 = function () {
|
||||
|
||||
Blockly.Arduino.sensebox_gps = function () {
|
||||
var dropdown = this.getFieldValue("dropdown");
|
||||
Blockly.Arduino.libraries_["library_senseBoxIO"] = "#include <senseBoxIO.h>";
|
||||
Blockly.Arduino.libraries_["gps_library"] =
|
||||
"#include <SparkFun_u-blox_GNSS_Arduino_Library.h>";
|
||||
Blockly.Arduino.libraries_["library_wire"] = "#include <Wire.h>";
|
||||
Blockly.Arduino.libraries_["library_senseBoxMCU"] =
|
||||
'#include "SenseBoxMCU.h"';
|
||||
Blockly.Arduino.definitions_["GPS"] = "SFE_UBLOX_GNSS myGNSS;";
|
||||
Blockly.Arduino.setupCode_["init_gps"] = ` Wire.begin();
|
||||
|
||||
@@ -383,6 +513,7 @@ return tsBuffer;
|
||||
*/
|
||||
|
||||
Blockly.Arduino.sensebox_sensor_truebner_smt50 = function () {
|
||||
Blockly.Arduino.libraries_["library_senseBoxIO"] = "#include <senseBoxIO.h>";
|
||||
var dropdown_port = this.getFieldValue("Port");
|
||||
var dropdown_value = this.getFieldValue("value");
|
||||
var dropdown_pin = 1;
|
||||
@@ -435,6 +566,7 @@ Blockly.Arduino.sensebox_sensor_watertemperature = function () {
|
||||
if (dropdown_port === "C") {
|
||||
dropdown_pin = 5;
|
||||
}
|
||||
Blockly.Arduino.libraries_["library_senseBoxIO"] = "#include <senseBoxIO.h>";
|
||||
Blockly.Arduino.libraries_["library_oneWire"] = '#include "OneWire.h"';
|
||||
Blockly.Arduino.libraries_["library_oneDallasTemperature"] =
|
||||
'#include "DallasTemperature.h"';
|
||||
@@ -488,6 +620,7 @@ float getWindspeed(){
|
||||
*/
|
||||
|
||||
Blockly.Arduino.sensebox_soundsensor_dfrobot = function () {
|
||||
Blockly.Arduino.libraries_["library_senseBoxIO"] = "#include <senseBoxIO.h>";
|
||||
var dropdown_port = this.getFieldValue("Port");
|
||||
var dropdown_pin = 1;
|
||||
if (dropdown_port === "A") {
|
||||
@@ -511,3 +644,42 @@ float getSoundValue(){
|
||||
var code = "getSoundValue()";
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
/**
|
||||
* Infineon DPS310 Pressure Sensor
|
||||
*
|
||||
*/
|
||||
|
||||
Blockly.Arduino.sensebox_sensor_dps310 = function () {
|
||||
var dropdown_name = this.getFieldValue("NAME");
|
||||
var code = "";
|
||||
var referencePressure = this.getFieldValue("referencePressure");
|
||||
Blockly.Arduino.libraries_["library_senseBoxIO"] = "#include <senseBoxIO.h>";
|
||||
Blockly.Arduino.libraries_[
|
||||
"adafruit_dps310"
|
||||
] = `#include <Adafruit_DPS310.h>`;
|
||||
Blockly.Arduino.definitions_["define_dps"] = "Adafruit_DPS310 dps;";
|
||||
Blockly.Arduino.setupCode_["dps_begin"] = "dps.begin_I2C(0x76);";
|
||||
Blockly.Arduino.setupCode_["dps_configuration"] = `
|
||||
dps.configurePressure(DPS310_64HZ, DPS310_64SAMPLES);
|
||||
dps.configureTemperature(DPS310_64HZ, DPS310_64SAMPLES);
|
||||
`;
|
||||
Blockly.Arduino.loopCodeOnce_["dps_events"] =
|
||||
"sensors_event_t temp_event, pressure_event;";
|
||||
Blockly.Arduino.loopCodeOnce_["dps_getEvents"] =
|
||||
"dps.getEvents(&temp_event, &pressure_event);";
|
||||
switch (dropdown_name) {
|
||||
case "Temperature":
|
||||
code = "temp_event.temperature";
|
||||
break;
|
||||
case "Pressure":
|
||||
code = "pressure_event.pressure";
|
||||
break;
|
||||
case "Altitude":
|
||||
code = "dps.readAltitude(" + referencePressure + ")";
|
||||
break;
|
||||
default:
|
||||
code = "";
|
||||
}
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
@@ -1,29 +1,40 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
import * as Blockly from "blockly/core";
|
||||
|
||||
/**
|
||||
* Telegram Bot by re:edu
|
||||
*/
|
||||
Blockly.Arduino.sensebox_telegram = function (Block) {
|
||||
let token = Block.getFieldValue('telegram_token');
|
||||
Blockly['Arduino'].libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"';
|
||||
Blockly['Arduino'].libraries_['library_telegram'] = `#include <UniversalTelegramBot.h>`
|
||||
Blockly['Arduino'].functionNames_['WiFiSSLClient'] = 'WiFiSSLClient client;';
|
||||
Blockly['Arduino'].functionNames_['telegram_objects'] = `#define BOTtoken "${token}" // your Bot Token (Get from Botfather)
|
||||
let token = Block.getFieldValue("telegram_token");
|
||||
Blockly.Arduino.libraries_["library_senseBoxIO"] = "#include <senseBoxIO.h>";
|
||||
Blockly["Arduino"].libraries_[
|
||||
"library_telegram"
|
||||
] = `#include <UniversalTelegramBot.h>`;
|
||||
Blockly["Arduino"].functionNames_["WiFiSSLClient"] = "WiFiSSLClient client;";
|
||||
Blockly["Arduino"].functionNames_[
|
||||
"telegram_objects"
|
||||
] = `#define BOTtoken "${token}" // your Bot Token (Get from Botfather)
|
||||
|
||||
UniversalTelegramBot bot(BOTtoken, client);`
|
||||
UniversalTelegramBot bot(BOTtoken, client);`;
|
||||
|
||||
let code = '';
|
||||
let code = "";
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_telegram_do = function (block) {
|
||||
var messageProcessing = Blockly.Arduino.statementToCode(block, 'telegram_do', Blockly.Arduino.ORDER_ATOMIC);
|
||||
var messageProcessing = Blockly.Arduino.statementToCode(
|
||||
block,
|
||||
"telegram_do",
|
||||
Blockly.Arduino.ORDER_ATOMIC
|
||||
);
|
||||
|
||||
Blockly.Arduino.definitions_['telegram_variables'] = `int Bot_mtbs = 1000; //mean time between scan messages
|
||||
long Bot_lasttime; //last time messages' scan has been done`
|
||||
Blockly.Arduino.definitions_[
|
||||
"telegram_variables"
|
||||
] = `int Bot_mtbs = 1000; //mean time between scan messages
|
||||
long Bot_lasttime; //last time messages' scan has been done`;
|
||||
|
||||
Blockly.Arduino.loopCodeOnce_['sensebox_telegram_loop'] = `if (millis() > Bot_lasttime + Bot_mtbs) {
|
||||
Blockly.Arduino.loopCodeOnce_[
|
||||
"sensebox_telegram_loop"
|
||||
] = `if (millis() > Bot_lasttime + Bot_mtbs) {
|
||||
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
|
||||
while(numNewMessages) {
|
||||
for(int i=0; i<numNewMessages; i++) {
|
||||
@@ -36,13 +47,17 @@ Blockly.Arduino.sensebox_telegram_do = function (block) {
|
||||
}
|
||||
Bot_lasttime = millis();
|
||||
}`;
|
||||
var code = '';
|
||||
var code = "";
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_telegram_do_on_message = function (block) {
|
||||
var message = this.getFieldValue('telegram_message');
|
||||
var stuffToDo = Blockly.Arduino.statementToCode(block, 'telegram_do_on_message', Blockly.Arduino.ORDER_ATOMIC);
|
||||
var message = this.getFieldValue("telegram_message");
|
||||
var stuffToDo = Blockly.Arduino.statementToCode(
|
||||
block,
|
||||
"telegram_do_on_message",
|
||||
Blockly.Arduino.ORDER_ATOMIC
|
||||
);
|
||||
var code = `
|
||||
if (text == "${message}") {
|
||||
${stuffToDo}
|
||||
@@ -51,7 +66,12 @@ Blockly.Arduino.sensebox_telegram_do_on_message = function (block) {
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_telegram_send = function (block) {
|
||||
var textToSend = Blockly.Arduino.valueToCode(this, 'telegram_text_to_send', Blockly.Arduino.ORDER_ATOMIC) || '"Keine Eingabe"';
|
||||
var textToSend =
|
||||
Blockly.Arduino.valueToCode(
|
||||
this,
|
||||
"telegram_text_to_send",
|
||||
Blockly.Arduino.ORDER_ATOMIC
|
||||
) || '"Keine Eingabe"';
|
||||
var code = `bot.sendMessage(chat_id, String(${textToSend}), "");\n`;
|
||||
return code;
|
||||
};
|
||||
|
||||
@@ -4,30 +4,62 @@ import Blockly from "blockly";
|
||||
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();";
|
||||
Blockly.Arduino.libraries_["library_senseBoxIO"] = "#include <senseBoxIO.h>";
|
||||
Blockly.Arduino.libraries_["library_WiFi"] = "#include <WiFi101.h>";
|
||||
Blockly.Arduino.variables_["ssid"] = `char ssid[] = "${ssid}";`;
|
||||
Blockly.Arduino.variables_["pass"] = `char pass[] = "${pw}";`;
|
||||
Blockly.Arduino.variables_["wifi_Status"] = "int status = WL_IDLE_STATUS;";
|
||||
if (pw === "") {
|
||||
Blockly.Arduino.setupCode_["sensebox_network"] =
|
||||
'b->connectToWifi("' + ssid + '");\ndelay(1000);';
|
||||
Blockly.Arduino.setupCode_["wifi_begin"] = `
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
while (true);
|
||||
}
|
||||
while (status != WL_CONNECTED) {
|
||||
status = WiFi.begin(ssid);
|
||||
delay(5000);
|
||||
}
|
||||
`;
|
||||
} else
|
||||
Blockly.Arduino.setupCode_["sensebox_network"] =
|
||||
'b->connectToWifi("' + ssid + '","' + pw + '");\ndelay(1000);';
|
||||
Blockly.Arduino.setupCode_["wifi_begin"] = `
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
while (true);
|
||||
}
|
||||
while (status != WL_CONNECTED) {
|
||||
status = WiFi.begin(ssid, pass);
|
||||
delay(5000);
|
||||
}
|
||||
`;
|
||||
var code = "";
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_wifi_status = function () {
|
||||
var code = "WiFi.status()";
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_wifi_rssi = function () {
|
||||
var code = "WiFi.RSSI();";
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_get_ip = function () {
|
||||
Blockly.Arduino.definitions_["define_ipadress"] = "IPAddress ip;";
|
||||
Blockly.Arduino.setupCode_["sensebox_get_ip"] = " ip = WiFi.localIP(ip);";
|
||||
var code = "";
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
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 + '");';
|
||||
Blockly.Arduino.libraries_["library_senseBoxIO"] = "#include <senseBoxIO.h>";
|
||||
Blockly.Arduino.libraries_["library_WiFi"] = "#include <WiFi101.h>";
|
||||
Blockly.Arduino.setupCode_["wifi_startAP"] = `WiFi.beginAP(${ssid});`;
|
||||
var code = "";
|
||||
return code;
|
||||
};
|
||||
|
||||
|
||||
Blockly.Arduino.sensebox_ethernet = function () {
|
||||
var ip = this.getFieldValue("ip");
|
||||
var gateway = this.getFieldValue("gateway");
|
||||
@@ -79,3 +111,4 @@ Blockly.Arduino.sensebox_ethernetIp = function () {
|
||||
var code = "Ethernet.localIP()";
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import * as Blockly from "blockly/core";
|
||||
|
||||
Blockly.Arduino["print_serial_monitor"] = function (block) {
|
||||
var serialId = block.getFieldValue("SERIAL_ID");
|
||||
var content =
|
||||
Blockly.Arduino.valueToCode(
|
||||
block,
|
||||
"CONTENT",
|
||||
Blockly.Arduino.ORDER_ATOMIC
|
||||
) || "0";
|
||||
var checkbox_name = block.getFieldValue("NEW_LINE") === "TRUE";
|
||||
var code = "";
|
||||
if (checkbox_name) {
|
||||
code = serialId + ".println(" + content + ");\n";
|
||||
} else {
|
||||
code = serialId + ".print(" + content + ");\n";
|
||||
}
|
||||
return code;
|
||||
};
|
||||
|
||||
/**
|
||||
* Code generator for block for setting the serial com speed.
|
||||
* Arduino code: setup{ Serial.begin(X); }
|
||||
* @param {!Blockly.Block} block Block to generate the code from.
|
||||
* @return {array} Completed code.
|
||||
*/
|
||||
Blockly.Arduino["init_serial_monitor"] = function (block) {
|
||||
var serialId = block.getFieldValue("SERIAL_ID");
|
||||
var serialSpeed = block.getFieldValue("SPEED");
|
||||
Blockly.Arduino.setupCode_[
|
||||
"init_serial"
|
||||
] = `${serialId}.begin(${serialSpeed});`;
|
||||
var code = "";
|
||||
return code;
|
||||
};
|
||||
@@ -1,114 +1,134 @@
|
||||
import Blockly from 'blockly';
|
||||
import Blockly from "blockly";
|
||||
/**
|
||||
* Webserver Blocks by Lucas Steinmann
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
Blockly.Arduino.sensebox_initialize_http_server = function (block) {
|
||||
var box_id = this.getFieldValue('Port');
|
||||
Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"';
|
||||
Blockly.Arduino.codeFunctions_['define_wifi_server'] = 'WiFiServer server(' + box_id + ');';
|
||||
Blockly.Arduino.setupCode_['sensebox_wifi_server_beging'] = 'server.begin();';
|
||||
return '';
|
||||
var box_id = this.getFieldValue("Port");
|
||||
Blockly.Arduino.libraries_["library_senseBoxMCU"] =
|
||||
'#include "SenseBoxMCU.h"';
|
||||
Blockly.Arduino.libraries_["library_http"] = "#include .h>";
|
||||
|
||||
Blockly.Arduino.codeFunctions_["define_wifi_server"] =
|
||||
"WiFiServer server(" + box_id + ");";
|
||||
Blockly.Arduino.setupCode_["sensebox_wifi_server_beging"] = "server.begin();";
|
||||
return "";
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_http_on_client_connect = function (block) {
|
||||
var onConnect = Blockly.Arduino.statementToCode(block, 'ON_CONNECT');
|
||||
var code = '';
|
||||
code += 'WiFiClient client = server.available();\n';
|
||||
code += 'if (client && client.available()) {\n';
|
||||
code += ' String request_string = listenClient(client);\n';
|
||||
code += ' Request request;\n';
|
||||
code += ' if (parseRequestSafe(request_string, request)) {\n';
|
||||
code += onConnect;
|
||||
code += ' }\n';
|
||||
code += ' delay(1);\n';
|
||||
code += ' client.stop();\n';
|
||||
code += ' delay(1);\n';
|
||||
code += '}\n';
|
||||
return code;
|
||||
var onConnect = Blockly.Arduino.statementToCode(block, "ON_CONNECT");
|
||||
var code = "";
|
||||
code += "WiFiClient client = server.available();\n";
|
||||
code += "if (client && client.available()) {\n";
|
||||
code += " String request_string = listenClient(client);\n";
|
||||
code += " Request request;\n";
|
||||
code += " if (parseRequestSafe(request_string, request)) {\n";
|
||||
code += onConnect;
|
||||
code += " }\n";
|
||||
code += " delay(1);\n";
|
||||
code += " client.stop();\n";
|
||||
code += " delay(1);\n";
|
||||
code += "}\n";
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_http_method = function (block) {
|
||||
var code = "request.method";
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
var code = "request.method";
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
|
||||
Blockly.Arduino.sensebox_http_uri = function (block) {
|
||||
var code = "request.uri";
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
var code = "request.uri";
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_http_protocol_version = function (block) {
|
||||
var code = "request.protocol_version";
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
var code = "request.protocol_version";
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_http_user_agent = function (block) {
|
||||
var code = "request.user_agent";
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
var code = "request.user_agent";
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_generate_html_doc = function (block) {
|
||||
var header = Blockly.Arduino.valueToCode(block, 'HEADER', Blockly.Arduino.ORDER_NONE) || '""';
|
||||
var body = Blockly.Arduino.valueToCode(block, 'BODY', Blockly.Arduino.ORDER_NONE) || '""';
|
||||
var code = 'buildHTML(' + header + ', ' + body + ')';
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
var header =
|
||||
Blockly.Arduino.valueToCode(block, "HEADER", Blockly.Arduino.ORDER_NONE) ||
|
||||
'""';
|
||||
var body =
|
||||
Blockly.Arduino.valueToCode(block, "BODY", Blockly.Arduino.ORDER_NONE) ||
|
||||
'""';
|
||||
var code = "buildHTML(" + header + ", " + body + ")";
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_generate_http_succesful_response = function (block) {
|
||||
var content = Blockly.Arduino.valueToCode(block, 'CONTENT', Blockly.Arduino.ORDER_NONE) || '""';
|
||||
var code = 'client.println(buildSuccessfulResponse(request, ' + content + '));\n';
|
||||
return code;
|
||||
var content =
|
||||
Blockly.Arduino.valueToCode(block, "CONTENT", Blockly.Arduino.ORDER_NONE) ||
|
||||
'""';
|
||||
var code =
|
||||
"client.println(buildSuccessfulResponse(request, " + content + "));\n";
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_generate_http_not_found_response = function (block) {
|
||||
var code = 'client.println(buildNotFoundResponse(request));\n';
|
||||
return code;
|
||||
var code = "client.println(buildNotFoundResponse(request));\n";
|
||||
return code;
|
||||
};
|
||||
|
||||
|
||||
Blockly.Arduino.sensebox_ip_address = function (block) {
|
||||
var code = "b->getIpAddress()";
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
var code = "b->getIpAddress()";
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_general_html_tag = function (block) {
|
||||
var tag = this.getFieldValue('TAG');
|
||||
var code = 'buildTag("' + tag + '",';
|
||||
var n = 0;
|
||||
var branch = Blockly.Arduino.valueToCode(block, 'DO' + n, Blockly.Arduino.ORDER_NONE);
|
||||
if (branch.length > 0) {
|
||||
code += '\n ' + branch;
|
||||
} else {
|
||||
code += '""';
|
||||
}
|
||||
for (n = 1; n <= block.additionalChildCount_; n++) {
|
||||
branch = Blockly.Arduino.valueToCode(block, 'DO' + n, Blockly.Arduino.ORDER_NONE);
|
||||
code += ' +' + branch;
|
||||
}
|
||||
return [code + ')', Blockly.Arduino.ORDER_ATOMIC];
|
||||
var tag = this.getFieldValue("TAG");
|
||||
var code = 'buildTag("' + tag + '",';
|
||||
var n = 0;
|
||||
var branch = Blockly.Arduino.valueToCode(
|
||||
block,
|
||||
"DO" + n,
|
||||
Blockly.Arduino.ORDER_NONE
|
||||
);
|
||||
if (branch.length > 0) {
|
||||
code += "\n " + branch;
|
||||
} else {
|
||||
code += '""';
|
||||
}
|
||||
for (n = 1; n <= block.additionalChildCount_; n++) {
|
||||
branch = Blockly.Arduino.valueToCode(
|
||||
block,
|
||||
"DO" + n,
|
||||
Blockly.Arduino.ORDER_NONE
|
||||
);
|
||||
code += " +" + branch;
|
||||
}
|
||||
return [code + ")", Blockly.Arduino.ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_web_readHTML = function (block) {
|
||||
var filename = this.getFieldValue('FILENAME');
|
||||
Blockly.Arduino.libraries_['library_spi'] = '#include <SPI.h>';
|
||||
Blockly.Arduino.libraries_['library_sd'] = '#include <SD.h>';
|
||||
Blockly.Arduino.codeFunctions_['define_sd' + filename] = 'File webFile;';
|
||||
Blockly.Arduino.setupCode_['sensebox_sd'] = 'SD.begin(28);';
|
||||
var func = [
|
||||
'String generateHTML(){',
|
||||
' webFile = SD.open("' + filename + '", FILE_READ);',
|
||||
' String finalString ="";',
|
||||
' while (webFile.available())',
|
||||
' {',
|
||||
' finalString+=(char)webFile.read();',
|
||||
' }',
|
||||
' return finalString;',
|
||||
'}'];
|
||||
var functionName = Blockly.Arduino.addFunction(
|
||||
'generateHTML', func.join('\n'));
|
||||
var code = functionName + '()';
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
};
|
||||
var filename = this.getFieldValue("FILENAME");
|
||||
Blockly.Arduino.libraries_["library_spi"] = "#include <SPI.h>";
|
||||
Blockly.Arduino.libraries_["library_sd"] = "#include <SD.h>";
|
||||
Blockly.Arduino.codeFunctions_["define_sd" + filename] = "File webFile;";
|
||||
Blockly.Arduino.setupCode_["sensebox_sd"] = "SD.begin(28);";
|
||||
var func = [
|
||||
"String generateHTML(){",
|
||||
' webFile = SD.open("' + filename + '", FILE_READ);',
|
||||
' String finalString ="";',
|
||||
" while (webFile.available())",
|
||||
" {",
|
||||
" finalString+=(char)webFile.read();",
|
||||
" }",
|
||||
" return finalString;",
|
||||
"}",
|
||||
];
|
||||
var functionName = Blockly.Arduino.addFunction(
|
||||
"generateHTML",
|
||||
func.join("\n")
|
||||
);
|
||||
var code = functionName + "()";
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user