diff --git a/Example/LoRaWAN/examples/TrackerD/GPS.cpp b/Example/LoRaWAN/examples/TrackerD/GPS.cpp index bc9541b..337b35d 100644 --- a/Example/LoRaWAN/examples/TrackerD/GPS.cpp +++ b/Example/LoRaWAN/examples/TrackerD/GPS.cpp @@ -46,6 +46,7 @@ bool GPS_DATA(void) { while (SerialGPS.available() > 0) { + //Serial.println("Inside GPS_data and Serial.GPS > 0"); if (gps.encode(SerialGPS.read())) { // Every time anything is updated, print everything. @@ -92,6 +93,7 @@ bool GPS_DATA(void) if((sys.pdop_value>=sensor.pdop_gps)&&(sensor.pdop_gps!=0.0)&&(sensor.Fix_Status == 3)) // if((sys.pdop_value>=sensor.pdop_gps)&&(sensor.pdop_gps!=0.0)) { + // Valid GPS data, prepare uplink String latitude_string , longitiude_string,year_string,month_string,day_string,hour_string,minute_string,second_string; latitude = gps.location.lat(); sensor.latitude = (int)(latitude*1000000); @@ -133,10 +135,10 @@ bool GPS_DATA(void) sys.gps_data_buff[i++] = (sensor.bat) & 0xFF; } -// sys.gps_data_Weite(); -// Serial.printf("addr_gps_write:%d\r\n",sys.addr_gps_write); -// sys.read_gps_data_on_flash(); -// Serial.printf("addr_gps_read:%d\r\n",sys.addr_gps_read); + // sys.gps_data_Weite(); + // Serial.printf("addr_gps_write:%d\r\n",sys.addr_gps_write); + // sys.read_gps_data_on_flash(); + // Serial.printf("addr_gps_read:%d\r\n",sys.addr_gps_read); if(sys.lon == 1) { if(sys.sensor_type == 22) @@ -172,7 +174,17 @@ bool GPS_DATA(void) digitalWrite(LED_PIN_BLUE, LOW); delay(100); } - } + } + if(sys.fix == 1) + { + // placeholders for gps data will be empty + sensor.latitude = 0; + sensor.longitude = 0; + + Serial.println("No GPS fix, sending placeholder data. 2nd if."); + + return true; + } if (millis() - last > 30000) { last = millis(); @@ -184,6 +196,7 @@ bool GPS_DATA(void) } else { + //Serial.println("Entering else statement ---- GPS.cpp ----"); if(sys.lon == 1) { if(sys.sensor_type == 22) @@ -200,7 +213,18 @@ bool GPS_DATA(void) digitalWrite(LED_PIN_BLUE, LOW); delay(100); } - } + } + // This if statement will only activate when no fix has been found and when sys.fix = 1. + if(sys.fix == 1) + { + // placeholders for gps data will be empty + sensor.latitude = 0; + sensor.longitude = 0; + + Serial.println("No GPS fix, sending placeholder data."); + + return true; + } if (millis() - last > 30000) { last = millis(); diff --git a/Example/LoRaWAN/examples/TrackerD/TrackerD.ino b/Example/LoRaWAN/examples/TrackerD/TrackerD.ino index 56105d3..4defca0 100644 --- a/Example/LoRaWAN/examples/TrackerD/TrackerD.ino +++ b/Example/LoRaWAN/examples/TrackerD/TrackerD.ino @@ -1587,6 +1587,7 @@ void gps_send(void) { if(GPS_DATA() == true ) { + // Serial.println("GPS_DATA = true ---- TrackerD.ino ----"); os_JOINED_flag = 0; sys.gps_work_flag = false; if(sys.Positioning_time != 0) diff --git a/Example/LoRaWAN/examples/TrackerD/at.cpp b/Example/LoRaWAN/examples/TrackerD/at.cpp index cdc5053..50fcda2 100644 --- a/Example/LoRaWAN/examples/TrackerD/at.cpp +++ b/Example/LoRaWAN/examples/TrackerD/at.cpp @@ -543,6 +543,25 @@ ATEerror_t at_lon_set(const char *param) return AT_OK; } +/************** AT_FIX **************/ +ATEerror_t at_fix_get(const char *param) +{ + if(keep) + Serial.print(AT FIX "="); + Serial.println(sys.fix); + return AT_OK; +} +ATEerror_t at_fix_set(const char *param) +{ + uint32_t is_on = atoi(param); + if(is_on >=2) // Has to be 1 or 0 + { + return AT_PARAM_ERROR; + } + sys.fix = is_on; + return AT_OK; +} + /************** AT_INTWK **************/ ATEerror_t at_intwk_get(const char *param) { diff --git a/Example/LoRaWAN/examples/TrackerD/at.h b/Example/LoRaWAN/examples/TrackerD/at.h index ae1026a..a47157c 100644 --- a/Example/LoRaWAN/examples/TrackerD/at.h +++ b/Example/LoRaWAN/examples/TrackerD/at.h @@ -50,6 +50,7 @@ #define DEVICE "+DEVICE" #define PDTA "+PDTA" #define BTDC "+BTDC" +#define FIX "+FIX" typedef enum { AT_OK = 0, @@ -129,6 +130,8 @@ ATEerror_t at_intwk_get(const char *param); ATEerror_t at_intwk_set(const char *param); ATEerror_t at_lon_get(const char *param); ATEerror_t at_lon_set(const char *param); +ATEerror_t at_fix_get(const char *param); +ATEerror_t at_fix_set(const char *param); ATEerror_t at_CHS_get(const char *param); ATEerror_t at_CHS_set(const char *param); ATEerror_t at_CHE_get(const char *param); @@ -418,6 +421,18 @@ static const struct ATCommand_s ATCommand[] = .set = at_lon_set, .run = at_return_error, }, +/**************** AT+FIX ****************/ +{ + .string = AT FIX, + .size_string = sizeof(FIX) - 1, +#ifndef NO_HELP + .help_string = AT FIX " : Enable/Disable Uplink without GPS", +#endif + .get = at_fix_get, + .set = at_fix_set, + .run = at_return_error, +}, + /**************** AT+CHE ****************/ { .string = AT CHE, diff --git a/Example/LoRaWAN/examples/TrackerD/common.cpp b/Example/LoRaWAN/examples/TrackerD/common.cpp index 3dcd0f6..186559f 100644 --- a/Example/LoRaWAN/examples/TrackerD/common.cpp +++ b/Example/LoRaWAN/examples/TrackerD/common.cpp @@ -10,140 +10,141 @@ int channel = 0;//通道号,取值0 ~ 15 int resolution = 8;//计数位数,2的8次幂=256 uint32_t s_config[32] = {0}; -uint8_t config_count = 0; +uint8_t config_count =0; uint32_t s_config1[32] = {0}; -uint8_t config_count1 = 0; +uint8_t config_count1 =0; -uint8_t addr_ble = 0; +uint8_t addr_ble =0; //// Instantiate eeprom objects with parameter/argument names and sizes EEPROMClass KEY("eeprom0"); EEPROMClass DATA("eeprom1"); EEPROMClass GPSDATA("eeprom2"); -SYS::SYS(uint8_t pin_red, uint8_t pin_blue, uint8_t pin_green) +SYS::SYS(uint8_t pin_red,uint8_t pin_blue,uint8_t pin_green) { - pinMode(pin_red, OUTPUT); - pinMode(pin_blue, OUTPUT); - pinMode(pin_green, OUTPUT); - pinMode(BAT_PIN_READ, INPUT); - pinMode(BAT_PIN_LOW, OUTPUT); - // digitalWrite(BAT_PIN_LOW, HIGH); + pinMode(pin_red,OUTPUT); + pinMode(pin_blue,OUTPUT); + pinMode(pin_green,OUTPUT); + pinMode(BAT_PIN_READ,INPUT); + pinMode(BAT_PIN_LOW,OUTPUT); +// digitalWrite(BAT_PIN_LOW, HIGH); } SYS::~SYS(void) { - + } int BatGet(void) { - int bat_i = 0; - float bat_f = 0.0; + + int bat_i=0; + float bat_f =0.0; float batv_f = 0.0; - if ((sys.cdevaddr <= 25692040 && sys.sensor_type == 13) || (sys.sensor_type == 13)) + if((sys.cdevaddr<=25692040)|| (sys.sensor_type == 13)) { - batv_f = 3.30 / 4095 * analogRead(BAT_PIN_READ); - if (batv_f == 3.3) + batv_f = 3.30/4095*analogRead(BAT_PIN_READ); + if(batv_f == 3.3) { - bat_f = 3.46 / 4095 * analogRead(BAT_PIN_READ); - bat_f = bat_f * 570 / 470; + bat_f = 3.46/4095*analogRead(BAT_PIN_READ); + bat_f = bat_f*570/470; } else { - bat_f = batv_f * 570 / 470; + bat_f = batv_f*570/470; } } - else if (sys.sensor_type == 22) + else { - batv_f = 3.30 / 4095 * analogRead(BAT_PIN_READ1); - if (batv_f == 3.3) - { - bat_f = 3.46 / 4095 * analogRead(BAT_PIN_READ1); - bat_f = bat_f * 570 / 470; - } - else - { - bat_f = batv_f * 570 / 470; - } + batv_f = 3.30/4095*analogRead(BAT_PIN_READ1); + if(batv_f == 3.3) + { + bat_f = 3.46/4095*analogRead(BAT_PIN_READ1); + bat_f = bat_f*570/470; + } + else + { + bat_f = batv_f*570/470; + } } - // Serial.printf("BAT:%.2f V\r\n",bat_f); - bat_i = (int)(bat_f * 1000); +// Serial.printf("BAT:%.2f V\r\n",bat_f); + bat_i = (int)(bat_f*1000); return bat_i; } void buzzer(void) { - pinMode(BAT_PIN_LOW, OUTPUT); - // digitalWrite(BAT_PIN_LOW, LOW); - // delay(1000); + pinMode(BAT_PIN_LOW,OUTPUT); +// digitalWrite(BAT_PIN_LOW, LOW); +// delay(1000); digitalWrite(BAT_PIN_LOW, HIGH); ledcSetup(channel, freq, resolution); - ledcAttachPin(BAT_PIN_LOW, channel); + ledcAttachPin(BAT_PIN_LOW, channel); ledcWriteTone(channel, 2000); for (int dutyCycle = 255; dutyCycle <= 255; dutyCycle = dutyCycle + 10) { - // Serial.println(dutyCycle); +// Serial.println(dutyCycle); ledcWrite(channel, dutyCycle); delay(500); - } + } ledcWrite(channel, 125); } void Stop_buzzer(void) { - pinMode(BAT_PIN_LOW, OUTPUT); + pinMode(BAT_PIN_LOW,OUTPUT); freq = 0; ledcSetup(channel, freq, resolution); - ledcAttachPin(BAT_PIN_LOW, channel); + ledcAttachPin(BAT_PIN_LOW, channel); ledcWriteTone(channel, 2000); for (int dutyCycle = 0; dutyCycle <= 0; dutyCycle = dutyCycle ) { - // Serial.println(dutyCycle); +// Serial.println(dutyCycle); ledcWrite(channel, dutyCycle); delay(500); break; - } + } } void device_strcmp(void) { - // Serial.printf("sys.cdevaddr=%d\r\n",sys.cdevaddr); - if ((sys.cdevaddr <= 25692040 && sys.sensor_type == 13)) - { - // Serial.printf("button_event_init\r\n"); + Serial.printf("sys.cdevaddr=%d\r\n",sys.cdevaddr); + if((sys.cdevaddr<=25692040)) + { +// Serial.printf("button_event_init\r\n"); button_event_init(); } - else if (sys.sensor_type == 22 || (sys.cdevaddr > 25692040)) - { - // Serial.printf("button_event_init\r\n"); + else if(sys.sensor_type == 22 || (sys.cdevaddr>25692040)) + { +// Serial.printf("button_event_init\r\n"); button_event_init1(); - } + } } void button_loop(void) { - if ((sys.cdevaddr <= 25692040 && sys.sensor_type == 13) ) + if((sys.cdevaddr<=25692040)) { - // Serial.printf("button_event_init\r\n"); - button_attach_loop(); +// Serial.printf("button_event_init\r\n"); + button_attach_loop(); } - else if (sys.sensor_type == 22 || (sys.cdevaddr > 25692040)) + else if(sys.sensor_type == 22 || (sys.cdevaddr>25692040)) { - // Serial.printf("button_event_init1\r\n"); - button_attach_loop1(); - } +// Serial.printf("button_event_init1\r\n"); + button_attach_loop1(); + } } void gpio_reset(void) { - // gpio_reset_pin((gpio_num_t)0); +// gpio_reset_pin((gpio_num_t)0); gpio_reset_pin((gpio_num_t)2); - // gpio_reset_pin((gpio_num_t)4); - if (sys.GPS_flag == 1 ) - { - gpio_reset_pin((gpio_num_t)12); - } +// gpio_reset_pin((gpio_num_t)4); + if(sys.GPS_flag ==1 ) + { + gpio_reset_pin((gpio_num_t)12); + } gpio_reset_pin((gpio_num_t)13); gpio_reset_pin((gpio_num_t)14); gpio_reset_pin((gpio_num_t)15); @@ -155,14 +156,14 @@ void gpio_reset(void) gpio_reset_pin((gpio_num_t)5); gpio_reset_pin((gpio_num_t)18); gpio_reset_pin((gpio_num_t)19); - - // gpio_pullup_dis((gpio_num_t)0); + +// gpio_pullup_dis((gpio_num_t)0); gpio_pullup_dis((gpio_num_t)2); - // gpio_pullup_dis((gpio_num_t)4); - if (sys.GPS_flag == 1 ) - { - gpio_pullup_dis((gpio_num_t)12); - } +// gpio_pullup_dis((gpio_num_t)4); + if(sys.GPS_flag ==1 ) + { + gpio_pullup_dis((gpio_num_t)12); + } gpio_pullup_dis((gpio_num_t)13); gpio_pullup_dis((gpio_num_t)14); gpio_pullup_dis((gpio_num_t)15); @@ -180,491 +181,441 @@ void Device_status() { uint8_t freq_band; uint16_t version; - + devicet.battrey = BatGet(); - if (sys.sensor_type == 13) + if(sys.sensor_type == 13) { devicet.sensor_type = 0x13; } - else if (sys.sensor_type == 22) + else if(sys.sensor_type == 22) { devicet.sensor_type = 0x22; - } - + } + sys.fire_version = string_touint(); - // Serial.printf("sys.fire_version:%d\r\n",sys.fire_version); - if (sys.fire_version >= 100) +// Serial.printf("sys.fire_version:%d\r\n",sys.fire_version); + if(sys.fire_version>=100) { - version = (sys.fire_version / 100) << 8 | (sys.fire_version / 10 % 10) << 4 | (sys.fire_version % 10); + version=(sys.fire_version/100)<<8|(sys.fire_version/10%10)<<4|(sys.fire_version%10); } else { - version = (sys.fire_version / 10) << 8 | (sys.fire_version % 10) << 4; + version=(sys.fire_version/10)<<8|(sys.fire_version%10)<<4; } devicet.firm_ver = version; - // Serial.printf("devicet.firm_ver:%d\r\n",devicet.firm_ver); -#if defined(CFG_eu868) - freq_band = 0x01; -#elif defined( CFG_us915) - freq_band = 0x02; -#elif defined( CFG_in866 ) - freq_band = 0x03; -#elif defined( CFG_au915 ) - freq_band = 0x04; -#elif defined( CFG_kz865 ) - freq_band = 0x05; -#elif defined( CFG_ru864 ) - freq_band = 0x06; -#elif defined( CFG_as923 ) -#if defined AS923_1 - freq_band = 0x08; -#elif defined AS923_2 - freq_band = 0x09; -#elif defined AS923_3 - freq_band = 0x0A; -#else - freq_band = 0x07; -#endif -#elif defined( CFG_CN470 ) - freq_band = 0x0B; -#elif defined( CFG_EU433 ) - freq_band = 0x0C; -#elif defined( CFG_kr920 ) - freq_band = 0x0D; -#elif defined( CFG_ma869 ) - freq_band = 0x0E; -#else - freq_band = 0x00; -#endif +// Serial.printf("devicet.firm_ver:%d\r\n",devicet.firm_ver); + #if defined(CFG_eu868) + freq_band=0x01; + #elif defined( CFG_us915) + freq_band=0x02; + #elif defined( CFG_in866 ) + freq_band=0x03; + #elif defined( CFG_au915 ) + freq_band=0x04; + #elif defined( CFG_kz865 ) + freq_band=0x05; + #elif defined( CFG_ru864 ) + freq_band=0x06; + #elif defined( CFG_as923 ) + #if defined AS923_1 + freq_band=0x08; + #elif defined AS923_2 + freq_band=0x09; + #elif defined AS923_3 + freq_band=0x0A; + #else + freq_band=0x07; + #endif + #elif defined( CFG_CN470 ) + freq_band=0x0B; + #elif defined( CFG_EU433 ) + freq_band=0x0C; + #elif defined( CFG_kr920 ) + freq_band=0x0D; + #elif defined( CFG_ma869 ) + freq_band=0x0E; + #else + freq_band=0x00; + #endif devicet.freq_band = freq_band; - -#if defined( CFG_us915 ) || defined( CFG_au915 ) - devicet.sub_band = sys.channel_single; -#else + + #if defined( CFG_us915 ) || defined( CFG_au915 ) + devicet.sub_band = sys.channel_single; + #else devicet.sub_band = 0xff; -#endif - - devicet.SMODE = ((sys.sensor_mode << 6) | (sys.mod << 4 ) | sys.ble_mod) & 0xFF; + #endif - devicet.FLAG = ((sys.PNACKmd << 2) | (sys.lon << 1) | sys.Intwk) & 0xFF; + devicet.SMODE = ((sys.sensor_mode <<6)|(sys.mod<<4 )|sys.ble_mod) & 0xFF; + devicet.FLAG = ((sys.PNACKmd<<2)|(sys.lon<<1)|sys.Intwk)&0xFF; + } void ABP_Band_information(void) { -#if defined( CFG_us915 ) || defined( CFG_au915 ) - if( sys.fre<72) - { - // NA-US and AU channels 0-71 are configured automatically - // but only one group of 8 should (a subband) should be active - // TTN recommends the second sub band, 1 in a zero based count. - // We'll disable all 72 channels used by TTN - for (int c = 0; c < 72; c++){ - LMIC_disableChannel(c); - } - // We'll only enable Channel 16 (905.5Mhz) since we're transmitting on a single-channel - LMIC_enableChannel(sys.fre); + #if defined( CFG_us915 ) || defined( CFG_au915 ) + // NA-US and AU channels 0-71 are configured automatically + // but only one group of 8 should (a subband) should be active + // TTN recommends the second sub band, 1 in a zero based count. + // We'll disable all 72 channels used by TTN + for (int c = 0; c < 72; c++){ + LMIC_disableChannel(c); } - else - { - uint8_t single = sys.fre-80; - if(single<8) - { - LMIC_enableSubBand(single); - } + // We'll only enable Channel 16 (905.5Mhz) since we're transmitting on a single-channel + LMIC_enableChannel(sys.fre); + #elif defined( CFG_eu868 ) + // Set up the channels used by the Things Network, which corresponds + // to the defaults of most gateways. Without this, only three base + // channels from the LoRaWAN specification are used, which certainly + // works, so it is good for debugging, but can overload those + // frequencies, so be sure to configure the full frequency range of + // your network here (unless your network autoconfigures them). + // Setting up channels should happen after LMIC_setSession, as that + // configures the minimal channel set. The LMIC doesn't let you change + // the three basic settings, but we show them here. + switch(sys.fre){ + case 0: + LMIC_setupChannel(0, 868100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band +// LMIC_disableChannel(0); + LMIC_disableChannel(1); + LMIC_disableChannel(2); + LMIC_disableChannel(3); + LMIC_disableChannel(4); + LMIC_disableChannel(5); + LMIC_disableChannel(6); + LMIC_disableChannel(7); + LMIC_disableChannel(8); + break; + case 1: + LMIC_setupChannel(1, 868300000, DR_RANGE_MAP(DR_SF12, DR_SF7B), BAND_CENTI); // g-band + LMIC_disableChannel(0); +// LMIC_disableChannel(1); + LMIC_disableChannel(2); + LMIC_disableChannel(3); + LMIC_disableChannel(4); + LMIC_disableChannel(5); + LMIC_disableChannel(6); + LMIC_disableChannel(7); + LMIC_disableChannel(8); + break; + case 2: + LMIC_setupChannel(2, 868500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band + LMIC_disableChannel(0); + LMIC_disableChannel(1); +// LMIC_disableChannel(2); + LMIC_disableChannel(3); + LMIC_disableChannel(4); + LMIC_disableChannel(5); + LMIC_disableChannel(6); + LMIC_disableChannel(7); + LMIC_disableChannel(8); + break; + case 3: + LMIC_setupChannel(3, 867100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band + LMIC_disableChannel(0); + LMIC_disableChannel(1); + LMIC_disableChannel(2); +// LMIC_disableChannel(3); + LMIC_disableChannel(4); + LMIC_disableChannel(5); + LMIC_disableChannel(6); + LMIC_disableChannel(7); + LMIC_disableChannel(8); + break; + case 4: + LMIC_setupChannel(4, 867300000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band + LMIC_disableChannel(0); + LMIC_disableChannel(1); + LMIC_disableChannel(2); + LMIC_disableChannel(3); +// LMIC_disableChannel(4); + LMIC_disableChannel(5); + LMIC_disableChannel(6); + LMIC_disableChannel(7); + LMIC_disableChannel(8); + break; + case 5: + LMIC_setupChannel(5, 867500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band + LMIC_disableChannel(0); + LMIC_disableChannel(1); + LMIC_disableChannel(2); + LMIC_disableChannel(3); + LMIC_disableChannel(4); +// LMIC_disableChannel(5); + LMIC_disableChannel(6); + LMIC_disableChannel(7); + LMIC_disableChannel(8); + break; + case 6: + LMIC_setupChannel(6, 867700000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band + LMIC_disableChannel(0); + LMIC_disableChannel(1); + LMIC_disableChannel(2); + LMIC_disableChannel(3); + LMIC_disableChannel(4); + LMIC_disableChannel(5); +// LMIC_disableChannel(6); + LMIC_disableChannel(7); + LMIC_disableChannel(8); + break; + case 7: + LMIC_setupChannel(7, 867900000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band + LMIC_disableChannel(0); + LMIC_disableChannel(1); + LMIC_disableChannel(2); + LMIC_disableChannel(3); + LMIC_disableChannel(4); + LMIC_disableChannel(5); + LMIC_disableChannel(6); +// LMIC_disableChannel(7); + LMIC_disableChannel(8); + break; + case 8: + LMIC_setupChannel(8, 868800000, DR_RANGE_MAP(DR_FSK, DR_FSK), BAND_MILLI); // g2-band + LMIC_disableChannel(0); + LMIC_disableChannel(1); + LMIC_disableChannel(2); + LMIC_disableChannel(3); + LMIC_disableChannel(4); + LMIC_disableChannel(5); + LMIC_disableChannel(6); + LMIC_disableChannel(7); +// LMIC_disableChannel(8); + break; + default: + break; } -#elif defined( CFG_eu868 ) - // Set up the channels used by the Things Network, which corresponds - // to the defaults of most gateways. Without this, only three base - // channels from the LoRaWAN specification are used, which certainly - // works, so it is good for debugging, but can overload those - // frequencies, so be sure to configure the full frequency range of - // your network here (unless your network autoconfigures them). - // Setting up channels should happen after LMIC_setSession, as that - // configures the minimal channel set. The LMIC doesn't let you change - // the three basic settings, but we show them here. - switch (sys.fre) { - case 1: - LMIC_setupChannel(0, 868100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band - // LMIC_disableChannel(0); - LMIC_disableChannel(1); - LMIC_disableChannel(2); - LMIC_disableChannel(3); - LMIC_disableChannel(4); - LMIC_disableChannel(5); - LMIC_disableChannel(6); - LMIC_disableChannel(7); - LMIC_disableChannel(8); - break; - case 2: - LMIC_setupChannel(1, 868300000, DR_RANGE_MAP(DR_SF12, DR_SF7B), BAND_CENTI); // g-band - LMIC_disableChannel(0); - // LMIC_disableChannel(1); - LMIC_disableChannel(2); - LMIC_disableChannel(3); - LMIC_disableChannel(4); - LMIC_disableChannel(5); - LMIC_disableChannel(6); - LMIC_disableChannel(7); - LMIC_disableChannel(8); - break; - case 3: - LMIC_setupChannel(2, 868500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band - LMIC_disableChannel(0); - LMIC_disableChannel(1); - // LMIC_disableChannel(2); - LMIC_disableChannel(3); - LMIC_disableChannel(4); - LMIC_disableChannel(5); - LMIC_disableChannel(6); - LMIC_disableChannel(7); - LMIC_disableChannel(8); - break; - case 4: - LMIC_setupChannel(3, 867100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band - LMIC_disableChannel(0); - LMIC_disableChannel(1); - LMIC_disableChannel(2); - // LMIC_disableChannel(3); - LMIC_disableChannel(4); - LMIC_disableChannel(5); - LMIC_disableChannel(6); - LMIC_disableChannel(7); - LMIC_disableChannel(8); - break; - case 5: - LMIC_setupChannel(4, 867300000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band - LMIC_disableChannel(0); - LMIC_disableChannel(1); - LMIC_disableChannel(2); - LMIC_disableChannel(3); - // LMIC_disableChannel(4); - LMIC_disableChannel(5); - LMIC_disableChannel(6); - LMIC_disableChannel(7); - LMIC_disableChannel(8); - break; - case 6: - LMIC_setupChannel(5, 867500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band - LMIC_disableChannel(0); - LMIC_disableChannel(1); - LMIC_disableChannel(2); - LMIC_disableChannel(3); - LMIC_disableChannel(4); - // LMIC_disableChannel(5); - LMIC_disableChannel(6); - LMIC_disableChannel(7); - LMIC_disableChannel(8); - break; - case 7: - LMIC_setupChannel(6, 867700000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band - LMIC_disableChannel(0); - LMIC_disableChannel(1); - LMIC_disableChannel(2); - LMIC_disableChannel(3); - LMIC_disableChannel(4); - LMIC_disableChannel(5); - // LMIC_disableChannel(6); - LMIC_disableChannel(7); - LMIC_disableChannel(8); - break; - case 8: - LMIC_setupChannel(7, 867900000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band - LMIC_disableChannel(0); - LMIC_disableChannel(1); - LMIC_disableChannel(2); - LMIC_disableChannel(3); - LMIC_disableChannel(4); - LMIC_disableChannel(5); - LMIC_disableChannel(6); - // LMIC_disableChannel(7); - LMIC_disableChannel(8); - break; - case 9: - LMIC_setupChannel(8, 868800000, DR_RANGE_MAP(DR_FSK, DR_FSK), BAND_MILLI); // g2-band - LMIC_disableChannel(0); - LMIC_disableChannel(1); - LMIC_disableChannel(2); - LMIC_disableChannel(3); - LMIC_disableChannel(4); - LMIC_disableChannel(5); - LMIC_disableChannel(6); - LMIC_disableChannel(7); - // LMIC_disableChannel(8); - break; - default: - LMIC_setupChannel(0, 868100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band - LMIC_setupChannel(1, 868300000, DR_RANGE_MAP(DR_SF12, DR_SF7B), BAND_CENTI); // g-band - LMIC_setupChannel(2, 868500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band - LMIC_disableChannel(2); - LMIC_disableChannel(3); - LMIC_disableChannel(4); - LMIC_disableChannel(5); - LMIC_disableChannel(6); - LMIC_disableChannel(7); - LMIC_disableChannel(8); - break; - } - // TTN defines an additional channel at 869.525Mhz using SF9 for class B - // devices' ping slots. LMIC does not have an easy way to define set this - // frequency and support for class B is spotty and untested, so this - // frequency is not configured here. -#elif defined(CFG_as923) - // Set up the channels used in your country. Only two are defined by default, - // and they cannot be changed. Use BAND_CENTI to indicate 1% duty cycle. -#if defined AS923_1 - switch (sys.fre) { - case 0: - LMIC_setupChannel(0, 923200000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); - LMIC_setupChannel(1, 923400000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); - break; - default: - break; - } -#elif defined AS923_2 - switch (sys.fre) { - case 0: - LMIC_setupChannel(0, 921400000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); - LMIC_setupChannel(1, 921600000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); - - break; - default: - break; - } -#elif defined AS923_3 - switch (sys.fre) { - case 0: - LMIC_setupChannel(0, 916600000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); - LMIC_setupChannel(1, 916800000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); - break; - default: - break; - } -#else defined AS923_4 - switch (sys.fre) { - case 0: - LMIC_setupChannel(0, 917300000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); - LMIC_setupChannel(1, 917500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); - break; - default: - break; - } -#endif - - // ... extra definitions for channels 2..n here -#elif defined(CFG_kr920) - // Set up the channels used in your country. Three are defined by default, - // and they cannot be changed. Duty cycle doesn't matter, but is conventionally - // BAND_MILLI. - switch (sys.fre) { - case 0: - LMIC_setupChannel(0, 922100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI); - break; - case 1: - LMIC_setupChannel(1, 922300000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI); - break; - case 2: - LMIC_setupChannel(2, 922500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI); - break; - default: - break; - } - // ... extra definitions for channels 3..n here. -#elif defined(CFG_in866) - // Set up the channels used in your country. Three are defined by default, - // and they cannot be changed. Duty cycle doesn't matter, but is conventionally - // BAND_MILLI. - switch (sys.fre) { - case 0: - LMIC_setupChannel(0, 865062500, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI); - break; - case 1: - LMIC_setupChannel(1, 865402500, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI); - break; - case 2: - LMIC_setupChannel(2, 865985000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI); - break; - default: - break; - } - // ... extra definitions for channels 3..n here. -#elif defined(CFG_kz865) - // Set up the channels used in your country. Three are defined by default, - // and they cannot be changed. Duty cycle doesn't matter, but is conventionally - // BAND_MILLI. - switch (sys.fre) { - case 0: - LMIC_setupChannel(0, 865100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI); - break; - case 1: - LMIC_setupChannel(1, 865300000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI); - break; - case 2: - LMIC_setupChannel(2, 865500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI); - break; - default: - break; - } - // ... extra definitions for channels 3..n here. -#elif defined(CFG_ma869) - // Set up the channels used in your country. Three are defined by default, - // and they cannot be changed. Duty cycle doesn't matter, but is conventionally - // BAND_MILLI. - switch (sys.fre) { - case 0: - LMIC_setupChannel(0, 869100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI); - break; - case 1: - LMIC_setupChannel(1, 869300000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI); - break; - case 2: - LMIC_setupChannel(2, 869500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI); - break; - default: - break; - } - // ... extra definitions for channels 3..n here. -#elif defined(CFG_ru864) - // Set up the channels used in your country. Only two are defined by default, - // and they cannot be changed. Use BAND_CENTI to indicate 1% duty cycle. - switch (sys.fre) { - case 0: - LMIC_setupChannel(0, 868900000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); - break; - case 1: - LMIC_setupChannel(1, 869100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); - break; - default: - break; - } - // ... extra definitions for channels 2..n here -#else -# error Region not supported -#endif - - LMIC_setLinkCheckMode(0); - if (sys.LORA_GetADR() == ADR_ENABLE) - { - LMIC_setAdrMode(0); - LMIC_setDrTxpow(sys.LORA_GetDR(), sys.LORA_GetTXP()); - } - else - { - sys.LORA_SetDR(LMIC.datarate); - } + // TTN defines an additional channel at 869.525Mhz using SF9 for class B + // devices' ping slots. LMIC does not have an easy way to define set this + // frequency and support for class B is spotty and untested, so this + // frequency is not configured here. + #elif defined(CFG_as923) + // Set up the channels used in your country. Only two are defined by default, + // and they cannot be changed. Use BAND_CENTI to indicate 1% duty cycle. + switch(sys.fre){ + case 0: + LMIC_setupChannel(0, 923200000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); + break; + case 1: + LMIC_setupChannel(1, 923400000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); + break; + default: + break; + } + // ... extra definitions for channels 2..n here + #elif defined(CFG_kr920) + // Set up the channels used in your country. Three are defined by default, + // and they cannot be changed. Duty cycle doesn't matter, but is conventionally + // BAND_MILLI. + switch(sys.fre){ + case 0: + LMIC_setupChannel(0, 922100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI); + break; + case 1: + LMIC_setupChannel(1, 922300000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI); + break; + case 2: + LMIC_setupChannel(2, 922500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI); + break; + default: + break; + } + // ... extra definitions for channels 3..n here. + #elif defined(CFG_in866) + // Set up the channels used in your country. Three are defined by default, + // and they cannot be changed. Duty cycle doesn't matter, but is conventionally + // BAND_MILLI. + switch(sys.fre){ + case 0: + LMIC_setupChannel(0, 865062500, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI); + break; + case 1: + LMIC_setupChannel(1, 865402500, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI); + break; + case 2: + LMIC_setupChannel(2, 865985000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI); + break; + default: + break; + } + // ... extra definitions for channels 3..n here. + #elif defined(CFG_kz865) + // Set up the channels used in your country. Three are defined by default, + // and they cannot be changed. Duty cycle doesn't matter, but is conventionally + // BAND_MILLI. + switch(sys.fre){ + case 0: + LMIC_setupChannel(0, 865100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI); + break; + case 1: + LMIC_setupChannel(1, 865300000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI); + break; + case 2: + LMIC_setupChannel(2, 865500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI); + break; + default: + break; + } + // ... extra definitions for channels 3..n here. + #elif defined(CFG_ma869) + // Set up the channels used in your country. Three are defined by default, + // and they cannot be changed. Duty cycle doesn't matter, but is conventionally + // BAND_MILLI. + switch(sys.fre){ + case 0: + LMIC_setupChannel(0, 869100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI); + break; + case 1: + LMIC_setupChannel(1, 869300000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI); + break; + case 2: + LMIC_setupChannel(2, 869500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI); + break; + default: + break; + } + // ... extra definitions for channels 3..n here. + #elif defined(CFG_ru864) + // Set up the channels used in your country. Only two are defined by default, + // and they cannot be changed. Use BAND_CENTI to indicate 1% duty cycle. + switch(sys.fre){ + case 0: + LMIC_setupChannel(0, 868900000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); + break; + case 1: + LMIC_setupChannel(1, 869100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); + break; + default: + break; + } + // ... extra definitions for channels 2..n here + #else + # error Region not supported + #endif + +// LMIC_setLinkCheckMode(0); +// if(sys.LORA_GetADR() == ADR_ENABLE) +// { +// LMIC_setAdrMode(0); +// LMIC_setDrTxpow(sys.LORA_GetDR(),sys.LORA_GetTXP()); +// } +// else +// { +// sys.LORA_SetDR(LMIC.datarate); +// } } void ABP_InIt(void) { - uint8_t appskey_buff[16] = {0}; - sys.LORA_GetAPPSKEY(appskey_buff); - uint8_t nwkskey_buff[16] = {0}; - sys.LORA_GetNWKSKEY(nwkskey_buff); - uint8_t appskey[sizeof(appskey_buff)]; - uint8_t nwkskey[sizeof(nwkskey_buff)]; - memcpy_P(appskey, appskey_buff, sizeof(appskey_buff)); - memcpy_P(nwkskey, nwkskey_buff, sizeof(nwkskey_buff)); - LMIC_setSession (0x34, sys.LORA_GetDevaddr(), nwkskey_buff, appskey_buff); + uint8_t appskey_buff[16]={0}; + sys.LORA_GetAPPSKEY(appskey_buff); + uint8_t nwkskey_buff[16]={0}; + sys.LORA_GetNWKSKEY(nwkskey_buff); + uint8_t appskey[sizeof(appskey_buff)]; + uint8_t nwkskey[sizeof(nwkskey_buff)]; + memcpy_P(appskey, appskey_buff, sizeof(appskey_buff)); + memcpy_P(nwkskey, nwkskey_buff, sizeof(nwkskey_buff)); + LMIC_setSession (0x13, sys.LORA_GetDevaddr(), nwkskey_buff, appskey_buff); } void SYS::Band_information(void) { -#if defined(CFG_eu868) - Serial.println("EU868"); -#elif defined( CFG_us915) - Serial.println("US915"); -#elif defined( CFG_in866 ) - Serial.println("IN865"); -#elif defined( CFG_au915 ) - Serial.println("AU915"); -#elif defined( CFG_kz865 ) - Serial.println("KZ865"); -#elif defined( CFG_ru864 ) - Serial.println("RU864"); -#elif defined( CFG_as923 ) -#if defined AS923_1 - Serial.println("AS923_1"); -#elif defined AS923_2 - Serial.println("AS923_2"); -#elif defined AS923_3 - Serial.println("AS923_3"); -#elif defined AS923_4 - Serial.println("AS923_4"); -#else - Serial.println("AS923"); -#endif -#elif defined( REGION_CN470 ) - Serial.println("CN470"); -#elif defined( REGION_EU433 ) - Serial.println("EU433"); -#elif defined( CFG_kr920 ) - Serial.println("KR920"); -#elif defined( REGION_ma869 ) - Serial.println("MA869"); -#else - Serial.println("********"); -#endif + #if defined(CFG_eu868) + Serial.println("EU868"); + #elif defined( CFG_us915) + Serial.println("US915"); + #elif defined( CFG_in866 ) + Serial.println("IN865"); + #elif defined( CFG_au915 ) + Serial.println("AU915"); + #elif defined( CFG_kz865 ) + Serial.println("KZ865"); + #elif defined( CFG_ru864 ) + Serial.println("RU864"); + #elif defined( CFG_as923 ) + #if defined AS923_1 + Serial.println("AS923_1"); + #elif defined AS923_2 + Serial.println("AS923_2"); + #elif defined AS923_3 + Serial.println("AS923_3"); + #elif defined AS923_4 + Serial.println("AS923_4"); + #else + Serial.println("AS923"); + #endif + #elif defined( REGION_CN470 ) + Serial.println("CN470"); + #elif defined( REGION_EU433 ) + Serial.println("EU433"); + #elif defined( CFG_kr920 ) + Serial.println("KR920"); + #elif defined( REGION_ma869 ) + Serial.println("MA869"); + #else + Serial.println("********"); + #endif } uint16_t string_touint(void) { - char *p; - uint8_t chanum = 0; + char *p; + uint8_t chanum=0; uint16_t versi; - char version[8] = ""; - if (sys.sensor_type == 13) - { - p = Pro_version; + char version[8]=""; + if(sys.sensor_type == 13) + { + p=Pro_version; } - else if (sys.sensor_type == 22) + else if(sys.sensor_type == 22) { - p = Pro_version1; + p=Pro_version1; } - - while (*p++ != '\0') + + while(*p++!='\0') { - if (*p >= '0' && *p <= '9') - { - version[chanum++] = *p; - } + if(*p>='0'&&*p<='9') + { + version[chanum++]=*p; + } } - versi = atoi(version); - + versi=atoi(version); + return versi; } -void I2C_Sent(int addr, uint8_t* buff, uint8_t buff_len) +void I2C_Sent(int addr,uint8_t* buff,uint8_t buff_len) { Wire.beginTransmission(addr); - for (uint8_t i = 0; i < buff_len; i++) + for(uint8_t i=0;i> 24; - blemask_data[j + 1] = s_config[0 + i] >> 16; - blemask_data[j + 2] = s_config[0 + i] >> 8; - blemask_data[j + 3] = s_config[0 + i]; - } - addr1 = 94; - for (uint8_t i = 0, j = 0; i < 3; i++, j = j + 4) + addr1 += sizeof(unsigned int); + blemask_data[j]= s_config[0+i]>>24; + blemask_data[j+1]= s_config[0+i]>>16; + blemask_data[j+2]= s_config[0+i]>>8; + blemask_data[j+3]= s_config[0+i]; + } + addr1 = 89; + for(uint8_t i=0,j = 0;i<3;i++,j=j+4) { s_config1[i] = DATA.readUInt(addr1); - addr1 += sizeof(unsigned int); - wifimask_data[j] = s_config1[0 + i] >> 24; - wifimask_data[j + 1] = s_config1[0 + i] >> 16; - wifimask_data[j + 2] = s_config1[0 + i] >> 8; - wifimask_data[j + 3] = s_config1[0 + i]; - } + addr1 += sizeof(unsigned int); + wifimask_data[j]= s_config1[0+i]>>24; + wifimask_data[j+1]= s_config1[0+i]>>16; + wifimask_data[j+2]= s_config1[0+i]>>8; + wifimask_data[j+3]= s_config1[0+i]; + } } void SYS::gps_data_Weite(void) { - if (sys.sensor_type == 13) + if(sys.sensor_type == 13) { - if (addr_gps_write >= 4095) + if(addr_gps_write >= 4095) { - gps_write = 4095; - addr_gps_write = 0; + gps_write = 4095; + addr_gps_write = 0; } - if (addr_gps_write <= 4095) + if(addr_gps_write <= 4095) { - for (uint8_t i = 0; i < 15; i++) - { - GPSDATA.writeUChar(addr_gps_write, sys.gps_data_buff[i]); - addr_gps_write += sizeof(unsigned char); - } - sys.config_Write(); - GPSDATA.commit(); - } - } - else if (sys.sensor_type == 22) + for(uint8_t i=0;i<15;i++) + { + GPSDATA.writeUChar(addr_gps_write, sys.gps_data_buff[i]); + addr_gps_write += sizeof(unsigned char); + } + sys.config_Write(); + GPSDATA.commit(); + } + } + else if(sys.sensor_type == 22) { - if (addr_gps_write >= 4080) + if(addr_gps_write >= 4080) { - gps_write = 4080; - addr_gps_write = 0; + gps_write = 4080; + addr_gps_write = 0; } - if (addr_gps_write <= 4080) + if(addr_gps_write <= 4080) { - for (uint8_t i = 0; i < 17; i++) - { - GPSDATA.writeUChar(addr_gps_write, sys.gps_data_buff[i]); - addr_gps_write += sizeof(unsigned char); - } - sys.config_Write(); - GPSDATA.commit(); - } - } - + for(uint8_t i=0;i<17;i++) + { + GPSDATA.writeUChar(addr_gps_write, sys.gps_data_buff[i]); + addr_gps_write += sizeof(unsigned char); + } + sys.config_Write(); + GPSDATA.commit(); + } + } + } void SYS::gps_data_Read(void) { - if (sys.sensor_type == 13) + if(sys.sensor_type == 13) { - for (uint8_t i = 0; i < 15; i++) + for(uint8_t i=0;i<15;i++) { sys.gps_data_buff[i] = GPSDATA.readUChar(addr_gps_read); addr_gps_read += sizeof(unsigned char); } } - else if (sys.sensor_type == 22) + else if(sys.sensor_type == 22) { - for (uint8_t i = 0; i < 17; i++) + for(uint8_t i=0;i<17;i++) { sys.gps_data_buff[i] = GPSDATA.readUChar(addr_gps_read); addr_gps_read += sizeof(unsigned char); - } + } } } void SYS::gps_pdta_Read(uint32_t pdta_addr) { - for (uint32_t i = 0; i < pdta_addr; i++) + for(uint32_t i=0;i 9) s1 -= 7; - + s2 = toupper(h2) - 0x30; if (s2 > 9) s2 -= 7; - + pbDest[i] = s1 * 16 + s2; } } diff --git a/Example/LoRaWAN/examples/TrackerD/common.h b/Example/LoRaWAN/examples/TrackerD/common.h index 76bf9fe..06bb807 100644 --- a/Example/LoRaWAN/examples/TrackerD/common.h +++ b/Example/LoRaWAN/examples/TrackerD/common.h @@ -75,6 +75,7 @@ class SYS:public LORA uint32_t sys_time = 1200000; //uint:ms uint8_t mod = 0; uint8_t lon = 1; //1:on 2:0ff + uint8_t fix = 0; //1:send uplink without GPS 2:0ff/default uint32_t Positioning_time = 180000; uint32_t cdevaddr = 0; uint32_t ble_tdc = 5; diff --git a/Example/LoRaWAN/platformio.ini b/Example/LoRaWAN/platformio.ini index c135286..853cddf 100644 --- a/Example/LoRaWAN/platformio.ini +++ b/Example/LoRaWAN/platformio.ini @@ -55,10 +55,10 @@ build_flags = ; -D CFG_cn490=1 ; Not yet supported ; -D CFG_cn783=1 ; Not yet supported ; -D CFG_eu433=1 ; Not yet supported - -D CFG_eu868=1 + ; -D CFG_eu868=1 ; -D CFG_in866=1 ; -D CFG_kr920=1 - ; -D CFG_us915=1 + -D CFG_us915=1