testing GPS
This commit is contained in:
		
							parent
							
								
									59cbe6939b
								
							
						
					
					
						commit
						4f2139a715
					
				@ -54,11 +54,11 @@ typedef struct {
 | 
				
			|||||||
    uint32_t latitude;
 | 
					    uint32_t latitude;
 | 
				
			||||||
    uint32_t longitude;
 | 
					    uint32_t longitude;
 | 
				
			||||||
    uint8_t hdop;
 | 
					    uint8_t hdop;
 | 
				
			||||||
    uint8_t satellites;
 | 
					    uint32_t satellites;
 | 
				
			||||||
    uint16_t altitude;
 | 
					    uint16_t altitude;
 | 
				
			||||||
    } gpsStatus_t;
 | 
					    } gpsStatus_t;
 | 
				
			||||||
  extern gpsStatus_t gps_status;        // struct for storing gps data
 | 
					  extern gpsStatus_t gps_status;        // struct for storing gps data
 | 
				
			||||||
  extern TinyGPSPlus my_gps;            // Make TinyGPS++ instance globally availabe
 | 
					  extern TinyGPSPlus gps;            // Make TinyGPS++ instance globally availabe
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern configData_t cfg;
 | 
					extern configData_t cfg;
 | 
				
			||||||
 | 
				
			|||||||
@ -5,7 +5,17 @@
 | 
				
			|||||||
// Local logging tag
 | 
					// Local logging tag
 | 
				
			||||||
