Classic Engineer’s Dilemma: IOT edition

There are many aspects of IOT/connected devices that appeal to me. I like looking at data, it’s interesting. I like automation, it can be fun, and convenient. Unfortunately there are many aspects of the current IOT landscape that are extremely unappealing. Universally, not just to me. The obvious solution then is to build my own :)

And that’s what I’ve started doing. Over the past five years, little by little, as I’ve wanted to do something, I’ve put something together, based on what I’ve got lying around. Originally I was making use of a web-based server to store and gather all my data, but got annoyed each time the internet cut off. In hindsight it’s not clear to me why I was experiencing so many connectivity issues at the time that I decided the best option was to host something locally, but that’s where we are today.

Server

The server is a Raspberry Pi. One that I had lying around, and I already had submitting temperature and air pressure data to my server. The server was just a shared hosting site with a few basic php commands to link up with a sql database. To provide some flexility, allow for some customization and make up for my large lack of web-dev experience, I chose to do it all in python. I’m using the CherryPy library to present a basic html web-interface that gives me a summary of what’s going on, and also handles all the data requests coming in from various local sources. If the internet goes down, it doesn’t matter, because everything is stored and presented on the local network.

Every time I look at this jumble of wires I tell myself that I should really tidy it up. But it’s working. And then I’d have to take it offline, and the risk of a short isn’t thaaat high. So what would I really get out of the exercise?

At times, like when I’m away from home and need to monitor some things, I can open another port and make it accessible from the internet, but this is off by default, mainly as a security improving effort.

What does it do?

As I worked on integrating the few sensors I had, I realised that this platform I was creating could do more than just save some data and show it to me. Well, more than just weather data. The platform running python made it easy to script all kinds of integrations. As I created more of these, I saw the value in having a standard task based framework on which to build all these integrations.

This basis of this is a config file which is read at startup, that reads what tasks need to be load and when they must run. After that, there’s nothing left to do. All the tasks run as scheduled, doing as they must. The main web-interface shows a status for each task, when it was last run, when its next scheduled run is as well as options to start and stop tasks or run them immediately.

Screenshot of the web-interface. Some very useful statuses in there

This scheduler approach is simple. It makes it easy to expand, and it all running on python means it’s easy for me to think of something I want done and implement it, as well as feed back all the results to the ‘server’ directly.

Connected items

So what all is included in my setup?

  • Raspberry Pi
    • The Raspberry Pi itself has a BMP180 and an MH-Z19 directly connected to it that it polls occasionally for the latest temperature, air pressure and CO2 levels in my office.
    • The CO2 sensor was pretty cheap, and accuracy isn’t amazing, along with its ‘auto-calibration’. But it still gives interesting results. It’s especially easy to see build-up in my office when the door is closed, as well as the drop every time the heating runs in the winter, bringing fresh air in. It’s certainly more accurate than this.
CO2 data. Big dip is when the furnace started up after ~12 hrs of not running on a cold (windows closed) but sunny day. Smaller spikes during day are from me closing my office door during a meeting
And some temperature data to go with it. I think the green spike was some sun shining on the sensor
  • ESP32
    • I ‘attended’ one of the Hackaday Remoticon sessions a couple years ago, where someone from DigiKey was presenting on an IOT platform (Machinechat) that they were selling. It did a lot of what I wanted, but the free tier was pretty limited, and why would I pay for something when I can do it myself for free ;) But I had the microcontroller and temperature sensor leftover, so just repurposed it to connect to my own server and feed temperatures from our downstairs.
  • ESP32
    • A more recent addition to the collection, and not related to a specific task, but just some extra code I’ve implemented for logging and status. When we moved into our rental, we were given one of the large garage remote controls. But, especially in the summer, my wife and I mostly cycle, and these remotes are bulky and annoying. We bought one of the smaller remotes, but my wife and I are often out separately. So now we can open the garage via Wi-Fi.
    • The ESP runs a basic web-server, just waiting for a request to open the garage door. I need to still install a sensor and feed this data back to the server. And if I’m doing that, I might as well monitor the temperature in the garage too…
You see a yoghurt container, I see the perfect container for a microcontroller, a relay and some LEDs

Other Tasks

