RoadTest: MaaXBoard Single Board Computer + Accessories
Author: ss_shrenik
Creation date:
Evaluation Type: Development Boards & Tools
Did you receive all parts the manufacturer stated would be included in the package?: True
What other parts do you consider comparable to this product?: The Weston Desktop Environment was little laggy and heating the board for regular operation. Moved to xface desktop it didnt have same issue.
What were the biggest problems encountered?: 1. My Pi camera module didn't work with MaaXBoard. Could capture video, seems compatible driver not present. 2. GPIO should not be made root accessible, it limits the use of this board for end IoT applications
Detailed Review:
Finally, due to lockdown in the whole country, I received this board almost two months late. Never the less, I could get time to work on it. Thanks, Element14 for shipping the board in such tough situations.
Anyway, the moment I saw this board's specification, it was clear that this is a powerful contender for Raspberry Pi, but more powerful. Hence I thought to implement the Edge IoT application. Edge IoT meaning, the processing is done at the Edge and not on the cloud.
The concept:
1. Bring up the Mozilla webthings Gateway on MaaXBoard
2. Use of OpenCV to demonstrate the capability of the board. Of course, a simple PIR motion sensor could do the thing, but I wanted to understand potential hence the OpenCV based motion sensor .
Now the real part:
1. Setup
Sure, for above I wanted to start with Debian image. The Getting started document was easy enough to do this. When the board boots up, by default it comes with Weston Desktop Environment. Feature-wise, its good but I found it little laggy and also heating CPU for normal operation(Not sure if it's only for my board). And Since i wanted to do Image processing stuff i didn't want extra performance overhead on the board, so i decided to go with headless Linux way. There are some really good blogs to do the same below are the links for same. Ohh by the way, i also went for headless setup to install tensorflow on MaaXboard.
https://www.hackster.io/monica/getting-started-with-maaxboard-headless-setup-24102b
https://www.hackster.io/monica/setting-up-tensorflow-on-the-maaxboard-f33cbc
2. Mozilla Webthings Gateway
When I started to look for how to setup this on any linux board, I started with process of compiling it onboard(to have some customization) https://github.com/mozilla-iot/gateway. But some dependencies made it difficult to compile and then I started looking out for pre-built binaries for ARM64 and found one. For webthings, you need nodejs, and then with dpkg you can install webthings right away.
nodejs install /home/ebv/shrenik/webthings/node-v12.18.2-linux-arm64/bin sudo dpkg -i webthings-gateway-debian-buster-arm64.deb
Once you install this, the webthings service will start on MaaXboard and then you can do initial setup and then login from browser to start with Mozilla webthings. Details can be found on https://iot.mozilla.org/
in my case below does the thing
https://<local ip>:8080
You can start with some virtual things on the gateway to understand its operation. To try next, i wanted to control GPIO of MaaXBoard from webthings. For this, webthings comes with a plugin called "Run a Program" where you can simply add your program path to execute. Was easy, isn't it?. Adding, a program was easy, but I got a problem in toggling GPIO, because they were only root accessible and there was no User group for GPIO which is present on Raspberry PI. Its a small thing but I think should have been made available for the user. I tried below in my script but still, for webthing user we could not access it.
SUBSYSTEM=="leds", PROGRAM="/bin/sh -c '\ chown -R root:leduser /sys/class/leds/usr_led/ && chmod -R 770 /sys/class/leds/usr_led;\ '"
3. Webthing
To start with real HW webthing, I simple used NodeMCU board to create LED webthing to connect with Mozilla webthing. Imp note here, make sure you use webthings lib v0.4.1 for this, otherwise you will end up getting 400 error while adding the thing in your Gateway. Not giving details of how to add thing, as its very well explained over official website.
4. OpenCV on MaaXBoard
This is pretty straighforward
apt-get install python3-opencv
and i could also get frame view on remote, most important thing. Anyway i was using RDP for actual operation but Xserver could also work for me over ssh.
5. Back to concept -> implementation
All above was basically preparation for the concept, what i wanted to do is to implement a simple motion detection in opencv and then send the update to Mozilla webthings gateway.
Motion detection was fairly simple and there are many examples online if you need to look at
# calculate st dev test _, stDev = cv2.meanStdDev(mod) if stDev > STD_DEV_THRESHOLD: cv2.putText(mod,"Movement detected", (50, 50), font, 1, (255, 0, 0), 1, cv2.LINE_AA) motion_status = 1 else: cv2.putText(mod, "No movement!!", (50, 50), font, 1, (255, 0, 0), 1, cv2.LINE_AA) motion_status = 0
Now we got the movement or no moment status captured in motion_status variable, next thing is to pass it to webthings gateway.
OpenCVMotionSensor for webthings
For this i went through one of the SingleThing webthing python example which mozilla has provided over their github repository. It was tricky though to search property and values needs to be added for motion sensor, but could found it. Then I wrote below class for OpenCVMotion sensor, which could detect as std motion sensor for webthings
class OpenCvMotionSensor(Thing): def __init__(self): Thing.__init__( self, 'urn:dev:ops:my-maaxboard-opencv-motion-sensor', 'OpenCV motion sensor', ['MotionSensor'], 'On device image processing for motion detection on MaaXBoard' ) self.motion = Value(0) self.add_property( Property(self, 'motion', self.motion, metadata={ '@type': 'MotionProperty ', 'title': 'MaaxBoard Opencv Motion', 'type': 'boolean', 'description': 'Whether the motion detected', 'readOnly': True, }))
Below are screenshots of the instance created and detected in Mozilla webthings gateway. The thing light is NodeMCU LED i mentioned about earlier
Till now, I could implement both of them separately, now it's time to combine them into one module to complete the task. Here I faced one problem, that Mozilla webthing acts as blocking server and Motion detection is also needed to be done continuously in a while loop, so I thought to use Mozilla webthing in thread and OpenCV program as normal while loop.
def run_server(name): asyncio.set_event_loop(asyncio.new_event_loop()) # Create a thing that represents a opencv motion sensor sensor = OpenCvMotionSensor() server = WebThingServer(SingleThing(sensor), port=8888) try: logging.info('starting the server') server.start() except KeyboardInterrupt: logging.debug('canceling the sensor update looping task') sensor.cancel_update_level_task() logging.info('stopping the server') server.stop() logging.info('done') #create thread for webthing server x = threading.Thread(target=run_server, args=(1,)) x.start()
To control nodemcu LED when motion is detected, I added a rule in Webthings gateway as below
With all of above actions CPU load was between 20-30% on an avg
See it in action
Conclusion:
1. Mozila webthings gateway and OpenCV+Tensorflow make this device capable for Edge processing application
2. On board Flash could improve performance further. We should have one version with this.
3. GPIO should be accessible to non root users as well.
4. This is a well-documented platform, makes is equally easier if not better for Raspberry Pi users.
5. On chip Cortex-M4 makes it context aware Low Power device, as this M4 can be used to detect Context and Application processor doesn't need wakeup for context recognition. (I want to try this)
6. Choice of Debian and Android OS provides more flexibility.
Future scope:
My plan is to use tensor flow further to explore full potential of this platform. Will keep you posted. Till then enjoy..!! Stay safe, stay healthy.
Complete code can be found below
Top Comments
ss_shrenik nice little overview. Well done.
~~Cris