Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By xtal
#42361 I'm not using sql,, but have had intermittant stops...
I have found that if I page refresh every 8-10 seconds I get no stops ?
I've been unable to figure out just what's going on....
User avatar
By Alexandre Pinheiro
#42372
martinayotte wrote:Maybe you need to provide the link to that SQL library.


Hi! I'm using this library: https://github.com/ChuckBell/MySQL_Connector_Arduino

I was using an older library for arduino and experienced hangs in at maximum 15 minutes. Right now, with this library, It take longer to hang. In fact, checking my table I noticed that I started the test at 02:54:05 AM and it hung at 04:25:11 AM... so it was 1:31:06 up. A great improvement.


The test SQL routine is:

Code: Select allvoid ExecutaQuery() {

  float Valor = 3.21;

  char INSERT_DATA[] = "INSERT INTO dbname.dbtable (deviceid,val,data,hora) VALUES ('%s','%s',%s,%s)";
  char query[255];
  char ConvValor[4];

  MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
  // Save
  dtostrf(Valor, 4, 2, ConvValor);

  sprintf(query, INSERT_DATA, "ESP07-P2", ConvValor, "NOW()", "NOW()");

  Serial.println (query);   // this is just to show the query in serial monitor

  // Execute the query
  cur_mem->execute(query);
  // Note: since there are no results, we do not need to read any data
  // Deleting the cursor also frees up memory used
  delete cur_mem;
  Serial.println("Data recorded.");
}


and there's my loop:

Code: Select allvoid loop() {

  if (WiFi.status() == WL_CONNECTED) {

    if (digitalRead(PinoSwitch) == 0) {
         // do nothing
    } else {

      ExecutaQuery();
      cont = cont + 1;
      Serial.print("Count: ");
      Serial.println(cont);
      Serial.println("");

    }

    WiFiClient client = server.available();
    String req = client.readStringUntil('\r');
    client.flush();

    // Match the request
    int val;
    if (req.indexOf("/gpio/0") != -1)
      val = 0;
    else if (req.indexOf("/gpio/1") != -1)
      val = 1;
    else {
      client.stop();
      return;
    }

    digitalWrite(PinoSwitch, val);
    client.flush();
  }
  else {
    ConectaWiFi();
  }


So, the basically, when I set PinoSwitch to 1, it begins to send the data to sql. I'm using MariaDB SQL server in a virtual machine runnning Ubuntu Server.

I'm still learning things, so maybe a problem with my code.
User avatar
By Alexandre Pinheiro
#42373
xtal wrote:I'm not using sql,, but have had intermittant stops...
I have found that if I page refresh every 8-10 seconds I get no stops ?
I've been unable to figure out just what's going on....


Have you checked everything related to power? I had lot of issues with that. The 470 uF capacitor and the pullups solved my problem.