Beyond the local devices actively pushing data to the server, there are a number of tasks that get run for ad-hoc items.

  • Outside Temperature
    • Lacking an outside connected thermometer, I instead choose to just pull data from the weather api every 20min.
  • Data plotting
    • Instead of learning how to plot data on the fly in a web-friendly format. I chose the lazy route I already had experience with, which is using python’s Plotly library to generate an interactive html graph. And because doing this on the fly on a raspberry pi can be very slow, I just do it every few hours, and supply the last generated one when requested. This can be improved. (UPDATE: I installed grafana, see screenshot at the end of the post)
  • NAS Wake/Sleep
    • I have a NAS downstairs, it can be a bit noisy. I only ever need to use it at night, which is also when it needs to be on to perform internet backups. So I get this task to use WoL to start it up in the evening, and an ssh command to put it to sleep in the wee hours of the morning.
  • Get external IP
    • At some stage I started setting up cloudflare to redirect a domain to my homeserver. I never completed this, but I did write a script to monitor our external IP address and update me via e-mail whenever it changed.
  • Strava
    • Earlier this year, Strava added Squash to their list of supported activities. I’d done a lot of squash activities, that were listed as Workouts. So I went about setting the record straight, using the Strava API to update all my previous activities that matched the criteria to be Squash. With all that done, I extended it to start adding weather data to my outdoor activites and ensuring that all my future squash activities get listed as such (Garmin don’t support Squash, so my activity still gets sent to Strava as a Workout, and then the script updates it). So now I have a web-hosted server that Strava notifies whenever I (or other people) complete an activity. My raspberry pi polls this server occasionally and runs scripts locally to determine if anything needs to happen, and then update activities as necessary.
You have to give whatever’s accessing the Strava API a name, thus StraWeer was born
  • Express Entry
    • At one stage we had an application in for Canadian Express Entry. They released new results usually once a week, but not at fixed times, and occasionally more than once per week. So I set this task to scrape the site where they posted the results and e-mail whenever it got updated with the latest results. Sometime after it was no longer applicable to us, the website was updated to no longer provide the information with a standard http request. So I stopped running it.

I started on this project a long time ago, and would often not look at the code for months or years, then update it to do something I wanted. It certainly has a lot of shortcomings, a lot of opportunity for improvement, and would do well to better implement a lot of things I’d consider good programming practice these days, but were not top of my mind at the time. That being said, it works. The fact that I only have to do something to it when I want to make an improvement is evidence of this. My biggest ongoing concern is when the Raspberry Pi’s SD card is going to pack up :D

And then

Most of the code that runs on the Raspberry Pi is available in the below repo. I’m still updating it with some of the Strava integration stuff, but I need to do some more improvements first

GCaw/HomeTaskServer

UPDATE: I installed Grafana, so pretty:

Mechatronics (in South Africa)

or Mechatronic Engineering, humourously (but incorrectly) referred to as Megatronics at times. In Afrikaans Megatronika or Megatroniese Ingenieurswese. What is it? What can you do with it? When I started studying I didn’t know, after 5 years I think I have a vague idea. So below I’m going to post what I know.

In it’s simplest form it’s a combination of Mechanical and Electronic Engineering. If I really don’t feel like explaining, I simplify it to robotics. This is certainly a large portion of Mechatronics, but by no means a limiting factor.

Mechatronics as a named profession is fairly new, but the idea has always been there. In the South African context, UCT have had an accredited BSc (Eng) Mechatronics course since 1997 (although how long it has actually been running is uncertain), NMMU a BEng since 2007 (first graduates) and Stellenbosch since 2005 [1]. Potchefstroom University (NWU) are apparently aiming to start a course in the next few years [2]. Although not offered in the BEng format, UKZN do offer Masters through their Mechatronics and Robotic Research Group [3]. [EDIT: added list of BTech degrees and Diplomas offered at the bottom of the post]

Mechatronics at Stellenbosch [2]

I completed my BEng Mechatronics at Stellenbosch University in 2011. The Mechatronics course was presented by the Department of Mechanical and Mechatronic Engineering in a four year course. The first two years were identical to that of those studying towards a BEng Mechanical. The first year course is identical for all engineering students. In the third and fourth years, the two courses still followed similar routes, with the Mechatronics course replacing several Mechanical courses with some courses presented by the Department of Electronic and Electrical Engineering. In third year these included Electronics and Computer System’s courses and fourth year Electronics and Electronic Design Courses. Losing out on some Strength of Materials and Thermo-Fluid Mechanics.

The department put it this way [6]

The most important difference between the mechanical engineering programme and the mechatronic programme is that mechanical engineers are equipped to develop mechatronic systems with existing controllers (computers, PLC’s, etc.), while mechatronic engineers are also equipped to develop specialised controllers (e.g. for embedded controllers) and the relevant electronics themselves.

At the time, the Head of Department felt that Mechatronics as an entity was still too new. Employers weren’t advertising for Mechatronic Engineers, and didn’t really know what to do with them when they did get them. This resulted in the close ties between the Mechanical and Mechatronic courses. I was often unhappy about this, having would of preferred more focus on the Electronics, but in the end it worked out. And the HoD’s opinions were/are valid.

When I chose Mechatronics, I didn’t know where I was going to work, I chose the course because it sounded interesting. It wasn’t until my final year that I found a direction to work towards. Course setups at different universities are going to be different, and will put emphasis on different subjects, that doesn’t necessarily make one better than the other. Either way you’re going to come out of it with a degree and a fair amount of knowledge. Most importantly though (and this is true for any engineering degree) is you’ll know how to learn.

