September 2019 Update

New! We're moving to the new forum!

ALL new Blog posts will be on the forum.

Please join us there.

This Blog will no longer be updated...

Wednesday, September 4, 2019

MySql Connector for Arduino - what's going on?

Posted 4:15pm

First off, I'm going to quit doing a single post per day. It will just end up being a big list of dates, with no clue as to what's inside.  Perhaps you aren't interested in some aspects of the project, but you are in others, you'd never be able to just find what you want, so back to the old style of posts, each one sorta geared to a topic.

And this topic is a hot one right now for me.  I recently re-installed windows on my development machine, and in doing so, decided to reinstall all the software from the internet so I would have not only the latest versions, but clean copies of everything. I was having real problems with speed on the computer, it was at a crawl, so I didn't want to reinstall anything from a backup if I could avoid it.

When I started coding again, the ESP8266 would just keep rebooting, the watchdog timer was doing it, and for the life of me, I couldn't figure out why, until finally, I checked the MySql Connector GitHub page, and saw there was an update 8 days prior. That update was not present on my computer before the reinstall, but when I downloaded the library after my reinstall, it was. The patch was supposed to somehow provide better compatibility with ESP8266's but not for me :(  In any case, removing the modification solved the problem, and all was well.

Well, sort of, I am still having a weird problem with the connector, but ONLY in the new SensorModule code on the 8266.  Everything is fine up until it does a sensor scan, and it goes to the database to get a list of sensorId's to scan, and then load the configuration for each before scanning them.

The process is this:
Load list of SensorId's
Loop through SensorId's and load sensorCfg for the specific sensor
  - This is done in 2 parts due to the number of fields 
    - load part 1
    - load part 2
  - send scan request to Mega2560 to scan this sensor, pass configuration data required
  - receive results for scan
  - save results to database
Next SensorId

This is the only process which is causing problems...   there are three queries

fetch sensor id list
fetch sensor config part 1
fetch sensor config part 2

In all my code up till now, I always leave the database open between queries. If I leave it open all the time in the new Sensor Module code on the 8266, then it starts failing, miserably!

Just a note, every time it does a query, it will open a connection to the database if it isn't already open.

It will get the list of Id's the first time through, but when it fetches the config, they will return empty rows or no rows at all. randomly, although rarely correct results.

If I add a database close before each of these three queries, then everything runs smoothly, before and after the scans...

I've been over the code with a fine tooth comb, compared it against working code, and find nothing wrong.

I even started rewriting the Switch Module, and it has no such issues.  

I can do one of two things here, just leave the database close calls before these three queries, and not solve the underlying issue, whatever it is, or I can start fresh, rewrite the SensorModule 8266 firmware again from scratch, and see if it still happens. The second option is time consuming, and has no guarantee the results will be any different but at least I can verify the point at which the problems begin to show up.

I think it's going to be the second option...

Update: Sept 5, 2019 3:00am

Check out my next post!

Happy, happy, happy... It's working again!

No comments:

Post a Comment

Any comments deemed off topic or offensive will be removed