For our semester project we had to realise something with Arduino that uses:
USB (serial) communication
Python to get the data from the serial port
MySQL to store the data
HTML (or some other accepted Web tech) to display the data
We were planning to use 2 different DHT sensors (DHT-11 and DHT-22) along with a MQ2 Smoke/Gas detector and the idea was that the DHT-11 would be placed in simulated room A and the DHT-22 and MQ2 in room B.
Maybe I'm getting this all wrong but the Arduino just spews out a long string of 4 digit numbers I'm not sure would make any sense when send to a SQL table and I'm also unsure if there is a possibility to differentiate what number comes from which sensor?
It won't. Your python code, running on the PC, will need to read those numbers and format them into SQL INSERT or UPDATE statements and send them to the database.
I would say that is a necessity! Your Arduino code will need to print something before the numbers to indicate which sensor they are coming from.
Your Arduino code seems to be using some potentially unreliable method of sending the sensor values from the different sensors every 2s, or 4s(?) or 0.5s. Why not simplify this and send the values from all 5 sensors together every 5s?
For starters, just add another print() statement before the values that specifies the room/sensor. Also look at the println() function which will add a newline after the data.
It won't. Your python code, running on the PC, will need to read those numbers and format them into SQL INSERT or UPDATE statements and send them to the database.
Ok, need to check my Python script again then.
Your Arduino code seems to be using some potentially unreliable method of sending the sensor values from the different sensors every 2s, or 4s(?) or 0.5s. Why not simplify this and send the values from all 5 sensors together every 5s?
I was trying to get some separation between the data blocks which obviously didn't work.
I'll simplify the Code as every 5 or so seconds is more than adequate.
Check out the Blink Without Delay example in the IDE (File->examples->02.digital->Blink Without Delay) to learn how you typically keep track of elapsed time so you can do things every X seconds rather than hoping you hit millis() at the exact right time.
That is the unreliable thing that I and @blh64 mentioned. Reading sensors can be slow, and could cause your sketch to miss or skip the exact millisecond that is a multiple of 5000. Follow advice from @blh64 for a reliable way to do the same thing.
Also, while having the words "Office:" and "Server:" appear on the serial monitor is helpful for us humans, it is unnecessary for your python script and will make parsing the text from the Arduino more difficult. Just separate each value with a comma and keep the values in the same sequence so that your python script knows which value is which by its position in the sequence.