-->
Page 1 of 1

Proper MySQL access from ESP8266

PostPosted: Mon Oct 22, 2018 11:13 pm
by mgiara
Hello!

Please feel free to move this if you feel there is a more appropriate sub.

I've migrated my project to the NodeMCU(ESP8266) and am successfully selecting from, updating, and appending to a MySQL database by means of Chuck Bell's library.

I'm curious if there are 'proper' chunks of code I can use as an example to base my functions off of.

ie:
to append a record to a table, I'm using something like this:
Code: Select allvoid sendRecord(String statement) {
  statement.toCharArray(INSERT_SQL, 300);
  bool recordSent = false;
  int connectFailed = 0;
  while (!recordSent) {
    if (conn.connect(server_addr, 3306, user, password)) {
      delay(500);
      cursor->execute(INSERT_SQL);
      conn.close();
      digitalWrite(D3, LOW);
      for (int i = 0; i < sizeof(INSERT_SQL); i++) {
        INSERT_SQL[i] = (char)0;
      }
      recordSent = true;
    } else {
      connectFailed++;
    }
    if (connectFailed > 10) {
      statusIndicateMySQL_not_connected();
    }
  }
}


This code regularly results in failure to connect, hence the while(!recordSent)

I haven't been able to find concrete examples that properly explain WHEN to close a connection object, or WHEN to destroy a cursor.

Also, the time delay that should be used between establishing a connection to the MySQL server and executing the INSERT statement.

Lots of little details like this are damaging the reliability of my code.

What is the most Proper way to manipulate a MySQL database from this MCU?

Re: Proper MySQL access from ESP8266

PostPosted: Thu Nov 01, 2018 4:58 pm
by mgiara
If there's no easy answer, would anyone be able to suggest good reading material that might point me in the right direction?
Or maybe a more active forum I could ask in?
I appreciate anything you can throw my way!!

Re: Proper MySQL access from ESP8266

PostPosted: Tue Dec 25, 2018 10:46 am
by kevireilly
Hey there. Is this a one-off personal project or is there a desire to get this device in to hands of many people?