Hi, as an absolute beginner I couldn't find any solution to the problem. the following code keeps throwing exceptions and I do not know why?
include "Adafruit_MQTT.h" // Adafruit MQTT library
include "Adafruit_MQTT_Client.h" // Adafruit MQTT library
include "ESP8266WiFi.h" // ESP8266 library
include // Adafruit Oled library for display
include <TinyGPS++.h> // Tiny GPS Plus Library
include // Software Serial Library so we can use Pins for communication with the GPS module
define SCREEN_ADDRESS 0x3C //added to define screen address
define SDA_PIN 4 // uses GPIO pins 4(SDA) and 5(SCL) of the ESP8266 Adafruit Feather
define SCL_PIN 5 // also known as pins D1(SCL) and D2(SDA) of the NodeMCU ESP-12
Adafruit_SSD1306 display(SDA_PIN,SCL_PIN); // Set OLED display pins
static const int RXPin = 12, TXPin = 13; // Ublox 6m GPS module to pins 12 and 13
static const uint32_t GPSBaud = 9600; // Ublox GPS default Baud Rate is 9600
TinyGPSPlus gps; // Create an Instance of the TinyGPS++ object called gps
SoftwareSerial ss(RXPin, TXPin); // The serial connection to the GPS device
const double HOME_LAT =xxxx ; // Enter Your Latitude and Longitude here
const double HOME_LNG =xxxxx ; // to track how far away the "patient" is away from Home
/* WiFi Access Point *****/
define WLAN_SSID "xxxxxxxxxxxx" // Enter Your router SSID
define WLAN_PASS "xxxxxxx" // Enter Your router Password
/* Adafruit.io Setup *****/
define AIO_SERVER "io.adafruit.com"
define AIO_SERVERPORT 1883 // use 8883 for SSL
define AIO_USERNAME "xxxxxxxxxxx" // Enter Your Adafruit IO Username
define AIO_KEY "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" // Enter Your Adafruit IO Key
/**** Global State (you don't need to change this!) **/
WiFiClient client; // Create an ESP8266 WiFiClient class to connect to the MQTT server.
const char MQTT_SERVER[] PROGMEM = AIO_SERVER; // Store the MQTT server, username, and password in flash memory.
const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME;
const char MQTT_PASSWORD[] PROGMEM = AIO_KEY;
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD);
/** Feeds ***/
// Setup a feed called 'gpslat' for publishing.
// Notice MQTT paths for AIO follow the form: /feeds/ // This feed is not needed, only setup if you want to see it
const char gpslat_FEED[] PROGMEM = AIO_USERNAME "/feeds/gpslat";
Adafruit_MQTT_Publish gpslat = Adafruit_MQTT_Publish(&mqtt, gpslat_FEED);
// Setup a feed called 'gpslng' for publishing.
// Notice MQTT paths for AIO follow the form: /feeds/ // This feed is not needed, only setup if you want to see it
const char gpslng_FEED[] PROGMEM = AIO_USERNAME "/feeds/gpslng";
Adafruit_MQTT_Publish gpslng = Adafruit_MQTT_Publish(&mqtt, gpslng_FEED);
// Setup a feed called 'gps' for publishing.
// Notice MQTT paths for AIO follow the form: /feeds/
const char gps_FEED[] PROGMEM = AIO_USERNAME "/feeds/gpslatlng/csv"; // CSV = commas seperated values
Adafruit_MQTT_Publish gpslatlng = Adafruit_MQTT_Publish(&mqtt, gps_FEED);
/****/
void setup()
{
Serial.begin(115200); // Setup Serial Comm for Serial Monitor @ 115200 baud
WiFi.mode(WIFI_STA); // Setup ESP8266 as a wifi station
WiFi.disconnect(); // Disconnect if needed
delay(100); // short delay
display.clearDisplay(); // Clear OLED display
display.setTextSize(1); // Set OLED text size to small
display.setTextColor(SSD1306_WHITE); // Set OLED color to White
display.setCursor(0,0); // Set cursor to 0,0
display.println(" Adafruit IO GPS");
display.println(" Tracker");
display.print("---------------------");
display.display(); // Update display
delay(1000); // Pause X seconds
ss.begin(GPSBaud); // Set Software Serial Comm Speed to 9600
display.print("Connecting to WiFi");
display.display();
WiFi.begin(WLAN_SSID, WLAN_PASS); // Start a WiFi connection and enter SSID and Password
while (WiFi.status() != WL_CONNECTED)
{ // While waiting on wifi connection, display "..."
delay(500);
display.print(".");
display.display();
}
display.println("Connected");
display.display();
} // End Setup
void loop() {
smartDelay(500); // Update GPS data TinyGPS needs to be fed often
MQTT_connect(); // Run Procedure to connect to Adafruit IO MQTT
float Distance_To_Home; // variable to store Distance to Home
float GPSlat = (gps.location.lat()); // variable to store latitude
float GPSlng = (gps.location.lng()); // variable to store longitude
float GPSalt = (gps.altitude.feet()); // variable to store altitude
Distance_To_Home = (unsigned long)TinyGPSPlus::distanceBetween(gps.location.lat(),gps.location.lng(),HOME_LAT, HOME_LNG); //Query Tiny GPS to Calculate Distance to Home
display.print("GPS Lat: ");
display.println(gps.location.lat(), 6); // Display latitude to 6 decimal points
display.print("GPS Lon: ");
display.println(gps.location.lng(), 6); // Display longitude to 6 decimal points
display.print("Distance: ");
display.println(Distance_To_Home); // Distance to Home measured in Meters
display.display();
// ** Combine Data to send to Adafruit IO *****
// Here we need to combine Speed, Latitude, Longitude, Altitude into a string variable buffer to send to Adafruit
char gpsbuffer[30]; // Combine Latitude, Longitude, Altitude into a buffer of size X
char *p = gpsbuffer; // Create a buffer to store GPS information to upload to Adafruit IO
dtostrf(Distance_To_Home, 3, 4, p); // Convert Distance to Home to a String Variable and add it to the buffer
p += strlen(p);
p[0] = ','; p++;
dtostrf(GPSlat, 3, 6, p); // Convert GPSlat(latitude) to a String variable and add it to the buffer
p += strlen(p);
p[0] = ','; p++;
dtostrf(GPSlng, 3, 6, p); // Convert GPSlng(longitude) to a String variable and add it to the buffer
p += strlen(p);
p[0] = ','; p++;
dtostrf(GPSalt, 2, 1, p); // Convert GPSalt(altimeter) to a String variable and add it to the buffer
p += strlen(p);
p[0] = 0; // null terminate, end of buffer array
if ((GPSlng != 0) && (GPSlat != 0)) // If GPS longitude or latitude do not equal zero then Publish
{
display.println("Sending GPS Data ");
display.display();
gpslatlng.publish(gpsbuffer); // publish Combined Data to Adafruit IO
Serial.println(gpsbuffer);
}
gpslng.publish(GPSlng,6); // Publish the GPS longitude to Adafruit IO
if (! gpslat.publish(GPSlat,6)) // Publish the GPS latitude to Adafruit IO
{
display.println(F("Failed")); // If it failed to publish, print Failed
} else
{
//display.println(gpsbuffer);
display.println(F("Data Sent!"));
}
display.display();
delay(1000);
if (millis() > 5000 && gps.charsProcessed() < 10)
display.println(F("No GPS data received: check wiring"));
// Wait a bit before scanning again
display.print("Pausing...");
display.display();
smartDelay(500); // Feed TinyGPS constantly
delay(1000);
}
// **** Smart delay - used to feed TinyGPS ****
static void smartDelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (ss.available())
gps.encode(ss.read());
} while (millis() - start < ms);
}
int8_t ret;
if (mqtt.connected()) { return; } // Stop and return to Main Loop if already connected to Adafruit IO
display.print("Connecting to MQTT... ");
display.display();
uint8_t retries = 3;
while ((ret = mqtt.connect()) != 0) { // Connect to Adafruit, Adafruit will return 0 if connected
display.println(mqtt.connectErrorString(ret)); // Display Adafruits response
display.println("Retrying MQTT...");
mqtt.disconnect();
display.display();
delay(5000); // wait X seconds
retries--;
if (retries == 0) { // basically die and wait for WatchDogTimer to reset me
while (1);
}
}
display.println("MQTT Connected!");
display.display();
delay(1000);
}
and viewing the result obtained by the serial monitor I get the following problem
when I use the exception decoder I get the following
PC: 0x4000e1cc
EXCVADDR: 0x00000000
Decoding stack results
0x40207339: delay(unsigned long) at C:\Users\MYPC\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\core_esp8266_wiring.cpp line 57
0x4020732e: delay(unsigned long) at C:\Users\MYPC\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\core_esp8266_wiring.cpp line 54
0x402010af: setup() at C:\Users\MYPC\Documents\Arduino\adafruit_gps/adafruit_gps.ino line 74
0x4020672c: loop_wrapper() at C:\Users\MYPC\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\core_esp8266_main.cpp line 194
resolved exception 29 error by removing progmem which stores information directly in the flash which caused auto resetting in ESP8266, plus added ip connection for successfull connection with MQTT.
Hi, as an absolute beginner I couldn't find any solution to the problem. the following code keeps throwing exceptions and I do not know why?
include "Adafruit_MQTT.h" // Adafruit MQTT library
include "Adafruit_MQTT_Client.h" // Adafruit MQTT library
include "ESP8266WiFi.h" // ESP8266 library
include // Adafruit Oled library for display
include <TinyGPS++.h> // Tiny GPS Plus Library
include // Software Serial Library so we can use Pins for communication with the GPS module
define SCREEN_ADDRESS 0x3C //added to define screen address
define SDA_PIN 4 // uses GPIO pins 4(SDA) and 5(SCL) of the ESP8266 Adafruit Feather
define SCL_PIN 5 // also known as pins D1(SCL) and D2(SDA) of the NodeMCU ESP-12
Adafruit_SSD1306 display(SDA_PIN,SCL_PIN); // Set OLED display pins
static const int RXPin = 12, TXPin = 13; // Ublox 6m GPS module to pins 12 and 13 static const uint32_t GPSBaud = 9600; // Ublox GPS default Baud Rate is 9600
TinyGPSPlus gps; // Create an Instance of the TinyGPS++ object called gps SoftwareSerial ss(RXPin, TXPin); // The serial connection to the GPS device
const double HOME_LAT =xxxx ; // Enter Your Latitude and Longitude here const double HOME_LNG =xxxxx ; // to track how far away the "patient" is away from Home
/* WiFi Access Point *****/
define WLAN_SSID "xxxxxxxxxxxx" // Enter Your router SSID
define WLAN_PASS "xxxxxxx" // Enter Your router Password
/* Adafruit.io Setup *****/
define AIO_SERVER "io.adafruit.com"
define AIO_SERVERPORT 1883 // use 8883 for SSL
define AIO_USERNAME "xxxxxxxxxxx" // Enter Your Adafruit IO Username
define AIO_KEY "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" // Enter Your Adafruit IO Key
/**** Global State (you don't need to change this!) **/
WiFiClient client; // Create an ESP8266 WiFiClient class to connect to the MQTT server.
const char MQTT_SERVER[] PROGMEM = AIO_SERVER; // Store the MQTT server, username, and password in flash memory. const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME; const char MQTT_PASSWORD[] PROGMEM = AIO_KEY;
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details. Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD);
/** Feeds ***/
// Setup a feed called 'gpslat' for publishing. // Notice MQTT paths for AIO follow the form:/feeds/ // This feed is not needed, only setup if you want to see it
const char gpslat_FEED[] PROGMEM = AIO_USERNAME "/feeds/gpslat";
Adafruit_MQTT_Publish gpslat = Adafruit_MQTT_Publish(&mqtt, gpslat_FEED);
// Setup a feed called 'gpslng' for publishing. // Notice MQTT paths for AIO follow the form:/feeds/ // This feed is not needed, only setup if you want to see it
const char gpslng_FEED[] PROGMEM = AIO_USERNAME "/feeds/gpslng";
Adafruit_MQTT_Publish gpslng = Adafruit_MQTT_Publish(&mqtt, gpslng_FEED);
// Setup a feed called 'gps' for publishing. // Notice MQTT paths for AIO follow the form:/feeds/
const char gps_FEED[] PROGMEM = AIO_USERNAME "/feeds/gpslatlng/csv"; // CSV = commas seperated values
Adafruit_MQTT_Publish gpslatlng = Adafruit_MQTT_Publish(&mqtt, gps_FEED);
/****/
void setup() { Serial.begin(115200); // Setup Serial Comm for Serial Monitor @ 115200 baud WiFi.mode(WIFI_STA); // Setup ESP8266 as a wifi station WiFi.disconnect(); // Disconnect if needed delay(100); // short delay
display.clearDisplay(); // Clear OLED display display.setTextSize(1); // Set OLED text size to small display.setTextColor(SSD1306_WHITE); // Set OLED color to White display.setCursor(0,0); // Set cursor to 0,0 display.println(" Adafruit IO GPS");
display.println(" Tracker"); display.print("---------------------"); display.display(); // Update display delay(1000); // Pause X seconds
ss.begin(GPSBaud); // Set Software Serial Comm Speed to 9600
display.print("Connecting to WiFi"); display.display();
WiFi.begin(WLAN_SSID, WLAN_PASS); // Start a WiFi connection and enter SSID and Password while (WiFi.status() != WL_CONNECTED) { // While waiting on wifi connection, display "..." delay(500); display.print("."); display.display(); } display.println("Connected"); display.display();
} // End Setup
void loop() {
smartDelay(500); // Update GPS data TinyGPS needs to be fed often MQTT_connect(); // Run Procedure to connect to Adafruit IO MQTT
float Distance_To_Home; // variable to store Distance to Home
float GPSlat = (gps.location.lat()); // variable to store latitude float GPSlng = (gps.location.lng()); // variable to store longitude float GPSalt = (gps.altitude.feet()); // variable to store altitude
Distance_To_Home = (unsigned long)TinyGPSPlus::distanceBetween(gps.location.lat(),gps.location.lng(),HOME_LAT, HOME_LNG); //Query Tiny GPS to Calculate Distance to Home
display.clearDisplay();
display.setCursor(0,0);
display.println(F(" GPS Tracking")); display.print("---------------------"); display.display();
display.print("GPS Lat: "); display.println(gps.location.lat(), 6); // Display latitude to 6 decimal points display.print("GPS Lon: "); display.println(gps.location.lng(), 6); // Display longitude to 6 decimal points display.print("Distance: "); display.println(Distance_To_Home); // Distance to Home measured in Meters
display.display();
// ** Combine Data to send to Adafruit IO ***** // Here we need to combine Speed, Latitude, Longitude, Altitude into a string variable buffer to send to Adafruit
if (millis() > 5000 && gps.charsProcessed() < 10) display.println(F("No GPS data received: check wiring"));
// Wait a bit before scanning again display.print("Pausing..."); display.display(); smartDelay(500); // Feed TinyGPS constantly delay(1000); }
// **** Smart delay - used to feed TinyGPS ****
static void smartDelay(unsigned long ms)
{ unsigned long start = millis(); do { while (ss.available()) gps.encode(ss.read()); } while (millis() - start < ms); }
// **** MQTT Connect - connects with Adafruit IO ***** void MQTT_connect() {
int8_t ret; if (mqtt.connected()) { return; } // Stop and return to Main Loop if already connected to Adafruit IO display.print("Connecting to MQTT... "); display.display();
uint8_t retries = 3; while ((ret = mqtt.connect()) != 0) { // Connect to Adafruit, Adafruit will return 0 if connected display.println(mqtt.connectErrorString(ret)); // Display Adafruits response display.println("Retrying MQTT..."); mqtt.disconnect(); display.display(); delay(5000); // wait X seconds retries--; if (retries == 0) { // basically die and wait for WatchDogTimer to reset me
while (1);
} } display.println("MQTT Connected!"); display.display(); delay(1000); }
and viewing the result obtained by the serial monitor I get the following problem
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 3584, room 16 tail 0 chksum 0xb0 csum 0xb0 v2843a5ac ~ld
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
Exception (29): epc1=0x4000e1cc epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
ctx: cont sp: 3ffffde0 end: 3fffffc0 offset: 0190 3fffff70: 40207339 00000064 3ffeeb28 4020732e
3fffff80: 3fffdad0 3ffee954 3ffeeae8 402010af
3fffff90: feefeffe feefeffe feefeffe feefeffe
3fffffa0: 3fffdad0 00000000 3ffeeae8 4020672c
3fffffb0: feefeffe feefeffe 3ffe84f4 401011d9
<<<stack<<<
when I use the exception decoder I get the following PC: 0x4000e1cc EXCVADDR: 0x00000000
Decoding stack results 0x40207339: delay(unsigned long) at C:\Users\MYPC\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\core_esp8266_wiring.cpp line 57 0x4020732e: delay(unsigned long) at C:\Users\MYPC\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\core_esp8266_wiring.cpp line 54 0x402010af: setup() at C:\Users\MYPC\Documents\Arduino\adafruit_gps/adafruit_gps.ino line 74 0x4020672c: loop_wrapper() at C:\Users\MYPC\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\core_esp8266_main.cpp line 194