Decoding exceptions and stack but cannot locate the problem

Dear friends,

I am totally new to the forum, so please forgive any mistakes that I may do.
I am currently building a system for my thesis, using a Wemos D1 R2 and a MPU6050 module, to read accelerometer and gyroscope data, and transmit to a MySQL Server.

The system, with the exact same code, was working fine, but eventually after several uploads and code changes it throws an exception as soon as the wires move even a tiny bit. To be more clear, the system is working perfectly fine, however when the tiniest movement happens to the wires, it stops working and throws an exception.

I have tried to resolve the issue by replacing my Wemos D1 R2 with a NodeMCU v1.0, by replacing the wires, even by replacing the MPU6050, but the problem still occurs.
I have used the exception decoder to figure out what is going wrong, but unfortunately I cannot understand what it says.

I have tried all the ESP8266 drivers, I am currently using 2.4.0-rc2.
In my code I only have imported as a .ZIP the particular MySQL library

Please find my code attached

#include <ESP8266WiFi.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
#include <WiFiClient.h>
#include <math.h>
#include <Wire.h>
#include <SPI.h>

const int MPU_addr=0x68;
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
float AcXN,AcYN,AcZN,GyXN,GyYN,GyZN,R;
int counter=1;

char ssid[] = "SKYEB5A9";
char pass[] = "12349999";
WiFiServer server(80);
WiFiClient client;
MySQL_Connection conn(&client);

char INSERT_SQL[]="INSERT INTO test.testdata(AcX,AcY,AcZ,GyX,GyY,GyZ,R) VALUES (%f,%f,%f,%f,%f,%f,%f)";
char query[128];

IPAddress server_addr(192, 168, 0, 5);
char user[] = "wemos";           // MySQL user
char password[] = "";       // MySQL password
byte mac[6];

