Nodemcu mysql connection library error

Hi I'm trying to connect my node mcu board and aws database server.
I'm using

#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>

these two library for the connection.

My code is as follows.

#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <MySQL_Connection.h> 
#include <MySQL_Cursor.h> 
#include <stdio.h>

String ssid = "secret";
String password = "secret";

String inputString = "";         // a string to hold incoming data
boolean stringComplete = false;  // whether the string is complete
//: and % was set from the transmitter node for the eage of data separation
char start_val = ':';
char end_val = '%';
int start_pos = 0;
int end_pos = 0;

int temp = 0;
int humid = 0;
int air = 0;

SoftwareSerial mySerial(D2,D3);


IPAddress server_addr(secret);
char user[] = "secret"; 
char password_[] = "secret"; 
WiFiClient client;
MySQL_Connection conn(&client); 
MySQL_Cursor* cursor; 
char INSERT_SQL[] = "INSERT INTO dht11.smartcity VALUES (7,8,9,10)"; 

void setup() {
  Serial.begin(115200);

  mySerial.begin(115200);

  WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) {
         delay(500);
         Serial.print(".");
    }
    
    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println(WiFi.localIP());


   
   
    Serial.print("Connecting to SQL... "); 
if (conn.connect(server_addr, 3306, user, password_)) 
{ 
  Serial.println("OK."); 
  } 
  else { 
    Serial.println("FAILED."); 
    }
    delay(5000);

    cursor = new MySQL_Cursor(&conn); 
   

}

void loop() {
  if (mySerial.available()){
    while (mySerial.available()) {    
    // get the new byte:
    char inChar = (char)mySerial.read();
    
    //Serial.println(inChar);     
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    }
    else
    // add it to the inputString:  
      inputString += inChar;
  }
    
    if (stringComplete) {
    start_pos = inputString.indexOf(start_val);
    end_pos = inputString.indexOf(end_val);
    String data_string = inputString.substring(start_pos+1, end_pos-1);
    Serial.println(data_string);
    String temperature = data_string.substring(10, 15);
    String humidity = data_string.substring(16, 21);
    String air_auality = data_string.substring(22, 24);

    temp = int(temperature.toFloat());
    humid = int(humidity.toFloat());
    air = int(air_auality.toFloat());
    Serial.println(temp);
    Serial.println(humid);
    Serial.println(air);
    
    inputString = "";
    stringComplete = false;
  }
 
  sprintf(INSERT_SQL, "INSERT INTO dht11.smartcity VALUES (now(),%d,%d,%d)",temp, humid, air); 
  if (conn.connected()) {
    Serial.println("connected to databases");
    cursor->execute(INSERT_SQL); 
  }
 
}
}

void Wifi_connect() {

  Serial.println("---------------------------------------");
  Serial.println(ssid);
  WiFi.begin(ssid, password); 

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println();
  Serial.println("Wifi connected!");
  Serial.println("\nConnected to network");
  Serial.print("My IP address is: ");
  Serial.println(WiFi.localIP());
}

/>
And when I run the code, they got uploaded well, and the wifi connection also works,
but there are some strange errors appearing on the serial monitor.

The error is as follows.

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Exception (28):
epc1=0x40203260 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000049 depc=0x00000000

stack>>>

ctx: cont
sp: 3ffffc30 end: 3fffffc0 offset: 0190
3ffffdc0: 00000055 3fffc6fc 00000000 3fff0634
3ffffdd0: 3fff0634 2c9f0300 00000001 402032b3
3ffffde0: 401034fc 00000000 3ffe85f6 402032a0
3ffffdf0: 40205060 00000030 0000001c 4020781c
3ffffe00: fffffffc 3ffeea0c 224a85b7 402288a5
3ffffe10: 00000000 00000000 00000000 3ffee5fc
3ffffe20: 402077e8 3ffe85f6 3ffee718 40203bf0
3ffffe30: 3fff0634 3ffee718 00000000 40203c14
3ffffe40: 3fff0634 3ffee718 3ffee718 40203ca4
3ffffe50: 3ffeed4c 00000000 00000000 40203667
3ffffe60: 00000000 00000000 40100625 4021631e
3ffffe70: 000002c3 000002c3 3ffe8620 40100d4f
3ffffe80: 00000000 4bc6a7f0 051eb851 00000001
3ffffe90: 3fff083c 00000020 3fff083c 40100f2e
3ffffea0: 3ffee190 00000000 00000000 401008fc
3ffffeb0: 000019d1 3ffee8e0 0000012c 40216d84
3ffffec0: 00000282 00000282 3ffe8620 40100d4f
3ffffed0: 3ffe85f6 00000000 3fff0314 3ffe85f6
3ffffee0: 00000000 0000002c 00000020 3ffe85f6
3ffffef0: 00000000 0000002c 3ffee5fc 402037aa
3fffff00: 00000007 3fff0634 3ffee5fc 4020351e
3fffff10: 0000004a 00000020 00000001 00000003
3fffff20: 00000001 3ffee7f0 3ffee5fc 40202f02
3fffff30: 40207d10 d3a52703 3ffee7f0 40203980
3fffff40: 3fffff90 00000cea 3ffe8602 3ffe85f6
3fffff50: 00000000 40202c5c 3ffee7f0 40203c14
3fffff60: 2719a8c0 00ffffff 0119a8c0 3ffee87c
3fffff70: 00000000 3ffee5fc 3ffee7f0 40201129
3fffff80: 00000040 00000000 feefeffe feefeffe
3fffff90: 40207d10 d3a52703 feefeffe feefeffe
3fffffa0: 3fffdad0 00000000 3ffee868 40204ac4
3fffffb0: feefeffe feefeffe 3ffe861c 401011e1
<<<stack<<<

these error appears with same interval(the delay time I set).

Is there anyway to solve this problem?
Or does the Nodemcu 12e boards doesn't fit with Adruino's Mysql connection library??

Help me anybody

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.