Smart Poi

I made an LED indicator for my portfolio site

Job hunting is tough – I’m busy until February 2022 but already feeling anxious about finding the next gig. That’s why I wanted to give myself a bit of an incentive – a visible indicator of success. I decided that whenever someone visits my portfolio site, I wanted an LED to light up. Read on to find out how I did it (using Flask, http requests, and an ESP8266)

Self Hosting

I recently had a bad experience with an online service shutting down on me – had a bit of a rant about it, although in the end it wasn’t too serious – but I am now determined to do self-hosting wherever possible *disclaimer: my current work project is hosted on Google Cloud, and I’m using Firebase and push services for some Android apps also.

The Flask api

The first step was to create a simple Flask api to facilitate tracking of site visits. This is based on this minimal flask api template on GitHub. I used a simple global variable to keep track of website visits because I’m doing this in my spare time and because it works fine – and I love boolean switches. Here is how it works in one simple gif:

Think of the hand as a visitor to my site, and the “switcher offer” is the ESP8266 at my home checking the api (the switch)

HTTP request from resume site

Since I am learning React my portfolio site was a good way to have another look at the framework. I used this single-page React resume site template as a base, adding my own details and an http request to the Flask api endpoint on load.

ESP8266 code

I used the basic http requests example with my own api details, and added in EEPROM code to record the incrementing number of visitors to persistent memory. The ESP8266 module checks once per second with the api whether there has been a new visitor to my site. If there has, the built in LED on my D1 Mini switches on. Although I have mostly moved over to using PlatformIO, for this very simple sketch I used the Arduino IDE.

Deployment

Like I said, this one is self-hosted. I’m using Digital Ocean droplets, which are a fixed cost of 5 dollars per month, for as many sites and services you can cram on there (trust me, it’s a lot). The React site was surprisingly simple to deploy, just build, copy the build folder and point Nginx at it. Flask is a little bit more complicated, compared to how easy it would be on Google Cloud, for example, but a few config files are really not too much to handle.

The result

Whenever someone visits my website, the LED lights up. Simple as that. And I can plug in and check how many visitors I have had. I’m hoping that one of those visitors will like what I do enough to hire me next year!

Visit my site https://devsoft.co.za to light up my visitor tracking LED.

Potential improvements

If I was making this into a product, I would certainly upgrade the Flask API to include a database to keep track of the number of visits, rather than doing this on the ESP8266 EEPROM – which maxes out at 255!* Obviously this could include a web interface for accessing the information, I could log the times… But most of this tracking stuff has been done already – analytics for websites. Perhaps the ESP8266 could pick up some of this information and display it on an LCD screen. A flask service for accessing Google Analytics from Arduino perhaps? Let me know if this is something you are interested in!

Also, proper authentication – if this wasn’t just for myself… JWT, rate limiting, CRUD endpoints and a web interface to change LED behaviour.

And maybe an RGB LED would be nice, then I could add in some of my other websites, in different colours!

*apparently the Arduino EEPROM library works differently on ESP8266 – ignore that part of the code, I need to update it (the counter still increments while the module is plugged in, though)

Goodbye Fritz.ai, goodbye proprietary online services

Fritz.ai “sunsetting services”:

Fritz.ai is (was) a cool service for, in particular, making machine learning apps easily. The marketing hype was slick, and they roped in a lot of developers to help them push their service to many devs, particularly in the Android space, with paid articles on medium, and on their website.

First of all, I have to say, I take full responsibility for this, and I don’t blame anyone at Fritz.ai for my problems, it’s their service, they can do what they want – but I wasted a lot of time learning how to use their api, publishing my own (unpaid, no affiliation) posts about the service, and using it in apps published to the play store. Their business model seemed clear – free to use but once you reach a threshold you have to pay for the service. Seems legit, probably was legit.

