GPS testing
This commit is contained in:
1 parent
1850f94f71
commit
aa1b4172fe
6 files changed
+87
-69
No files matched your search
+28
-13
@@ -6,7 +6,7 @@
|
||||
static const char TAG[] = "main";
|
||||
|
||||
// read GPS data and cast to global struct
|
||||
void gps_read(){
|
||||
void gps_read() {
|
||||
gps_status.latitude = (uint32_t) (gps.location.lat() * 1000000);
|
||||
gps_status.longitude = (uint32_t) (gps.location.lng() * 1000000);
|
||||
gps_status.satellites = (uint8_t) gps.satellites.value();
|
||||
@@ -19,11 +19,10 @@ void gps_loop(void * pvParameters) {
|
||||
|
||||
configASSERT( ( ( uint32_t ) pvParameters ) == 1 ); // FreeRTOS check
|
||||
|
||||
#ifdef GPS_SERIAL
|
||||
// initialize and, if needed, configure, GPS
|
||||
#if defined GPS_SERIAL
|
||||
HardwareSerial GPS_Serial(1);
|
||||
#endif
|
||||
|
||||
#ifdef GPS_I2C
|
||||
#elif defined GPS_I2C
|
||||
// to be done
|
||||
#endif
|
||||
|
||||
@@ -31,7 +30,8 @@ void gps_loop(void * pvParameters) {
|
||||
|
||||
if (cfg.gpsmode)
|
||||
{
|
||||
#ifdef GPS_SERIAL
|
||||
#if defined GPS_SERIAL
|
||||
|
||||
// serial connect to GPS device
|
||||
GPS_Serial.begin(GPS_SERIAL);
|
||||
|
||||
@@ -39,19 +39,34 @@ void gps_loop(void * pvParameters) {
|
||||
// feed GPS decoder with serial NMEA data from GPS device
|
||||
while (GPS_Serial.available()) {
|
||||
gps.encode(GPS_Serial.read());
|
||||
vTaskDelay(1/portTICK_PERIOD_MS); // reset watchdog
|
||||
}
|
||||
vTaskDelay(1/portTICK_PERIOD_MS); // reset watchdog
|
||||
}
|
||||
// after GPS function was disabled, close connect to GPS device
|
||||
GPS_Serial.end();
|
||||
#endif
|
||||
|
||||
#ifdef GPS_I2C
|
||||
// I2C connect to GPS device
|
||||
#elif defined GPS_I2C
|
||||
|
||||
/*
|
||||
to be done
|
||||
*/
|
||||
// I2C connect to GPS device with 100 kHz
|
||||
Wire.begin(GPS_I2C_PINS, 100000);
|
||||
Wire.beginTransmission(GPS_I2C_ADDRESS_WRITE);
|
||||
Wire.write(0x00);
|
||||
|
||||
i2c_ret == Wire.beginTransmission(GPS_I2C_ADDRESS_READ);
|
||||
if (i2c_ret == 0) { // check if device seen on i2c bus
|
||||
while(cfg.gpsmode) {
|
||||
// feed GPS decoder with serial NMEA data from GPS device
|
||||
while (Wire.available()) {
|
||||
Wire.requestFrom(GPS_I2C_ADDRESS_READ, 255);
|
||||
gps.encode(Wire.read());
|
||||
vTaskDelay(1/portTICK_PERIOD_MS); // reset watchdog
|
||||
}
|
||||
}
|
||||
// after GPS function was disabled, close connect to GPS device
|
||||
|
||||
Wire.endTransmission();
|
||||
Wire.setClock(400000); // Set back to 400KHz to speed up OLED
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
+6
-2
@@ -4,9 +4,13 @@
|
||||
#define HAS_LED NOT_A_PIN // LoPy4 has no on board LED, so we use RGB LED on LoPy4
|
||||
#define HAS_RGB_LED GPIO_NUM_0 // WS2812B RGB LED on GPIO0
|
||||
|
||||
// use only if your LoPy lives on a Pytrack expansion board
|
||||
// !!EXPERIMENTAL - not tested yet!!
|
||||
// uncomment this only if your LoPy lives on a Pytrack expansion board with GPS
|
||||
// see http://www.quectel.com/UploadImage/Downlad/Quectel_L76-L_I2C_Application_Note_V1.0.pdf
|
||||
//#define HAS_GPS 1
|
||||
//#define GPS_I2C GPIO_NUM_9, GPIO_NUM_8 // SDA, SCL
|
||||
//#define GPS_I2C_PINS GPIO_NUM_9, GPIO_NUM_8 // SDA, SCL
|
||||
//#define GPS_I2C_ADDRESS_READ 0x21
|
||||
//#define GPS_I2C_ADDRESS_WRITE 0x20
|
||||
//#define HAS_BUTTON GPIO_NUM_4
|
||||
|
||||
// Hardware pin definitions for Pycom LoPy board
|
||||
|
||||
+6
-2
@@ -4,9 +4,13 @@
|
||||
#define HAS_LED NOT_A_PIN // LoPy4 has no on board LED, so we use RGB LED on LoPy4
|
||||
#define HAS_RGB_LED GPIO_NUM_0 // WS2812B RGB LED on GPIO0
|
||||
|
||||
// use only if your LoPy lives on a Pytrack expansion board
|
||||
// !!EXPERIMENTAL - not tested yet!!f
|
||||
// uncomment this only if your LoPy lives on a Pytrack expansion board with GPS
|
||||
// see http://www.quectel.com/UploadImage/Downlad/Quectel_L76-L_I2C_Application_Note_V1.0.pdf
|
||||
//#define HAS_GPS 1
|
||||
//#define GPS_I2C GPIO_NUM_9, GPIO_NUM_8 // SDA, SCL
|
||||
//#define GPS_I2C_PINS GPIO_NUM_9, GPIO_NUM_8 // SDA, SCL
|
||||
//#define GPS_I2C_ADDRESS_READ 0x21
|
||||
//#define GPS_I2C_ADDRESS_WRITE 0x20
|
||||
//#define HAS_BUTTON GPIO_NUM_4
|
||||
|
||||
// Hardware pin definitions for Pycom LoPy4 board
|
||||
|
||||
+15
-12
@@ -116,7 +116,7 @@ void do_send(osjob_t* j){
|
||||
|
||||
// prepare payload with sum of unique WIFI MACs seen
|
||||
static uint8_t mydata[4];
|
||||
|
||||
|
||||
mydata[0] = (macs_wifi & 0xff00) >> 8;
|
||||
mydata[1] = macs_wifi & 0xff;
|
||||
|
||||
@@ -129,19 +129,26 @@ void do_send(osjob_t* j){
|
||||
mydata[3] = 0;
|
||||
}
|
||||
|
||||
// Prepare upstream data transmission at the next possible time.
|
||||
LMIC_setTxData2(COUNTERPORT, mydata, sizeof(mydata), (cfg.countermode & 0x02));
|
||||
ESP_LOGI(TAG, "%d bytes queued to send", sizeof(mydata));
|
||||
sprintf(display_lmic, "PACKET QUEUED");
|
||||
|
||||
#ifdef HAS_GPS
|
||||
static uint8_t gpsdata[18];
|
||||
if (cfg.gpsmode && gps.location.isValid()) {
|
||||
gps_read();
|
||||
LMIC_setTxData2(GPSPORT, (byte*)&gps_status, sizeof(gps_status), (cfg.countermode & 0x02));
|
||||
memcpy (gpsdata+4, &gps_status, sizeof(gps_status));
|
||||
memcpy (gpsdata, mydata, 4);
|
||||
ESP_LOGI(TAG, "lat=%f / lon=%f | Sats=%u | HDOP=%u | Alti=%u", gps_status.latitude / 1000000, gps_status.longitude / 1000000, gps_status.satellites, gps_status.hdop, gps_status.altitude);
|
||||
LMIC_setTxData2(COUNTERPORT, gpsdata, sizeof(gpsdata), (cfg.countermode & 0x02));
|
||||
ESP_LOGI(TAG, "%d bytes queued to send", sizeof(gpsdata));
|
||||
}
|
||||
else {
|
||||
#endif
|
||||
|
||||
LMIC_setTxData2(COUNTERPORT, mydata, sizeof(mydata), (cfg.countermode & 0x02));
|
||||
ESP_LOGI(TAG, "%d bytes queued to send", sizeof(mydata));
|
||||
sprintf(display_lmic, "PACKET QUEUED");
|
||||
|
||||
#ifdef HAS_GPS
|
||||
}
|
||||
#endif
|
||||
|
||||
// clear counter if not in cumulative counter mode
|
||||
if (cfg.countermode != 1) {
|
||||
reset_counters(); // clear macs container and reset all counters
|
||||
@@ -178,10 +185,6 @@ void onEvent (ev_t ev) {
|
||||
strcpy_P(buff, PSTR("JOINED"));
|
||||
sprintf(display_lora, " "); // clear previous lmic status message from display
|
||||
|
||||
// Disable link check validation (automatically enabled
|
||||
// during join, but not supported by TTN at this time). -> do we need this?
|
||||
// LMIC_setLinkCheckMode(0);
|
||||
|
||||
// set data rate adaptation
|
||||
LMIC_setAdrMode(cfg.adrmode);
|
||||
// Set data rate and transmit power (note: txpower seems to be ignored by the library)
|
||||
|
||||
+2
-2
@@ -586,8 +586,8 @@ xTaskCreatePinnedToCore(sniffer_loop, "wifisniffer", 2048, ( void * ) 1, 1, NULL
|
||||
// if device has GPS and GPS function is enabled, start GPS reader task on core 0
|
||||
#ifdef HAS_GPS
|
||||
if (cfg.gpsmode) {
|
||||
ESP_LOGI(TAG, "Starting GPS task on core 0");
|
||||
xTaskCreatePinnedToCore(gps_loop, "gpsfeed", 2048, ( void * ) 1, 1, NULL, 0);
|
||||
ESP_LOGI(TAG, "Starting GPS task on core 0");
|
||||
xTaskCreatePinnedToCore(gps_loop, "gpsfeed", 2048, ( void * ) 1, 1, NULL, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in new issue
Block a user