I’m quite confident that specific things that I learn in my first year of work will be of more value to my career than a specific subject at varsity, but having struggled through several subjects, I know I can figure out most things that come my way. I know where to look and how to go about solving problems.

In my final year we were a class of 85 Mechanical/Mechatronic students, of which I’d say about 30-35 received their BEng Mechatronics in 2011.

Mechatronics at NMMU [2]

NMMU have a slightly different setup. Mechatronics is presented by the Mechatronics school of the Department of Engineering, the Built Environment and IT. Mechatronics is the only Engineering degree they offer. As such, first year physics and maths are taken alongside BSc students and after the first year, courses taken are aimed only at Mechatronics students. The format of the course is still identical to that of when it started giving a good balance of subjects. The University also offers an array of BTech degrees in other Engineering fields.

I’m currently pursuing my master’s degree at NMMU. Their 4th year BEng Mechatronics class has roughly 25 students in it and the 3rd year class about 30. First year applications are limited to 60, with the most recent 1st year class starting with 50 students. The Mechatronics department is currently sponsored by General Motors South Africa (who have a plant in PE) and also have close ties to the Volkswagen plant in Uitenhage.

Mechatronics in General

Mechatronics as a career is still finding its feet. Meaning many consider it a jack of all trades, master of none type of situation, and although the course may feel that way, it’s certainly not the end of the story.

Mechatronics isn’t a new field, it’s just finally been given a name. When you tell people you’re a Mechatronic Engineer they don’t know what that is. I had a month stint at a large production facility as part of vacation training and I was asked to choose between focusing on their Mechanical or Electrical divisions, eventually settling for a bit of time at each. But that’s how businesses in SA are structured. This will change.

Several Mechatronic Engineers that I know have taken up Automation maintenance posts. Nothing wrong with this, personally it’s not where I want to be. Contrary to this though, my first job next year will be in automation maintenance. I however plan to use this as a stepping stone into a design career.

Automation is fun, and whereas I am going into automation in a production sense, automation also relates to smaller and/or more technical situations. The recent landing of the Curiosity rover on Mars is a perfect example of Mechatronic systems. There are several elements here, from the automated landing system to the remote control of the device.

In the motor industry, systems such as traction control, ABS and ESP are all examples of Mechatronic systems. Heavily complicated systems that rely on the processing of data from sensors to enable control of actuators. As such a Mechatronic Engineer can make him/herself home in  many different industries. These include the Automotive, Aerospace, Manufacturing, Medical and Communications Industries.

Mechatronic Engineers can register with ECSA to become Professional Engineers [4]. The industry is governed by the South African Institute for Mechanical Engineers. I don’t see Mechatronics separating from this tree any time soon. The degree, being accredited by ECSA also means that the degree will be recognised internationally in many countries thanks to the Washington, Sydney and Dublin Accords [5]

So what do you do when you have your degree? You do whatever you want. You’ll find something. I’m not aware of any of my colleagues who are currently not pursuing a post-graduate degree or are employed. Not all of them are in Mechatronic specific posts. Some have opted for more mechanical orientated jobs, while others have gone entirely into areas such as electronic design or programming. And that’s one thing, a degree in Mechatronic Engineering in no way limits you. Very few engineering degrees will actually.

After re-reading what I’ve written, I think I’ve put forward some information relating to Mechatronic Engineering, but it’s still left fairly vague, maybe it’s just because none of us know what we’re really doing :)

"This is silly, of course. The enemy will be born in the Network"

From xkcd.com

 

A National Diploma in Mechatronics (for registration as a Professional Engineering Technician) can also be had from the following institutions [7]:

  • Tshwane University of Technology
  • UNISA
  • Cape Peninsula University of Technology

A BTech in Mechatronics (for registration as a Professional Engineering Technologist) from [8]:

  • Tshwane University of Technology
  • UNISA
  • Cape Peninsula University of Technology

and to reiterate, a BEng, or BScEng (for registration as a Professional Engineer) [1]:

  • Stellenbosch University
  • University of Cape Town
  • Nelson Mandela Metropolitan University

Note: Although other institutions may offer courses in Mechatronics, or Mechanical Engineering with a focus on Mechatronic elements, the ones listed above are the only ones recognised by ECSA for registration as a mechatronic professional. Information was correct at time of posting, but may have changed since.

There are also several Universities of Technology and FET Colleges which offer courses in Mechatronics. CPUT is one of these institutions. Another training institution is Umbilo Training Specialists in Durban. They are running a free training course, once a month where anyone can come to learn more and expand their knowledge. Checkout their page for details.

For some more reading and a very complimentary view with some poignant remarks have a read here.

As part of my degree at Stellenbosch University I completed a project which can be seen here.

As part of my master’s degree at NMMU I completed a project which can be seen here and here.

If you’re looking for bursaries, try this website.

If you have any questions, feel free to ask in the comments section.