week9

This week's assignment is to make an HTTP/S client on a microcontroller, and connect it to a server on Glitch or DigitalOcean.I try to use Nano nano 33 IoT board to send DHT22  sensor data into a web server and display the data in a web page.

Here are my rough system diagram. 

ConnectedWeek9.png

For my server side, I sent the sensor data (I accidentally broke my dht12 sensor before and it couldn't read the data properly, so I used the random function instead) from the sensor with http POST  request.  Then when the server received the data, i store them into database.

( I watched the tutorial of Daniel to save and fetch data ). And in the web side, I 

get the data from database with GET request. But when I try to only display the latest data from the database, I find it cannot work by using data[data.length-1] ,since that every time when new data store to database, it is disordered. So i just fetch the latest data from the my response method.

截屏2021-04-04 下午4.57.06.png

Also I use setInterval and setTimeout function  every 3 seconds to reload my textContent so that it can display the latest data of sensor.

截屏2021-04-04 下午4.30.59.png

Currently the historical data displayed is displayed out of order, I haven't solved the problem of arranging the data in the order of the timestamp.

截屏2021-04-04 下午4.31.21.png

I host my server on DigitalOcean.  the host link