initial gps ttn mapper code
This commit is contained in:
@@ -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];
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user