Sensor Page - SamsungResearchUK-IoT-Meetup/multimode_sensor_platform GitHub Wiki
By now you should have the default page up and running on your microweb server. This section describes the sensor page displayed on the web server. Details are provided on the sensors in the sensor page.
The sensor web page is linked from the main index.html. However you can get to the senor page from http://(micropython IP address):8000/sensors/. You will see a page similar to the one below:
If you have the tile sensor on the board you should see values for:
- temperature
- humidity; and
- lux.
From your terminal window you will also see output from the pyboard printing sensor data to the screen:
>>> Connected on IP: 192.168.43.127
INFO:microWebSrv:Accepted 'client': <socket state=3 timeout=4000 incoming=0 off=0> and 'client address': ('192.168.43.214', 58538)
INFO:microWebSrv:Processing request HTTP Method: GET Path: /sensors Version: HTTP/1.1
** Current temperature: 24.84589
** Current humidity: 51.99585
** Current lux: 0.21
** Current time: (2019, 10, 11, 18, 34, 8)
DEBUG:microWebSrv:Server writing response via route handler. Response code: 200 Content Length: 597
The web page is rendered in urls.py in the function def _httpHandlerSensorsGet(httpClient, httpResponse).
You will notice a python decorator which takes a URL path (/sensors) and serves HTTP GET messages by default. The HTML content is populated with docstring triple """. The '$s' is substituted by the method calls after the docstring.
<body>
<h1>Sensors Page</h1>
Current Time: %s
<br />
PIR Sensor: %s
<br />
Doppler Radar: %s
<br />
Temperature Sensor: %s
<br />
Light (LUX) Level: %s
<br />
Humidity Level: %s
<br />
LED Light: %s
<br />
</body>
</html>
""" % (current_time, pir.pir_total(), microRadar.mr_total(), humidityTemperature.temperature(), humidityTemperature.humidity(), lightLevel.lux(), "N/A",)
At the top of the function you will see the sensor object method calls being used to get sensor data:
temperature = humidityTemperature.temperature()
humidity = humidityTemperature.humidity()
lux = lightLevel.lux()
current_time = time.localtime()[:-2]
You will notice that no sensor data is populated for the Doppler radar or PIR sensor. A TODO Maybe! So for temperature, the temperature method is called on the humidityTempearture object. Creation of the tempeartureHUmidity object happens at the start of the urls.py file like so:
i2c = machine.I2C('X')
humidityTemperature = HDC_Sensor(i2c)
The first line creates an I2C object which knows how to use the I2C bus. This is passed into HDC_Sensor when instantiating the HDC sensor.
To find out more about the sensor, how they connect, work and other methods that can be used with the sensors go to the detailed sensor page
The next logical section is to move onto Augmented Reality which is also linked from the main index.html file. On the browser the URL path is simple /AR. You can get to the WiKi page for Augmented Reality here