ChuckBell / MySQL_Connector_Arduino

Database connector library for using MySQL with your Arduino projects.
332 stars 133 forks source link

instance of the cursor in reboot.ino crash #33

Closed valentin4o closed 2 years ago

valentin4o commented 6 years ago

Hi, my name is Valentin. I use ESP8266 32M CP2102 NodeMCU programmed with Arduino Board Manager. It's SPI connected to RFID-RC522. I experience problem with the "Create an instance of the cursor passing in the connection" as in Listing 5: Simple Select Sketch written in _MySQL_Connector_Arduino_ReferenceManual.pdf It is also used in reboot.ino which I wish to implement in my sketch. I simplified it in order to be sure that very way of instance creation of class _MySQLCursor makes trouble in my scheme. The problem looks at the Serial monitor like:

tail 8 chksum 0x2d csum 0x2d

ets Jan 8 2013,rst cause:2, boot mode:(1,6)

ets Jan 8 2013,rst cause:4, boot mode:(1,6)

wdt reset

And this is my sketch:

/*
  MySQL Connector/Arduino Example : basic select
*/
#include<SoftwareSerial.h>

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <SPI.h>
#include <MFRC522.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>

char ssid[] = "TPLINK";//
char pass[] = "12151800712272";

IPAddress server_addr(192, 168, 0, 33); // IP of the MySQL *server* here
char user[] = "iduser";              // MySQL user login username
char password[] = "parpada"; // MySQL user login password

#define SS_PIN 2 //FOR RFID SS PIN BECASUSE WE ARE USING BOTH ETHERNET SHIELD AND RS-522
#define RST_PIN 15

WiFiClient client;
SoftwareSerial mySerial(8, 9);

MySQL_Connection conn((Client *)&client);

char query[] = "SELECT 1 FROM dual";

// Create an instance of the cursor passing in the connection
MySQL_Cursor cur = MySQL_Cursor(&conn);

void setup() {
  Serial.begin(115200);
  delay(10);
  mySerial.begin(115200);
  SPI.begin();
  //  while (!Serial); // wait for serial port to connect
  // Ethernet.begin(mac_addr);
  // Begin WiFi section

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

  // print out info about the connection:

  Serial.println("Connected to network");
  IPAddress ip = WiFi.localIP();
  Serial.print("My IP address is: ");
  Serial.println(ip);

  Serial.println("Connecting...");
  if (conn.connect(server_addr, 3306, user, password)) {
    delay(1000);
  }
  else
    Serial.println("Connection failed.");
}
void loop() {
  row_values *row = NULL;
  long head_count = 0;
  delay(1000);
  Serial.println("1) Demonstrating using a cursor dynamically allocated.");// Initiate the query class instance
  MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
  // Execute the query
  cur_mem->execute(query);
  // Fetch the columns (required) but we don't use them.
  column_names *columns = cur_mem->get_columns();
  // Read the row (we are only expecting the one)
  do {
    row = cur_mem->get_next_row();
    if (row != NULL) {
      head_count = atol(row->values[0]);
    }
  } while (row != NULL);
  // Deleting the cursor also frees up memory used
  delete cur_mem;
  // Show the result
  Serial.print(" NYC pop = ");
  Serial.println(head_count);
}

My suggestion is that trouble comes when instance is created outside of the setup() If it's inside setup() in the following way

// Initiate the query class instance MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);

then the problem does not exist. Could you please help me?

ChuckBell commented 2 years ago

Closed due to inactivity. Please open a new ticket if this is still relevant.