My Android apps didn’t take off, so I never reached that threshold, never ended up paying for anything at all – but I did waste a lot of time making apps using a service which is getting switched off at the end of the month (August 2021). In other words, my apps are going to be switched off, for the (very) few users who did install them. If I want to continue with these apps, they will need a substantial re-write. In many ways I’m lucky that the apps were not successful!

So I have learned a valuable lesson here:

The lesson is: don’t trust your work to “flashy” or “new” products and services. I could have spent a week back then just learning the ins and outs of tensorflow on android, and done it myself. Just because I’m lazy doesn’t mean I’m stupid. Lesson learned.

*here is the full unedited email for those who are interested – I still don’t see any mention of this on their site or blog:

We’re Sunsetting Fritz AI


Service will end August 30, 2021


Hello,

This email is to let you know that we will be sunsetting the Fritz AI mobile machine learning platform, effective August 30, 2021.

What does this mean for my account?

As always, any custom trained models, datasets and annotations are exportable. Please see this documentation for how to export datasets and models.

After the sunsetting date, access to the Fritz AI SDK, webapp, API, and hosted services will be discontinued. All models, datasets, and resources stored in Fritz AI will be removed.

For mobile apps, the Fritz SDK will lose API connectivity, but on-device model inference should continue to function. Regardless, we advise you to update your apps, removing the Fritz SDK and models.

Snapchat lenses do not depend on the Fritz SDK nor API, and lenses should continue to function as before.

Why are we doing this?

Fritz AI’s mission has been to make the power of machine learning solutions available to mobile developers. When we started in 2017 there were few options available. In the following years there have been many great entries to the market such as ML Kit, Create ML, MediaPipe, Lobe.ai, MakeML, Firebase ML, and more. Now there is a mature ecosystem of tools, including free and open source options.

We understand that this decision will have significant consequences for our community, but we truly believe the wide range of incredible tools and resources out there will empower you to continue on without Fritz AI.


Sincerely,

Dan & Jameson
Founders, Fritz AI

Magic Poi Magic

SmartPoi is re-branding as MagicPoi

Magic Poi online portal
Magic Poi login screen

New stuff:

Check out http://magicpoi.circusscientist.com to sign in to the new experimental online portal. A place to upload and share poi images. I am working on a way to get the images directly onto your poi, straight from the server. If you have access to a linux terminal, you can test this using curl: curl http://magicpoi.circusscientist.com/api/get-filenames for a list of files in .bin format. Or just visit the link here to see all the files listed in a browser: http://magicpoi.circusscientist.com/api/get-filenames

To download a specific file you need to send a get request to the api like so: curl -X GET http://smartpoi.circusscientist.com/api/output/e5d2dd82008b343354a0f37ab435c32aab9dc132.jpg.bin -O -J -L $url – which will download the file and save in the current directory. Now that the api is set up, I have working poi code to get and display the images directly from the poi, so will be sharing this on GitHub once it is cleaned up a bit.

Oh and I finally managed to get the images to work right-side-up! So no more need to rotate 90 degrees before uploading.

coming soon:

There is a lot to do still, both on the server side and in the poi code. I recently switched over to PlatformIO, as the huge code base was getting a bit unwieldy for Arduino IDE. This is going to mean a huge re-write of everything, but will give me an opportunity to enhance things along the way, such as:

  • Built in web server on the poi, able to switch between Online and Offline modes, including access to the magicpoi.circusscientist portal (so you will be able to control and manage the poi operation from any browser) – I tried this already, the magicpoi site works in an <iframe>, and there are many open source libraries for the access point management.
  • Many utilities such as creating timelines, image generation, text to image etc on the magicpoi portal. Also a better user interface (looking at javascript gallery plugins, but first getting the basic functionality up and running)
  • Much easier poi sync and multi-poi control using mesh networking
  • Support for more poi sizes (72px is currently the default on the portal – or was it 80px?)
  • ESP32 support – this is inevitable, unfortunately my only ESP32 device broke, so this is on hold for now.
  • Many other hardware improvements being worked on (thanks Caleb!) such as accelerometer, ESP32, external flash, smaller embedded LED’s, battery management and more.