static const char TAG[] = "main";
 | 
					static const char TAG[] = "main";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// GPS Read FreeRTos Task
 | 
					// GPS read data to global struct
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void gps_read(){
 | 
				
			||||||
 | 
					    gps_status.latitude = gps.location.lat();
 | 
				
			||||||
 | 
					    gps_status.longitude = gps.location.lng();
 | 
				
			||||||
 | 
					    gps_status.satellites = (uint8_t) gps.satellites.value();
 | 
				
			||||||
 | 
					    gps_status.hdop = (uint8_t) (gps.hdop.value() / 100);
 | 
				
			||||||
 | 
					    gps_status.altitude = (uint16_t) gps.altitude.meters(); 
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GPS serial feed FreeRTos Task
 | 
				
			||||||
void gps_loop(void * pvParameters) {
 | 
					void gps_loop(void * pvParameters) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    configASSERT( ( ( uint32_t ) pvParameters ) == 1 ); // FreeRTOS check
 | 
					    configASSERT( ( ( uint32_t ) pvParameters ) == 1 ); // FreeRTOS check
 | 
				
			||||||
@ -17,8 +27,7 @@ void gps_loop(void * pvParameters) {
 | 
				
			|||||||
    while(1) {
 | 
					    while(1) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        while (GPS_Serial.available()) {
 | 
					        while (GPS_Serial.available()) {
 | 
				
			||||||
            my_gps.encode(GPS_Serial.read());
 | 
					            gps.encode(GPS_Serial.read());
 | 
				
			||||||
            ESP_LOGI(TAG, "GSP checksum passed / failed: %d / %d", my_gps.passedChecksum(), my_gps.failedChecksum());
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        vTaskDelay(1/portTICK_PERIOD_MS); // reset watchdog
 | 
					        vTaskDelay(1/portTICK_PERIOD_MS); // reset watchdog
 | 
				
			||||||
 | 
				
			|||||||
@ -2,20 +2,20 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#define CFG_sx1276_radio 1 // HPD13A LoRa SoC
 | 
					#define CFG_sx1276_radio 1 // HPD13A LoRa SoC
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define HAS_LED 21 // on board green LED_G1
 | 
					#define HAS_LED GPIO_NUM_21 // on board green LED_G1
 | 
				
			||||||
#define HAS_BUTTON GPIO_NUM_0 // on board button "BOOT" (next to reset button)
 | 
					//#define HAS_BUTTON GPIO_NUM_39 // on board button "BOOT" (next to reset button) !! seems not to work!!
 | 
				
			||||||
#define HAS_BATTERY_PROBE ADC1_GPIO35_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7
 | 
					#define HAS_BATTERY_PROBE ADC1_GPIO35_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7
 | 
				
			||||||
#define BATT_FACTOR 2 // voltage divider 100k/100k on board
 | 
					#define BATT_FACTOR 2 // voltage divider 100k/100k on board
 | 
				
			||||||
#define HAS_GPS 9600, SERIAL_8N1, 12, 15   //17-TX 18-RX
 | 
					#define HAS_GPS 9600, SERIAL_8N1, 12, 15
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// re-define pin definitions of pins_arduino.h
 | 
					// re-define pin definitions of pins_arduino.h
 | 
				
			||||||
#define PIN_SPI_SS    18 // ESP32 GPIO18 (Pin18) -- HPD13A NSS/SEL (Pin4) SPI Chip Select Input
 | 
					#define PIN_SPI_SS    GPIO_NUM_18 // ESP32 GPIO18 (Pin18) -- HPD13A NSS/SEL (Pin4) SPI Chip Select Input
 | 
				
			||||||
#define PIN_SPI_MOSI  27 // ESP32 GPIO27 (Pin27) -- HPD13A MOSI/DSI (Pin6) SPI Data Input
 | 
					#define PIN_SPI_MOSI  GPIO_NUM_27 // ESP32 GPIO27 (Pin27) -- HPD13A MOSI/DSI (Pin6) SPI Data Input
 | 
				
			||||||
#define PIN_SPI_MISO  19 // ESP32 GPIO19 (Pin19) -- HPD13A MISO/DSO (Pin7) SPI Data Output
 | 
					#define PIN_SPI_MISO  GPIO_NUM_19 // ESP32 GPIO19 (Pin19) -- HPD13A MISO/DSO (Pin7) SPI Data Output
 | 
				
			||||||
#define PIN_SPI_SCK   5  // ESP32 GPIO5 (Pin5)   -- HPD13A SCK (Pin5) SPI Clock Input
 | 
					#define PIN_SPI_SCK   GPIO_NUM_5  // ESP32 GPIO5 (Pin5)   -- HPD13A SCK (Pin5) SPI Clock Input
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// non arduino pin definitions
 | 
					// non arduino pin definitions
 | 
				
			||||||
#define RST   LMIC_UNUSED_PIN // connected to ESP32 RST/EN
 | 
					#define RST   LMIC_UNUSED_PIN // connected to ESP32 RST/EN
 | 
				
			||||||
#define DIO0  26 // ESP32 GPIO26 <-> HPD13A IO0
 | 
					#define DIO0  GPIO_NUM_26 // ESP32 GPIO26 <-> HPD13A IO0
 | 
				
			||||||
#define DIO1  33 // Lora1 <-> HPD13A IO1 // !! NEEDS EXTERNAL WIRING !!
 | 
					#define DIO1  GPIO_NUM_33 // Lora1 <-> HPD13A IO1 // !! NEEDS EXTERNAL WIRING !!
 | 
				
			||||||
#define DIO2  32 // Lora2 <-> HPD13A IO2 // needs external wiring, but not necessary for LoRa, only FSK
 | 
					#define DIO2  LMIC_UNUSED_PIN // Lora2 <-> HPD13A IO2 // needs external wiring, but not necessary for LoRa, only FSK
 | 
				
			||||||
 | 
				
			|||||||
@ -137,12 +137,8 @@ void do_send(osjob_t* j){
 | 
				
			|||||||
    sprintf(display_lmic, "PACKET QUEUED");
 | 
					    sprintf(display_lmic, "PACKET QUEUED");
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    #ifdef HAS_GPS
 | 
					    #ifdef HAS_GPS
 | 
				
			||||||
        if (cfg.gpsmode && my_gps.location.isValid()) {
 | 
					        if (cfg.gpsmode && gps.location.isValid()) {
 | 
				
			||||||
            gps_status.latitude = my_gps.location.lat();
 | 
					            gps_read();
 | 
				
			||||||
            gps_status.longitude = my_gps.location.lng();
 | 
					 | 
				
			||||||
            gps_status.satellites = my_gps.satellites.value();
 | 
					 | 
				
			||||||
            gps_status.hdop = my_gps.hdop.value();
 | 
					 | 
				
			||||||
            gps_status.altitude = my_gps.altitude.meters();
 | 
					 | 
				
			||||||
            LMIC_setTxData2(GPSPORT, (byte*)&gps_status, sizeof(gps_status), (cfg.countermode & 0x02));
 | 
					            LMIC_setTxData2(GPSPORT, (byte*)&gps_status, sizeof(gps_status), (cfg.countermode & 0x02));
 | 
				
			||||||
            ESP_LOGI(TAG, "HDOP=%d, SATS=%d, LAT=%d, LON=%d", gps_status.hdop, gps_status.satellites, gps_status.latitude, gps_status.longitude );
 | 
					            ESP_LOGI(TAG, "HDOP=%d, SATS=%d, LAT=%d, LON=%d", gps_status.hdop, gps_status.satellites, gps_status.latitude, gps_status.longitude );
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										22
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								src/main.cpp
									
									
									
									
									
								
							@ -57,15 +57,15 @@ u1_t rcmd_data_size;                // buffer for rcommand results size
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#ifdef HAS_GPS
 | 
					#ifdef HAS_GPS
 | 
				
			||||||
    gpsStatus_t gps_status;         // struct for storing gps data
 | 
					    gpsStatus_t gps_status;         // struct for storing gps data
 | 
				
			||||||
    TinyGPSPlus my_gps;             // create TinyGPS++ instance
 | 
					    TinyGPSPlus gps;             // create TinyGPS++ instance
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED; // sync main loop and ISR when modifying shared variable DisplayIRQ
 | 
					portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED; // sync main loop and ISR when modifying IRQ handler shared variables
 | 
				
			||||||
 | 
					
 | 
				
			||||||
std::set<uint16_t> macs; // associative container holds total of unique MAC adress hashes (Wifi + BLE)
 | 
					std::set<uint16_t> macs; // associative container holds total of unique MAC adress hashes (Wifi + BLE)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// this variables will be changed in the ISR, and read in main loop
 | 
					// this variables will be changed in the ISR, and read in main loop
 | 
				
			||||||
static volatile int ButtonPressed = 0, DisplayTimerIRQ = 0, ChannelTimerIRQ = 0;
 | 
					static volatile int ButtonPressedIRQ = 0, DisplayTimerIRQ = 0, ChannelTimerIRQ = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// local Tag for logging
 | 
					// local Tag for logging
 | 
				
			||||||
static const char TAG[] = "main";
 | 
					static const char TAG[] = "main";
 | 
				
			||||||
@ -167,14 +167,14 @@ void lorawan_loop(void * pvParameters) {
 | 
				
			|||||||
    bool btstop = btStop();
 | 
					    bool btstop = btStop();
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Button IRQ Handler Routine, IRAM_ATTR necessary here, see https://github.com/espressif/arduino-esp32/issues/855
 | 
				
			||||||
#ifdef HAS_BUTTON
 | 
					#ifdef HAS_BUTTON
 | 
				
			||||||
    // Button IRQ
 | 
					 | 
				
			||||||
    // IRAM_ATTR necessary here, see https://github.com/espressif/arduino-esp32/issues/855
 | 
					 | 
				
			||||||
    void IRAM_ATTR ButtonIRQ() {
 | 
					    void IRAM_ATTR ButtonIRQ() {
 | 
				
			||||||
        ButtonPressed++;
 | 
					        ButtonPressedIRQ++;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Wifi Channel Rotation Timer IRQ Handler Routine
 | 
				
			||||||
void IRAM_ATTR ChannelSwitchIRQ() {
 | 
					void IRAM_ATTR ChannelSwitchIRQ() {
 | 
				
			||||||
    portENTER_CRITICAL(&timerMux);
 | 
					    portENTER_CRITICAL(&timerMux);
 | 
				
			||||||
    ChannelTimerIRQ++;
 | 
					    ChannelTimerIRQ++;
 | 
				
			||||||
@ -344,8 +344,11 @@ uint64_t uptime() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#ifdef HAS_BUTTON
 | 
					#ifdef HAS_BUTTON
 | 
				
			||||||
    void readButton() {
 | 
					    void readButton() {
 | 
				
			||||||
        if (ButtonPressed) {
 | 
					        if (ButtonPressedIRQ) {
 | 
				
			||||||
            ButtonPressed--;
 | 
					            portENTER_CRITICAL(&timerMux);
 | 
				
			||||||
 | 
					            ButtonPressedIRQ--;
 | 
				
			||||||
 | 
					            portEXIT_CRITICAL(&timerMux);
 | 
				
			||||||
 | 
					            ESP_LOGI(TAG, "Button pressed");
 | 
				
			||||||
            ESP_LOGI(TAG, "Button pressed, resetting device to factory defaults");
 | 
					            ESP_LOGI(TAG, "Button pressed, resetting device to factory defaults");
 | 
				
			||||||
            eraseConfig();
 | 
					            eraseConfig();
 | 
				
			||||||
            esp_restart();  
 | 
					            esp_restart();  
 | 
				
			||||||
@ -623,6 +626,9 @@ void loop() {
 | 
				
			|||||||
            reset_salt();       // get new salt for salting hashes
 | 
					            reset_salt();       // get new salt for salting hashes
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ( (uptime() % 10000) == 0 )
 | 
				
			||||||
 | 
					            ESP_LOGI(TAG, "GPS NMEA data passed %d / failed: %d / with fix: %d || Sats: %d / HDOP: %d", gps.passedChecksum(), gps.failedChecksum(), gps.sentencesWithFix(), gps.satellites.value(), gps.hdop.value());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        vTaskDelay(1/portTICK_PERIOD_MS); // reset watchdog
 | 
					        vTaskDelay(1/portTICK_PERIOD_MS); // reset watchdog
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    } // end of infinite main loop
 | 
					    } // end of infinite main loop
 | 
				
			||||||
 | 
				
			|||||||
@ -48,5 +48,6 @@ void wifi_sniffer_packet_handler(void *buff, wifi_promiscuous_pkt_type_t type);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
//defined in gpsread.cpp
 | 
					//defined in gpsread.cpp
 | 
				
			||||||
#ifdef HAS_GPS
 | 
					#ifdef HAS_GPS
 | 
				
			||||||
 | 
					  void gps_read(void);
 | 
				
			||||||
  void gps_loop(void * pvParameters);
 | 
					  void gps_loop(void * pvParameters);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
@ -260,13 +260,11 @@ void get_voltage (uint8_t val) {
 | 
				
			|||||||
void get_gps (uint8_t val) {
 | 
					void get_gps (uint8_t val) {
 | 
				
			||||||
    ESP_LOGI(TAG, "Remote command: get gps status");
 | 
					    ESP_LOGI(TAG, "Remote command: get gps status");
 | 
				
			||||||
    #ifdef HAS_GPS
 | 
					    #ifdef HAS_GPS
 | 
				
			||||||
        gps_status.latitude = my_gps.location.lat();
 | 
					    if (gps.location.isValid()) {
 | 
				
			||||||
        gps_status.longitude = my_gps.location.lng();
 | 
					        gps_read();
 | 
				
			||||||
        gps_status.satellites = my_gps.satellites.value();
 | 
					 | 
				
			||||||
        gps_status.hdop = my_gps.hdop.value();
 | 
					 | 
				
			||||||
        gps_status.altitude = my_gps.altitude.meters(); 
 | 
					 | 
				
			||||||
        transmit((byte*)&gps_status, sizeof(gps_status));
 | 
					        transmit((byte*)&gps_status, sizeof(gps_status));
 | 
				
			||||||
        ESP_LOGI(TAG, "HDOP=%d, SATS=%d, LAT=%d, LON=%d", gps_status.hdop, gps_status.satellites, gps_status.latitude, gps_status.longitude );
 | 
					        ESP_LOGI(TAG, "HDOP=%d, SATS=%d, LAT=%d, LON=%d", gps_status.hdop, gps_status.satellites, gps_status.latitude, gps_status.longitude );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    #endif
 | 
					    #endif
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user