void setup(){
  Serial.print("Connecting to Selected Wi-Fi...");
  WiFi.begin(ssid, pass);
   while (WiFi.status() != WL_CONNECTED) {
  Serial.print("MAC: ");
  Serial.println("Wi-Fi connected successfully");
  Serial.println("Connecting to database");
  while (conn.connect(server_addr, 3306, user, password) != true) {
    Serial.print ( "." );
  Serial.println("Connected to SQL Server!");  
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.beginTransmission(0b1101000); //I2C address of the MPU
  Wire.write(0x1B); //Accessing the register 1B - Gyroscope Configuration (Sec. 4.4) 
  Wire.write(0x00000000); //Setting the gyro to full scale +/- 250deg./s 
  Wire.beginTransmission(0b1101000); //I2C address of the MPU
  Wire.write(0x1C); //Accessing the register 1C - Acccelerometer Configuration (Sec. 4.5) 
  Wire.write(0b00000000); //Setting the accel to +/- 2g

void loop(){
  //Read Raw Data
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.requestFrom(MPU_addr,14,true);  // request a total of 14 registers<<8|;  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)<<8|;  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)<<8|;  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)<<8|;  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)<<8|;  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)<<8|;  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)<<8|;  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
  //Normalize Raw Data

  //Print Normalized Data
  Serial.print("AcX = "); Serial.print(AcXN,4);
  Serial.print(" | AcY = "); Serial.print(AcYN,4);
  Serial.print(" | AcZ = "); Serial.print(AcZN,4);
  Serial.print(" | Tmp = "); Serial.print((Tmp/340.00)+36.53);  //equation for temperature in degrees C from datasheet
  Serial.print(" | GyX = "); Serial.print(GyXN,4);
  Serial.print(" | GyY = "); Serial.print(GyYN,4);
  Serial.print(" | GyZ = "); Serial.println(GyZN,4);
  sprintf(query, INSERT_SQL, AcXN, AcYN, AcZN, GyXN, GyYN, GyZN, R);
  if (conn.connect(server_addr, 3306, user, password)) {  
    MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
    delete cur_mem;

And please find the exception decoder results attached as well

0x401004d8: malloc at C:\Users\Vasileios Magias\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\cores\esp8266\umm_malloc/umm_malloc.c line 1668
0x40106abc: pvPortMalloc at C:\Users\Vasileios Magias\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\cores\esp8266/heap.c line 40
0x402252c8: pbuf_alloc at core/pbuf.c line 366
0x40205bbd: Print::write(char const*) at C:\Users\Vasileios Magias\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\cores\esp8266/Print.cpp line 211
0x40226835: tcp_enqueue_flags at core/tcp_out.c line 762
0x40226901: tcp_send_fin at core/tcp_out.c line 144
0x4020cbcc: tcp_close_shutdown at core/tcp.c line 221
0x40225def: tcp_close at core/tcp.c line 288
0x4020332b: ClientContext::close() at C:\Users\Vasileios Magias\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\libraries\ESP8266WiFi\src/WiFiClient.cpp line 324
:  (inlined by) ClientContext::unref() at C:\Users\Vasileios Magias\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\libraries\ESP8266WiFi\src\include/ClientContext.h line 111
0x40203368: WiFiClient::stop() at C:\Users\Vasileios Magias\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\libraries\ESP8266WiFi\src/WiFiClient.cpp line 324
0x402033b8: WiFiClient::connect(IPAddress, unsigned short) at C:\Users\Vasileios Magias\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\libraries\ESP8266WiFi\src/WiFiClient.cpp line 324
0x4020667c: Print::write(unsigned char const*, unsigned int) at C:\Users\Vasileios Magias\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\cores\esp8266/Print.cpp line 38
0x40203a37: MySQL_Connection::connect(IPAddress, int, char*, char*) at C:\Users\Vasileios Magias\Documents\Arduino\libraries\MySQL_Connector_Arduino-master\src/MySQL_Connection.cpp line 67
0x40202a37: loop at C:\Users\Vasileios Magias\Documents\Arduino\TransmitterFullFinal/TransmitterFullFinal.ino line 114
0x402017fb: delay at C:\Users\Vasileios Magias\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\cores\esp8266/core_esp8266_wiring.c line 51
0x4020259c: setup at C:\Users\Vasileios Magias\Documents\Arduino\TransmitterFullFinal/TransmitterFullFinal.ino line 78
0x40206128: loop_wrapper at C:\Users\Vasileios Magias\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\cores\esp8266/core_esp8266_main.cpp line 57
0x4010070c: cont_norm at C:\Users\Vasileios Magias\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\cores\esp8266/cont.S line 109

I would really appreciate your help, and I hope that comes as soon as possible because I will have to present my thesis in about a month.

Thank you for your time and help,


Problem triggered by touching or moving wires implies that either the wires are loose, or that there are floating pins that are picking up noise from your hand being near them - but how that translates to an exception? Possibly there's somewhere in your code that you're making assumptions about what pin states and/or combinations thereof are possible, but not accounting for unexpected possibilities?

There are no floating pins, as I have the module constantly connected to a breadbord.
It starts get readings and transmitting them to the MySQL database, but as soon as even the tiniest movement happens it throws an exception and restarts. I cannot understand what is going on, and I urgently need someones help.

There are no floating pins, as I have the module constantly connected to a breadbord.



My apologies, I misunderstood the term.
Can these floating pins cause an error, such an exception which will make the device restart? If so, what can I do to resolve the issue?
I am a bit confused about this due to the fact that my system was working like a charm a couple of days ago, and now it has this behaviour even when I try to use another board.

If your code makes assumptions about the state of those pins, that could cause an exception when the pins are in an unexpected state. And if the power rail was the fiddlyconnection, it definitely could,

The fact that it used to work, and that you're using breadboard (which is notorious for problems with bad connections - I never use it for that reason*) both support the bad connection theory.

*I use "solderable breadboard" or "prototyping board" instead. I sell a bunch of it on tindie (originally because I wasnt happy with what I could buy) -

It seems that the whole thing was a sprintf() issue. The sprintf() was crashing the stack somehow.
However, could you advise me on how to change my code and execute the INSERT INTO statement without the sprintf() function? I am trying to import float variables into the database.

char INSERT_SQL[]="INSERT INTO test.testdata(AcX,AcY,AcZ,GyX,GyY,GyZ,R) VALUES (%f,%f,%f,%f,%f,%f,%f)";
char query[128];

How much does that all come to?

Did you use pull-ups or pull-downs?


char INSERT_SQL[]="INSERT INTO test.testdata(AcX,AcY,AcZ,GyX,GyY,GyZ,R) VALUES (%f,%f,%f,%f,%f,%f,%f)";

char query[128];

How much does that all come to?

Changet the query size to 256.
It works fine now but it performs slowly due to the sprintf() probably.Is there any way to make it work faster?