some notes:

The online portal is “alpha” quality, so please expect things to break. I have limited the image uploads to 10 per account, and the .bin files (for imaging on the poi) are all kept in one public folder for now, so please don’t upload anything personal or proprietary at this point. This is just for ease of use, as I haven’t set up security end-points for the poi – server connection. Passwords are hashed, however, so at least that much is secure (this means even I can’t see your password), and the server is kept up-to-date with security updates.

So what do you think about the Magic Poi project? So many people have emailed with stories and photo’s of their test builds, it’s hugely motivating, so thanks everyone, you know who you are! I need to do a blog post with some of the images I have received, many different versions of the poi being built and spun all over the world – will have to get permission from the individuals concerned first though.

It’s slow but steady progress, and I am getting more certain over time that Magic Poi could be a serious contender in the LED poi space eventually. At least in kit form, on Indigogo!

UPDATES:

Sign up for our update alerts:

The magic of open source

Recently I found an awesome Android retro-gaming app – Super Retro Mega Wars, available on F-Droid. I was excited to introduce my son to the fun of Asteroids, Tetris, Snake and Tower Defense. Unfortunately the difficulty level was beyond a 7-year-olds’ abilities, and he soon lost interest.

All of the apps on F-Droid are open source, though, and I am an Android developer. Let’s see what I can do, I thought.

A few minutes later: I am pleased to present a kid friendly version of “Super Retro Mega Wars”, you can check it out here – Retro Wars Kid Friendly Version.

Changes include:

  • Asteroids: instead of blowing up, the space ship destroys asteroids it touches
  • Tetris: blocks and lines only
  • Snake: slowed down to a manageable speed
  • Tower Defense: more missiles and bigger explosions

All of this took me a total of around 10 minutes to set up, despite the app being coded in Kotlin (I am still transitioning from Java). Mainly this is due to the very clear way that the code is presented by the author – thank you @pserwylo, my son loves your game.

This brings me to the point of this article. Open source is amazing. It gives joy and empowerment to people from around the globe. There are loads of important projects out there that have a huge impact by being freely available and editable. Even a simple game app can make a difference – I know the source of this one is going to help me become a better developer.

I only wish the same could be said for vaccines. Imagine a world where we could say that scientists gave away their recipes with the hope that others could use and build on their work*.

*I am aware that many do, just none that I am aware of who are involved in producing the current commercially available Covid-19 vaccines.**

**Thought provoking further reading: https://jacobinmag.com/2021/02/finland-vaccine-covid-patent-ip/ – I have no affiliation, just an interesting article about a failed attempt at making an open source Covid-19 vaccine in Finland.

SmartPoi going online

Recently due to Covid my focus has shifted from performance to full time programming. I now code for a living, and have done for the past six months.

Since my work project involves server architecture I have come up with a new idea for SmartPoi – what if I could use the full power of the internet on the poi? The idea is to have an online server which the Android app can connect to and retrieve images, timelines, and visualisations. Each Android app could be associated with an account, with private and sharing functionality (so we could share images – a bit like on the visualpoi site).

