update gps code
make gps blocks to osem block compatible
This commit is contained in:
@@ -1,66 +1,74 @@
|
||||
import Blockly from 'blockly';
|
||||
|
||||
import Blockly from "blockly";
|
||||
|
||||
/**
|
||||
* Block send Data to the openSenseMap
|
||||
*/
|
||||
* Block send Data to the openSenseMap
|
||||
*/
|
||||
Blockly.Arduino.sensebox_send_to_osem = function (block) {
|
||||
var code = '';
|
||||
var sensor_id = this.getFieldValue('SensorID');
|
||||
var code = "";
|
||||
var sensor_id = this.getFieldValue("SensorID");
|
||||
var id = sensor_id.slice(-3).toUpperCase();
|
||||
var sensor_value = Blockly.Arduino.valueToCode(this, 'Value', Blockly.Arduino.ORDER_ATOMIC) || '"Keine Eingabe"';
|
||||
Blockly.Arduino.definitions_['SENSOR_ID' + id + ''] = 'const char SENSOR_ID' + id + '[] PROGMEM = "' + sensor_id + '";';
|
||||
code += 'addMeasurement(SENSOR_ID' + id + ',' + sensor_value + ');\n';
|
||||
var sensor_value =
|
||||
Blockly.Arduino.valueToCode(this, "Value", Blockly.Arduino.ORDER_ATOMIC) ||
|
||||
'"Keine Eingabe"';
|
||||
Blockly.Arduino.definitions_["SENSOR_ID" + id + ""] =
|
||||
"const char SENSOR_ID" + id + '[] PROGMEM = "' + sensor_id + '";';
|
||||
code += "addMeasurement(SENSOR_ID" + id + "," + sensor_value + ");\n";
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_osem_connection = function (Block) {
|
||||
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 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();
|
||||
var type = this.getFieldValue('type');
|
||||
var ssl = this.getFieldValue('SSL');
|
||||
var type = this.getFieldValue("type");
|
||||
var ssl = this.getFieldValue("SSL");
|
||||
var port = 0;
|
||||
var count = 0;
|
||||
if (blocks !== undefined) {
|
||||
for (var i = 0; i < blocks.length; i++) {
|
||||
if (blocks[i].type === 'sensebox_send_to_osem') {
|
||||
if (blocks[i].type === "sensebox_send_to_osem") {
|
||||
count++;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
var num_sensors = count;
|
||||
Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"';
|
||||
Blockly.Arduino.definitions_['num_sensors'] = 'static const uint8_t NUM_SENSORS = ' + num_sensors + ';'
|
||||
Blockly.Arduino.definitions_['SenseBoxID'] = '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;';
|
||||
Blockly.Arduino.libraries_["library_senseBoxMCU"] =
|
||||
'#include "SenseBoxMCU.h"';
|
||||
Blockly.Arduino.definitions_["num_sensors"] =
|
||||
"static const uint8_t NUM_SENSORS = " + num_sensors + ";";
|
||||
Blockly.Arduino.definitions_["SenseBoxID"] =
|
||||
'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;';
|
||||
} else if (ssl === "FALSE") {
|
||||
Blockly.Arduino.definitions_["WiFiClient"] = "WiFiClient client;";
|
||||
port = 80;
|
||||
}
|
||||
|
||||
Blockly.Arduino.definitions_['measurement'] = `typedef struct measurement {
|
||||
Blockly.Arduino.definitions_["measurement"] = `typedef struct measurement {
|
||||
const char *sensorId;
|
||||
float value;
|
||||
} measurement;`;
|
||||
Blockly.Arduino.definitions_['buffer'] = 'char buffer[750];';
|
||||
Blockly.Arduino.definitions_['num_measurement'] = `measurement measurements[NUM_SENSORS];
|
||||
Blockly.Arduino.definitions_["buffer"] = "char buffer[750];";
|
||||
Blockly.Arduino.definitions_[
|
||||
"num_measurement"
|
||||
] = `measurement measurements[NUM_SENSORS];
|
||||
uint8_t num_measurements = 0;`;
|
||||
Blockly.Arduino.definitions_['lengthMultiplikator'] = 'const int lengthMultiplikator = 35;';
|
||||
Blockly.Arduino.functionNames_['addMeasurement'] = `
|
||||
Blockly.Arduino.definitions_["lengthMultiplikator"] =
|
||||
"const int lengthMultiplikator = 35;";
|
||||
Blockly.Arduino.functionNames_["addMeasurement"] = `
|
||||
void addMeasurement(const char *sensorId, float value) {
|
||||
measurements[num_measurements].sensorId = sensorId;
|
||||
measurements[num_measurements].value = value;
|
||||
num_measurements++;
|
||||
}`;
|
||||
if (type === 'Stationary') {
|
||||
Blockly.Arduino.functionNames_['writeMeasurementsToClient'] = `
|
||||
if (type === "Stationary") {
|
||||
Blockly.Arduino.functionNames_["writeMeasurementsToClient"] = `
|
||||
void writeMeasurementsToClient() {
|
||||
// iterate throug the measurements array
|
||||
for (uint8_t i = 0; i < num_measurements; i++) {
|
||||
@@ -72,7 +80,8 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) {
|
||||
// reset num_measurements
|
||||
num_measurements = 0;
|
||||
}`;
|
||||
Blockly.Arduino.functionNames_['submitValues'] = `
|
||||
Blockly.Arduino.functionNames_["submitValues"] =
|
||||
`
|
||||
void submitValues() {
|
||||
if (client.connected()) {
|
||||
client.stop();
|
||||
@@ -83,7 +92,9 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) {
|
||||
strcpy_P(_server, server);
|
||||
for (uint8_t timeout = 2; timeout != 0; timeout--) {
|
||||
Serial.println(F("connecting..."));
|
||||
connected = client.connect(_server, `+ port + `);
|
||||
connected = client.connect(_server, ` +
|
||||
port +
|
||||
`);
|
||||
if (connected == true) {
|
||||
// construct the HTTP POST request:
|
||||
sprintf_P(buffer,
|
||||
@@ -110,17 +121,33 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) {
|
||||
}
|
||||
}
|
||||
}`;
|
||||
var code = '';
|
||||
var code = "";
|
||||
code += branch;
|
||||
code += "submitValues();\n";
|
||||
}
|
||||
else if (type === 'Mobile') {
|
||||
var lat = Blockly.Arduino.valueToCode(Block, 'lat', Blockly.Arduino.ORDER_ATOMIC);
|
||||
var lng = Blockly.Arduino.valueToCode(Block, 'lng', Blockly.Arduino.ORDER_ATOMIC);
|
||||
var timestamp = Blockly.Arduino.valueToCode(Block, 'timeStamp', Blockly.Arduino.ORDER_ATOMIC);
|
||||
var altitude = Blockly.Arduino.valueToCode(Block, 'altitude', Blockly.Arduino.ORDER_ATOMIC);
|
||||
Blockly.Arduino.definitions_['lengthMultiplikator'] = 'const int lengthMultiplikator = 77;';
|
||||
Blockly.Arduino.functionNames_['writeMeasurementsToClient'] = `
|
||||
} else if (type === "Mobile") {
|
||||
var lat = Blockly.Arduino.valueToCode(
|
||||
Block,
|
||||
"lat",
|
||||
Blockly.Arduino.ORDER_ATOMIC
|
||||
);
|
||||
var lng = Blockly.Arduino.valueToCode(
|
||||
Block,
|
||||
"lng",
|
||||
Blockly.Arduino.ORDER_ATOMIC
|
||||
);
|
||||
var timestamp = Blockly.Arduino.valueToCode(
|
||||
Block,
|
||||
"timeStamp",
|
||||
Blockly.Arduino.ORDER_ATOMIC
|
||||
);
|
||||
var altitude = Blockly.Arduino.valueToCode(
|
||||
Block,
|
||||
"altitude",
|
||||
Blockly.Arduino.ORDER_ATOMIC
|
||||
);
|
||||
Blockly.Arduino.definitions_["lengthMultiplikator"] =
|
||||
"const int lengthMultiplikator = 77;";
|
||||
Blockly.Arduino.functionNames_["writeMeasurementsToClient"] = `
|
||||
void writeMeasurementsToClient(float lat, float lng, float altitude, char* timeStamp) {
|
||||
// iterate throug the measurements array
|
||||
for (uint8_t i = 0; i < num_measurements; i++) {
|
||||
@@ -132,7 +159,10 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) {
|
||||
// reset num_measurements
|
||||
num_measurements = 0;
|
||||
}`;
|
||||
Blockly.Arduino.functionNames_['submitValues'] = `
|
||||
Blockly.Arduino.variables_["latitude"] = "float latitude;";
|
||||
Blockly.Arduino.variables_["longitude"] = "float longitude;";
|
||||
Blockly.Arduino.functionNames_["submitValues"] =
|
||||
`
|
||||
void submitValues(float lat, float lng, float altitude, char* timeStamp) {
|
||||
if (client.connected()) {
|
||||
client.stop();
|
||||
@@ -143,7 +173,9 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) {
|
||||
strcpy_P(_server, server);
|
||||
for (uint8_t timeout = 2; timeout != 0; timeout--) {
|
||||
Serial.println(F("connecting..."));
|
||||
connected = client.connect(_server, `+ port + `);
|
||||
connected = client.connect(_server, ` +
|
||||
port +
|
||||
`);
|
||||
if (connected == true) {
|
||||
// construct the HTTP POST request:
|
||||
sprintf_P(buffer,
|
||||
@@ -170,10 +202,19 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}`
|
||||
code = '';
|
||||
}`;
|
||||
code = "";
|
||||
code += branch;
|
||||
code += 'submitValues(' + lat + ',' + lng + ',' + altitude + ',' + timestamp + ');\n';
|
||||
code +=
|
||||
"submitValues((" +
|
||||
lat +
|
||||
"/float(10000000)),(" +
|
||||
lng +
|
||||
"/float(10000000),(" +
|
||||
altitude +
|
||||
"/float(100))," +
|
||||
timestamp +
|
||||
");\n";
|
||||
}
|
||||
return code;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user