Home - SamsungResearchUK-IoT-Meetup/multimode_sensor_platform GitHub Wiki
This WiKi will get you up and running with the Multimode Sensor Platform. This is based on IoT sensors connected to the Pyboard D, running a Micro Web Server to communicate with the devices on the board. The project will also expose an Augmented Reality (AR) User Interface (UI) to the device. So if your mobile device supports Web XR then you should be able to follow along.
First things first. Before cloning the repo you should setup a python virtual environment so that nothing used in this project will inter-fear with anything else you are working on. If you are new to setting up python virtual environments go to our Python Setup Wiki page and follow the instructions.
To use MicroPython you don't have to install any IDE. There is also a guide to getting some tools installed and setup with your pyboard. The pyboard setup guide takes you through running the repl, installing RSHELL, copying python files and running code directly from the repl. Here is the Micropython Setup guide. You can also use minicom or picocom, if you are more familiar with these tools.
The hardware needed for the Multimode Sensor Platform is based on the Micropython Pyboard 'D' and comes in 3 components.
- The 'Brains' unit which contains the microprocessor, flash, ram, reset button, test button, LED, antenna, WiFi module and connector.
- The DIP switch connects the microprocessor to the tiles via an I2C bus. This allows the brains unit to interface to the tile sensors and PIN out's for other types of sensor for testing with.
- The 'tile' sensors. Our tile sensor contains a temperature, humidity and LUX light sensor.
To find out more about the hardware follow the links below:
- MicroPython pyboardD PYBD-SF2-W4F2 (will work with SF3 and SF6 as well)
- MicroPython adapter WBUS-DIP68 for connecting external sensors
- MicroPython SensorTile TILE-SENSA with temperature, humidity, light and RGB-LED
- Micro-USB to USB cable for connecting your pyboard to your machine
- To add more sensors to the platform a PIR-Sensor can be added to the hardware setup need a pic here
Before you start setting up the microwebserver environment make sure your pyboard runs at least firmware version v1.10. To find out which version is on your pyboard you can follow these steps:
First make sure which firmware version runs on your pyboard D. To do this, you can type this command into the REPL:
import os
os.uname()
You should see an output like this
(sysname='pyboard', nodename='pyboard', release='1.10.0', version='v1.10-182-gd43a2d351 on 2019-01-)
The release will tell you which firmware is currently running on the pyboard. Check that your firmware supports threading. To do this try and import _thread on the REPL prompt:
>>> import _thread
If you get an error with ImportError: no module named '_thread' continue with the section on updating your firmware.
If the firmware which runs on the pybaord doesn't support threating yet, you can download this firmware image and install it onto your pyboard following these instructions: Firmware-upgrade
The MicroPython pyboard D doesn't need to be put manually into the dfu mode for upgrading the firmware. Simply type pyb.bootloader() into the comand line of your console and follow the steps mentioned bellow.
pyb.bootloader()
Your pyboard D is in dfu-mode, when you see the RGB-LED flashing red every second.
To get you up and running with the Mulitmode sensor platform you need to do the following:
- clone the repo and navigate to the /microserver folder;
- copy files to the board;
- restart the board to ensure the new files are read by the microcontroller; and
- import the start.py file from the repl.
The steps are explained in detail:
Clone this repo into your work environmnet:
$/> git clone https://github.com/SamsungResearchUK-IoT-Meetup/multimode_sensor_platform.git
You should see folders within the multimode_sensor_platform/ directory for assets, docs, firmware, microserver and tests.
If you have installed rshell you can simply copy the files from the /microserver folder into /flash/. If you are doing this from your terminal you need to copy the files into /media//PYBFLASH/
Your Pyboard should have the following files on it:
/media/<USER NAME>/PYBFLASH$ ls -l
total 8
-rw-r--r-- 1 366 Jun 7 15:17 boot.py
-rw-r--r-- 1 27 Jul 10 16:49 main.py
-rw-r--r-- 1 2786 Jan 1 2015 pybcdc.inf
-rw-r--r-- 1 1727 Apr 17 16:27 README.md
-rw-r--r-- 1 698 Mar 3 2019 README.txt
Copy the following folders to the Pyboard:
- drivers: (drivers for the sensors being used)
- libraries: (at the time of writing the logging library)
- web: (microweb server files)
- wifi: (a small wifi driver to reconnect the pyboard in bad wifi areas)
- www: (all web files i.e. javascript, css and html files)
Copy the urls.py and start.py file to the pyboard. At the time of writing the sensor_manager.py file is not being used or integrated to the platform. Ensure you type the sync command to force files to write to file system if you are using Linux e.g.
$/> sync
Either press the restart button on the board or unplug and re-plug the device. Your pyboard folders should now look like this:
/media/<USER NAME>/PYBFLASH$ ls -l
total 34
-rw-r--r-- 1 366 Jun 7 15:17 boot.py
drwxr-xr-x 2 1024 Oct 10 2019 drivers
drwxr-xr-x 3 1024 Oct 10 2019 libraries
-rw-r--r-- 1 27 Jul 10 16:49 main.py
-rw-r--r-- 1 2786 Jan 1 2015 pybcdc.inf
-rw-r--r-- 1 1727 Apr 17 16:27 README.md
-rw-r--r-- 1 698 Mar 3 2019 README.txt
-rw-r--r-- 1 8482 Oct 10 2019 start.py
-rw-r--r-- 1 11553 Oct 10 2019 urls.py
drwxr-xr-x 2 1024 Oct 10 2019 web
drwxr-xr-x 2 1024 Oct 10 2019 wifi
drwxr-xr-x 2 1024 Oct 10 2019 www
First open the start.py file in your favorite text editor and replace the line 104:
status = myWifi.connect('Samsung-test', 'test1234')
with your own WiFi SSID nad WiFi password. Make sure you save the file to the board and restart your pyboard. Now open your pyboard REPL and import start.py. You should see the following:
$/> repl
Entering REPL. Use Control-X to exit.
>
MicroPython v1.11-328-gd96391a-dirty on 2019-09-23; PYBD-SF2W with STM32F722IEK
Type "help()" for more information.
>>>
>>> import start
WiFi Manager bringing up wlan interface.
Trying to connect to SSID: Samsung-test
Retrying to connect. Trying 0 of 5's
Retrying to connect. Trying 1 of 5's
Retrying to connect. Trying 2 of 5's
WiFi Manager is now monitoring the connection
We have a WiFi connection. Bringing up web server
To disconnect first import all objects from start.py: '>>> from start import * '
Then to disconnect do: '>>> myWifi.disconnect()' at your repl prompt
DEBUG:microWebSrv:New thread started for Function: <bound_method> and with arguments: ()
*** Server now running! ***
>>> DEBUG:microWebSrv:Server Process is now started. About to accept SOCKET incoming connections
Connected on IP: 192.168.43.127
Please note, the IP address will be dependant on your WiFi hotspot. To check the web server is up and running open your browser (which must be on the same WiFi hotspot) and navigate to port 8000. e.g. on this pyboard instance I would navigate to the following URL: http://192.168.43.127:8000/
You can easily stop the web server by calling the Stop method. To do this from the REPL:
>>> from start import srv
>>> srv.Stop()
You will notice that the WiFi manager is still monitoring your WiFi connection. This can be annoying, to stop it monitoring you can ask it to disconnect:
>>> from start import myWifi
>>> myWifi.disconnect()
(True, 'Wifi connection disconnected')
>>> Wifi Manager has stopped monitoring the connection
Next move onto the Sensors Page to find out how this works.