The first part of this new functionality I am working on is a virtual poi imager (see https://circusscientist.com/Axel_Belhache_Demo/ for an idea of how this could look). This will have a way to upload your own images, and eventually you will be able to create an account and save images there. The long term goal is to connect the online server with the Android app, and make it easier to get new images, and share them. *UPDATE: The test page is now live! Try it out by uploading your own poi images here: magicpoicircusscientist.com. Currently limited to 10 images, and they need to be rotated 90 degrees before uploading.. I’m working on it!

As an added bonus, it is possible to send images to the poi straight from a browser (someone asked me about that recently on GitHub), so there could be a web app which would make SmartPoi usable without the Android app. Some functionality is not possible, though, with web alone – such as streaming images straight to the poi. For security reasons (DDOS) web browsers don’t allow UDP sending from the browser. Luckily SmartPoi backup images are uploaded using http requests. This means that standard poi things like offline images will be able to be loaded straight from the website onto the poi soon. Possibly timelines as well. I also hope to add re-sizing of images and text image generation to the list at some point.

Just as a side note – due to personal circumstances I am not able to do any hardware work for the rest of the year. The SmartPoi kit Indigogo launch will thus not be possible this year. Coding work is still very much in progress (I recently updated the app to work on Android version >9. )

As always, if you want to be first to hear the latest news about SmartPoi, you can sign up using the form below. Many thanks to those of you who emailed me with images of your own SmartPoi in action, it’s great to know that my contributions are inspiring people to make their own. We are just getting started. Loads more to come!

UPDATES:

Sign up for our update alerts:

DigitalOcean: Migrating WordPress Websites from Ubuntu Server 16.04 to 20.04

As you probably know (see the banner above) I am a happy user of DigitalOcean for many years now – I host multiple websites on a single server without any hassle. They don’t get that much traffic – 1000 or so hits a month for this one for example – so I’m happy sticking with the $5 per month offering for now.

Ubuntu 16.04 is reaching end of life!

It’s time for an upgrade! According to the DigitalOcean documentation it is not recommended to upgrade in-place (do-release-upgreade in the terminal)… I tried and stuff broke, so that is good advice. Luckily I have backups enabled for an extra $1 per month only, so restoring the server was a one-click affair. Now I have a new droplet and need to migrate ALL of my sites to it one by one.

Migration Notes:

  1. I followed this excellent tutorial: https://medium.com/@christoph.schmidl/how-to-manually-backup-wordpress-daa43e37a9bd to backup the mysql database and wordpress folder (/var/www/mysite) – but used wget on the new server to fetch the archives directly.
  2. I had to revoke the letsencrypt https certification – https://maximef.com/2020/10/21/how-to-delete-certbot-certificate-by-domain-name-lets-encrypt/ – don’t forget to remove old files left behind
  3. In the DigitalOcean dashboard, point the url to the new droplet
  4. Create new virtual host files and enable in apache (a2enmod sitename.com) – to learn more about using apache virtualhost files to host multiple sites on one server see: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-18-04 – it’s the same for 20.04
  5. I had an issue with the WordPress database but found out that all that’s needed is to match the wordpress wp-config.php information to the mysql database and user info. This tutorial was helpful (if a bit out of date, the procedure for creating a user has changed…) https://www.vultr.com/docs/troubleshooting-wordpress-database-errors
  6. Create new LetsEncrypt https cert – see #2 link, using certbot.
  7. And everything works (hopefully)

Tweaking the server:

I had some issues with the Ubuntu Server being a bit slow sometimes – think I used the one click WordPress install. It seems that there are ways to optimize this – here is a great link to some ideas about this:

  1. Add swap: https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-20-04
  2. More settings for swap: https://bitlaunch.io/blog/how-to-create-and-adjust-swap-space-in-ubuntu-20-04/

Now my server is running smoothly, it’s time to migrate this blog. Or have I done it already? I doubt you would notice!

Why you should hire a juggler (Or the similarities between learning to juggle and learning to code)

Learning new juggling moves is a task that benefits from breaking down into smaller, more achievable goals. In this respect it is very similar to learning a new coding language or framework.

Take my favorite 3 ball juggling move, for example: the Box.

In order to learn this we need to work out what is going on. There are three separate throws, two going up (one in each hand) and one going across.

Steps to learn the box:

1. One ball, up, across, up again

2. The hard part on both sides, with two balls (simultaneous up and side throw, not very intuitive but once you have it, it feels great)

3. Go for it. if you spent enough time on step 2, you can do it!

By the way, the example above is from https://libraryofjuggling.com/

Similarly in programming we have to break tasks down into pieces, only putting them together at the end. Recently I got a new job building an online app using Flask, JavaScript and a little bit of JQuery, Jinja and something called “Tabulator” for web tables (and Bootstrap for buttons).

Learning

Previously I had only worked in Android (Java) and Arduino (C++), so at least the syntax made sense on the front end, but in order to get the basics down I started by going through the FreeCodeCamp examples. Once I knew how to call a function, parse an array, set up a library and so on it was time to move on to the next step – building a basic program which works.

Finally I gained enough understanding of the inner workings that I was able to add/remove features without being afraid of breaking things and could start to enjoy building something.

Deploying

In Juggling, I learned that being able to keep up the pattern without dropping is only part of the process. As soon as I wanted to show off my new moves I was faced with another set of problems to solve. After some more practice, I learned that every juggling routine needs a flashy start and finish (to get people’s attention). It’s also important to be able to juggle without looking at the pattern, while talking at the same time.

In the software world this is called deployment. Personally I like going with my own Ubuntu based server (hosted by Digital Ocean ) but there are many options out there, each with their own different requirements to learn. The new job I mentioned is hosted on Google Cloud.

Conclusion

Conclusion and take away message: practice is always an important part of learning anything, but the basics need to be covered at first and you should definitely hire a juggler.

Check out my CV! (soon to include Python, Flask, JavaScript, Jinja, Google Cloud Services, and more)

SmartPoi Update

There have been a number of changes to the SmartPoi project in the last year. Due to issues I have had while spinning them at gigs I decided to make some much needed changes. This is a major upgrade

  1. Changed to binary format to save images (in LittleFS file system) – this is so much smaller than the previous text based format, I can now fit 100 offline images onto the small poi and 50 images onto the large poi. The maximum image size is larger. Also, all images can be displayed one after the other. And the timing can be changed for offline images as well.
  2. Added setup code to the Android app – no longer do I need to run a separate program to set up the test images, the Smart Poi Demo app now creates the correct files and folders*
    *unfortunately, Google in their wisdom are removing file system access slowly in newer versions of Android. This means that my code is going to have to be updated once again (angry face emoji)
  3. Uploading offline images to the poi is simple and available straight from the Android app. An upload image button uploads all of the images at once (one folder at a time only for now)

The Future of Smart Poi

I am planning the launch of a kit version, hopefully this will be possible some time during 2021(*Update: more like 2022). The design will be modular, with the battery, circuit, and LED’s all coming separate. I have a friend who is a qualified designer who will be helping with this part. The idea is to be able to have a ‘snap-on’ LED strip, so that more pixels can be added at a much lower cost than if I was making a whole new set of poi. The same goes for the battery, and even the main circuit (ESP32 anyone?). If I can do it right, it will mean that upgrades will be cheaper and also easier.

The new poi will be known as “Magic Poi”. Future Magic Poi Website here (It’s a fun Visual Poi Comparison site for now..)

Try out the current code:

  1. Firmware (on Github)
  2. Android App (on Github) or download the .apk

Smart Poi Overview page… may be a bit outdated now. Things are changing fast. I think you will agree that it’s improving with time. The future of Visual Poi is here, and it’s modular, open source, and streams over WiFi!

Sign up to hear news and updates:

Creating an app for Android Gingerbread in 2020

Whatsapp has officially revoked support, Google says 0.2% of devices accessing Google Play are still running it. I explore the difficulty in targeting a 10-year old version of Android.

Step 1: Search the internet

Maybe I’m using the wrong search terms but this is a bit of a bust. Google likes to showcase new shiny things. My search did come up with the above information regarding Whatsapp and also Google removing support (if you want to target the Play Store) but how do I do this for just my phone?

Step 2: Just go for it

I am using Android Studio. What if I just choose Gingerbread in the settings from a new project? Will it work?

Ok, it turns out that I only have lowest Android 4.0 (Ice Cream Sandwich)
I need 2.3.3 (Gingerbread)

Let’s check the SDK settings in Android Studio – I am sure I installed all the correct target libraries years ago, what is the problem?

SDK tools says Gingerbread is installed. Google says no!

Step 3: What happens if I plug the phone in?

Android Studio and ADB recognise the device. API level is 10. OK in my new project I go to build.gradle (why are there two, couldn’t they just call the one you need to edit something else?) and change API level to 10 (target, min, compile) – now what? Wait some hours while Gradle does it’s magic. I’m waiting for my laptop to be depreciated by Android Studio to be honest, it’s such a resource hog! (pro tip, if your laptop is running too hot, check out cpulimit on the command line. Or just get a job and buy a new one..)

This is turning out almost as bad as React Native, which I had a look at the other night – 1 hour to get to a “Hello World” app to work. Admittedly I was installing the framework from scratch…

So far so good, Gradle hasn’t thrown any errors, I’m installing the basic Gingerbread app now…

Oh snap! ConstraintLayout not supported on Gingerbread. Do I want to override this warning and install anyway (or use another layout, what did people use for Gingerbread back then?

Install anyway Gradle lets find out if I can get this thing to run. I love ConstraintLayout, most of my apps use it!

Ok nah, Android support v7 library has moved past the whole “Gingerbread” thing (AKA they DEPRECIATED it). Time to start again – I may need a new test project..

Support v4 library has minimum API 14, same as Support v7 library.

So far no luck compiling anything for my old phone with Android Studio.

Let’s Try Github

There’s loads of old code on Github, clone and install something from +5 years ago when Gingerbread was still supported?

OK success. I went and imported a project (https://github.com/andmatand/knitknit-gingerbread/) 44 commits, somebody put some time into this knitting tool for their girlfriend (it says so on the readme)

Then I had to specifically choose not to use the latest versions of libraries, add maven (all guided by Android Studio) and voilla. The thing installs.

This is pretty hit/miss. But as a proof of concept I will take it. I want to use my old phone for something, maybe as a streaming webcam, we used to use it as a baby monitor when my son was little. Now I can make my own apps for it.

Next up: Installing Ubuntu on my S3 mini (using PostmarketOS) and running some good old c – and is there any point in doing this if you can just install Termux?

ESP8266 libraries treasure trove

While looking for a new WiFi manager for my SmartPoi project, I stumbled upon a great resource: https://www.arduinolibraries.info/architectures/esp8266 – a list of Arduino libraries broken down by architecture.

Just having a quick look, I have noticed some great libraries to help improve my ESP8266 based projects (I haven’t had a chance to look at these yet, but looking forward to it!):

some interesting esp8266 libraries:

  1. https://www.arduinolibraries.info/libraries/esp8266-timer-interrupt
    – interrupts for ESP8266! So useful.
  2. https://www.arduinolibraries.info/libraries/esp_eeprom
    – Speed up EEProm and add wear levelling
  3. https://www.arduinolibraries.info/libraries/firebase-esp8266-client
    – Firebase? On ESP8266? Sounds like a challenge!
  4. https://www.arduinolibraries.info/libraries/mini-grafx
    – graphics library, not sure which displays this supports…
  5. https://www.arduinolibraries.info/libraries/process-scheduler
    – process scheduler, is this easy to use though?
  6. https://www.arduinolibraries.info/libraries/restfully
    – hopefully this is better than doing it manually
  7. https://www.arduinolibraries.info/libraries/rich-http-server
    – more http requests wrappers
  8. https://www.arduinolibraries.info/libraries/settings-manager
    – store settings in .json
  9. too many WiFi config libraries to list here, I saw at least 15!

These are only the few I was interested in personally, the site lists 244 libraries for ESP8266. Check it out!