initial gps ttn mapper code
This commit is contained in:
@@ -119,6 +119,33 @@ Blockly.Blocks['sensebox_send_lora_sensor_value'] = {
|
||||
LOOP_TYPES: ['sensebox_lora_message_send'],
|
||||
};
|
||||
|
||||
Blockly.Blocks['sensebox_lora_ttn_mapper'] = {
|
||||
init: function (block) {
|
||||
this.setColour(getColour().sensebox);
|
||||
this.appendDummyInput()
|
||||
.appendField("TTN Mapper")
|
||||
this.appendValueInput('Latitude')
|
||||
.appendField('Latitude')
|
||||
.setCheck(null);
|
||||
this.appendValueInput('Longitude')
|
||||
.appendField('Longitude')
|
||||
.setCheck(null);
|
||||
this.appendValueInput('Altitude')
|
||||
.appendField('Altitude')
|
||||
.setCheck(null);
|
||||
this.appendValueInput('pDOP')
|
||||
.appendField('pDOP')
|
||||
.setCheck(null);
|
||||
this.appendValueInput('Fix Type')
|
||||
.appendField('Fix Type')
|
||||
.setCheck(null);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip(Blockly.Msg.senseBox_display_printDisplay_tip);
|
||||
this.setHelpUrl('https://sensebox.de/books');
|
||||
}
|
||||
};
|
||||
|
||||
Blockly.Blocks['sensebox_lora_cayenne_send'] = {
|
||||
init: function () {
|
||||
this.setTooltip(Blockly.Msg.senseBox_LoRa_cayenne_tip);
|
||||
|
||||
@@ -321,3 +321,25 @@ Blockly.Blocks['sensebox_scd30'] = {
|
||||
this.setTooltip(Blockly.Msg.senseBox_bme_tip);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* GPS Module
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
Blockly.Blocks['sensebox_gps'] = {
|
||||
init: function () {
|
||||
var dropdownOptions = [["Latitude", "latitude"], ["Longitude", "longitude"], ["Altitude", "altitude"], ["pDOP", "pDOP"], ["Fix Type", "fixType"]];
|
||||
this.appendDummyInput()
|
||||
.appendField("GPS Modul");
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.ALIGN_RIGHT)
|
||||
.appendField(Blockly.Msg.senseBox_value)
|
||||
.appendField(new Blockly.FieldDropdown(dropdownOptions), "dropdown")
|
||||
this.setOutput(true, Types.NUMBER.typeName);
|
||||
this.setColour(getColour().sensebox);
|
||||
this.setTooltip(Blockly.Msg.senseBox_bme_tip);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -195,6 +195,59 @@ Blockly.Arduino.sensebox_lora_cayenne_send = function (block) {
|
||||
return '';
|
||||
}
|
||||
|
||||
Blockly.Arduino.sensebox_lora_ttn_mapper = function (block) {
|
||||
var latitude = Blockly.Arduino.valueToCode(this, 'Latitude', Blockly.Arduino.ORDER_ATOMIC)
|
||||
var longitude = Blockly.Arduino.valueToCode(this, 'Longitude', Blockly.Arduino.ORDER_ATOMIC)
|
||||
var altitude = Blockly.Arduino.valueToCode(this, 'Altitude', Blockly.Arduino.ORDER_ATOMIC)
|
||||
var pDOP = Blockly.Arduino.valueToCode(this, 'pDOP', Blockly.Arduino.ORDER_ATOMIC)
|
||||
var fixType = Blockly.Arduino.valueToCode(this, 'Fix Type', Blockly.Arduino.ORDER_ATOMIC)
|
||||
Blockly.Arduino.functionNames_['functions_do_send'] = `
|
||||
void do_send(osjob_t* j){
|
||||
// Check if there is not a current TX/RX job running
|
||||
if (LMIC.opmode & OP_TXRXPEND) {
|
||||
Serial.println(F("OP_TXRXPEND, not sending"));
|
||||
} else {
|
||||
|
||||
int fixType = ${fixType};
|
||||
if (fixType >= 3) { // we have a 3D fix
|
||||
int32_t latitude = ${latitude}; // in degrees * 10^-7
|
||||
int32_t longitude = ${longitude}; // in degrees * 10^-7
|
||||
int32_t altitude = ${altitude} / 100; // in dm above mean sea level
|
||||
uint16_t pDOP = ${pDOP}; // positional dillution of precision
|
||||
|
||||
uint8_t data[12];
|
||||
|
||||
data[0] = latitude;
|
||||
data[1] = latitude >> 8;
|
||||
data[2] = latitude >> 16;
|
||||
data[3] = latitude >> 24;
|
||||
|
||||
data[4] = longitude;
|
||||
data[5] = longitude >> 8;
|
||||
data[6] = longitude >> 16;
|
||||
data[7] = longitude >> 24;
|
||||
|
||||
data[8] = altitude;
|
||||
data[9] = altitude >> 8;
|
||||
|
||||
data[10] = pDOP;
|
||||
data[11] = pDOP >> 8;
|
||||
|
||||
|
||||
// Prepare upstream data transmission at the next possible time.
|
||||
LMIC_setTxData2(1, data, sizeof(data), 0);
|
||||
Serial.println(F("Packet queued"));
|
||||
} else {
|
||||
// wait for better fix type
|
||||
os_setTimedCallback(&sendjob, os_getTime() + sec2osticks(TX_INTERVAL), do_send);
|
||||
}
|
||||
}
|
||||
// Next TX is scheduled after TX_COMPLETE event.
|
||||
}`;
|
||||
Blockly.Arduino.loopCodeOnce_['os_runloop'] = 'os_runloop_once();'
|
||||
return '';
|
||||
}
|
||||
|
||||
Blockly.Arduino.sensebox_lora_initialize_abp = function (block) {
|
||||
var nwskey = this.getFieldValue('NWSKEY');
|
||||
var appskey = this.getFieldValue('APPSKEY');
|
||||
|
||||
@@ -295,4 +295,50 @@ Blockly.Arduino.sensebox_scd30 = function () {
|
||||
}
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* GPS Module
|
||||
*
|
||||
*/
|
||||
|
||||
Blockly.Arduino.sensebox_gps = function () {
|
||||
var dropdown = this.getFieldValue('dropdown');
|
||||
Blockly.Arduino.libraries_['gps_library'] = '#include "SparkFun_Ublox_Arduino_Library.h"'
|
||||
Blockly.Arduino.libraries_['wire'] = '#include <Wire.h>'
|
||||
Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"';
|
||||
Blockly.Arduino.definitions_['GPS'] = 'SFE_UBLOX_GPS myGPS;';
|
||||
Blockly.Arduino.setupCode_['init_gps'] = ` Wire.begin();
|
||||
|
||||
if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
|
||||
{
|
||||
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
|
||||
while (1);
|
||||
}
|
||||
|
||||
myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
|
||||
myGPS.saveConfiguration(); //Save the current settings to flash and BBR`;
|
||||
var code = '';
|
||||
switch (dropdown) {
|
||||
case 'latitude':
|
||||
code = 'myGPS.getLatitude()';
|
||||
break;
|
||||
case 'longitude':
|
||||
code = 'myGPS.getLongitude()';
|
||||
break;
|
||||
case 'altitude':
|
||||
code = 'myGPS.getAltitudeMSL()';
|
||||
break;
|
||||
case 'pDOP':
|
||||
code = 'myGPS.getPDOP()';
|
||||
break;
|
||||
case 'fixType':
|
||||
code = 'myGPS.getFixType()';
|
||||
break;
|
||||
default:
|
||||
code = ''
|
||||
}
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
|
||||
}
|
||||
@@ -46,6 +46,7 @@ class Toolbox extends React.Component {
|
||||
<Block type="sensebox_sensor_pressure" />
|
||||
<Block type="sensebox_sensor_bme680_bsec" />
|
||||
<Block type="sensebox_scd30" />
|
||||
<Block type="sensebox_gps" />
|
||||
<Block type="sensebox_sensor_ultrasonic_ranger" />
|
||||
<Block type="sensebox_sensor_sound" />
|
||||
<Block type="sensebox_button" />
|
||||
@@ -241,6 +242,9 @@ class Toolbox extends React.Component {
|
||||
<Block type="sensebox_lora_message_send" />
|
||||
<Block type="sensebox_send_lora_sensor_value" />
|
||||
</Category>
|
||||
<Category id="catSenseBoxOutput_Map" name=" TTN Mapper" colour={getColour().sensebox}>
|
||||
<Block type="sensebox_lora_ttn_mapper" />
|
||||
</Category>
|
||||
<Category id="catSenseBoxOutput_LoRa_cayenne" name=" Cayenne LPP" colour={getColour().sensebox}>
|
||||
<Block type="sensebox_lora_cayenne_send" />
|
||||
<Block type="sensebox_lora_cayenne_temperature" />
|
||||
|
||||
Reference in New Issue
Block a user