Stuff I'm Up To

Technical Ramblings

ESPAsyncWebServer — March 28, 2019

ESPAsyncWebServer

This is a great ESP8266 component that greatly simplifies the deployment of a web server. It’s very capable and can handle websockets, compressed files and compared to other ESP web servers is streets ahead in terms of performance and abilities – It’s not without it’s challenges though.

One challenge in particular is the use of the ArduinoJson module. Or more correctly the use of ArduinoJson v5, when the most current is v6. As I discovered When I needed the AsyncJson functions, I found that I was using ArduinoJson v6 by default. This prevented my project from compiling because ESPAsyncWebServer is coded using v5 in its AsyncJson module.

A downgrade of ArduinoJson to v5 should have solved the issue, but up popped another issue. Looking through the Github issues history I found exactly my problem, but relating to PlatformIO not Arduino IDE.

error: expected class-name before '{' token
class AsyncJsonResponse: public AsyncAbstractResponse {

https://github.com/me-no-dev/ESPAsyncWebServer/issues/475#issuecomment-464770544

The solution was simply reorder my includes so AsyncJson is after the ESPAsyncWebServer. eg.

#include <ESPAsyncWebServer.h>
#include <AsyncJson.h>
#include <ArduinoJson.h>

The next quirk I encountered was the handler for receiving and processing json in the request body. The example given in the docs:

AsyncCallbackJsonWebHandler* handler = new AsyncCallbackJsonWebHandler("/api", [](AsyncWebServerRequest *request, JsonVariant &json) {
  JsonObject& jsonObj = json.as<JsonObject>();
});
server.addHandler(handler);

Never triggered even when my body had json in it. In the Github issues I found that this is down to the AsyncJson.h code not allowing for a Content-Type header that also included the code page data. There are two choices, modify the AsyncJson.h or set your client to match the exact Content-Type requirement of application/json; and not application/json; charset=UTF-8.

In my case I was able to modify the clients JavaScript axios call to specify the precise header without the code page. If you look at the AsyncJson.h file you’ll find


if (!request->contentType().equalsIgnoreCase(JSON_MIMETYPE))

So there’s no allowance for anything but the specific mime type and no code page. (See jnicolson’s comment)

Hopefully there’ll be an upgrade to ESPAsyncWebServer that moves it to ArduinoJson v6, but right now using v5 is the answer.

References

Scorpion Lite

Advertisements
Scorpion Lite – ESP8266 — March 27, 2019

Scorpion Lite – ESP8266

Looks like my friend likes to try to go one better. When he saw how I’d taken his original Wake-On-Wi-Fi idea and turned it into project Scorpion he moved to using ESP8266.

At the time I started looking into using a Raspberry Pi for the project I did also look at some very lightweight alternatives using the ESP8266 chip set. These are small devices perfect for use in a plethora of IoT projects. Their size is their strength and, for me, their weakness.

Moving onto a small chip means I have a few issues to solve that the Raspberry solves easily. 1) Power supply 2) File storage 3) My skills.

Adafruit Huzzah and FTDI Cable

Something I already had in my box of wires and gadgets is an Adafruit Huzzah ESP8266 board. I bought it a while ago and needed to combine it with a few other bits to make it work. To program it I needed a USB FTDI cable – which I also have.

But then my friend discovered the Wemos D1 Mini – now re-branded Lolin. The big benefit here is that it solves problem #1 (power supply) and means I don’t need an FTDI cable, just a regular micro USB cable which also supplies power.

Wemos also have a relay “shield” that means I can create a tidy package that builds in the ESP8266 and includes the relay required to turn on the PC.

Continue reading
Ubiquiti Amplifi — March 21, 2019

Ubiquiti Amplifi

Bye, bye Asus RT66U you served me well. Until all of a sudden the connection speeds on my 802.11ac would fluctuate wildly between 3Mbps and 150Mbps when previously I was seeing rock solid 877Mbps. If I switched to 802.11n I’d be stable at 216Mbps, but who wants that when I previously had more than three times that?

Time for something new. I checked out some of the reviews of newer routers and settled on the Amplifi. It’s a great looking design with some great reviews, but not the cheapest. I bought the Amplifi HD R and one of the MeshPoint HD’s. Both UK versions, with UK three pronged mains plugs.

My needs were near Gigabit Wi-Fi to my PC located upstairs from an Access Point located downstairs. I say Access Point because the actual ISP router is located elsewhere and I wanted to leave that as is, with it handling the upnp, port forwarding and firewall stuff – the router here would be used as an Access Point.

Ubiquiti Amplifi

Installation couldn’t be easier. In fact as an IT professional it’s a little daunting to have something so easy that is setup from a mobile phone and sits well in the realms of the end-user!

That said it has a wealth of features only accessible from the mobile phone config, that make it a highly capable Wi-Fi router.

In my chosen configuration I am using the Amplifi in bridge mode, so I lose the firewall and some of the features for managing clients. But it was important I leave my DHCP and internal network bridged to maintain the functionality of my Lifx lighting, Google Home and more importantly my scoRPIon device.

Once connected to my LAN (using the WAN port) I still have four Gigabit ports available for my wired network devices. The Amplifi sits under my TV and feeds my Tivo, XBox One X and Kodi with ease.

The wireless connection to my upstairs PC is now rocking a 1.1Gbps connection – still using the same Asus PCE-AC68 network card.

I added the MeshPoint in the kitchen, and will only really come into it’s own in the summer when the added signal range for the garden will be used. Right now it’s pretty redundant as the router pretty much covers everything I need in the house. The adding of the MeshPoint is again done from the mobile phone and is extremely straightforward.

Thankfully the brightness of LED base light and LCD display can be controlled from the phone app, as they can be a bit bright and distracting.

What’s in My EDC — January 30, 2019

What’s in My EDC

EDC All Packed

Every Day Carry is an up and coming buzz, but we’ve all probably been doing it for years. I’ve always had a few essentials in the car that includes a multi-tool, torch, a pen and packet of paracetamol.

I just decided to pad it out a bit and include some more useful stuff that could be grabbed from the car and chucked into an away day bag or rucksack. This is just a list of what goes into it.

The pack I chose to bundle this into comes from Amazon for £8. It’s a 1000D nylon pouch with two zip pockets, a buckle pocket and most importantly Molle fastenings. The Molle fastenings mean it’s able to be attached to any other Molle on a rucksack or vest. In this case the Molle has also been thought out to allow it to fit on to a regular belt.

I’m finding this an evolutionary process. Things I hadn’t thought put into my EDC are being added as I discover them and things I have are replaced by better or simpler versions.

What’s inside
Continue reading
Project scoRPIon – Wake-on-WiFi — July 8, 2018

Project scoRPIon – Wake-on-WiFi

A friend setup his home systems to turn on his PC using Amazon Alexa and tasker to trigger a Raspberry Pi to operate a relay and effectively activate the power button.

What a wonderful idea!

I have a host of Raspberry Pi’s, but instead of Alexa I have chosen the Google Home (Assistant) for my voice control.

My PC is located upstairs from my router and connects using 802.11ac WiFi. Being WiFi that rules out using Wake-on-LAN, which I used to do. So using a RPI to trigger a relay is genius.

Continue reading

Node.js v8 on Raspberry Pi Zero — June 27, 2018

Node.js v8 on Raspberry Pi Zero

With Raspbian on my Zero I only get Node v4 in the repository. So How do I get a newer version of Node.js?

If I follow the standard Node instruction for installing from a repository I get:

$ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -

## Installing the NodeSource Node.js 8.x LTS Carbon repo...

## You appear to be running on ARMv6 hardware. Unfortunately this is not currently supported by the NodeSource Linux distributions. Please use the 'linux-armv6l' binary tarballs available directly from nodejs.org for Node.js 4 and later.

So it looks like I must download the tar.xz file.

Continue reading

Raspberry Pi Wifi at boot — June 26, 2018

Raspberry Pi Wifi at boot

You can configure the Raspberry Pi raspbian image to have the details of your Wifi network at boot time – so no more hunting for keyboards and HDMI cables to fire it up onto your WLAN.

https://www.raspberrypi-spy.co.uk/2017/04/manually-setting-up-pi-wifi-using-wpa_supplicant-conf/

wpa_supplicant.conf

country=gb
update_config=1
ctrl_interface=/var/run/wpa_supplicant
network={
scan_ssid=1
ssid="MyNetworkSSID"
psk="Pa55w0rd1234"
}

Also create an empty file called ssh to start the sshd daemon on boot.

Lidarr — May 23, 2018

Lidarr

Since trying out Headphones a few years ago I got frustrated with it in the first hour and ditched it and went back to manually downloading music. That was until I got pointed to Lidarr.

Lidarr is either a fork of, or certainly based on the excellent Sonarr project for downloading TV series.  Lidarr applies the same methodology and familiar interface to download music.

Continue reading

Google Home and Kodi — November 29, 2017

Google Home and Kodi

I thought I’d take the opportunity to add a Google Home to my gadget collection. After all it’s on a £50 off same this week, so comes in at £79 delivered.

What I really want from it above all is to control my Kodi setup. Being able to voice control what movie or TV show to play would make the wife’s life a lot easier – and when she’s happy, I’m happy.

This is where I came across the GoogleHomeKodi project on GitHub and referenced on the Kodi forum here.

Continue reading

Setting up Baofeng UV-5R for PMR 446 — May 11, 2017

Setting up Baofeng UV-5R for PMR 446

Yes, it is illegal so don’t press the transmit button

1. Reset the radio to factory defaults

Goto Menu 40 (Press Menu followed by 40 or use up down to scroll to RESET ALL)

Press Menu to move the select down to ALL, press Menu. Press Menu to confirm, then Menu again to reply to SOURCE? (Which I’m sure is a bad translation of SURE?)

2. Set the Language.

The Radio will restart and now speak in Chinese. Great if you speak Chinese.

Set it back to English by pressing Menu 14 to get to VOICE, press Menu to move the selector to CHI, press UP or DOWN to get to ENG, press Menu to confirm.

Turn off and on radio it should be in English now.

3. Set the Step to 6.25k

Goto Menu 1, press Menu to move the selector down. Press 2, and when it shows 6.25k press Menu to confirm.

4. Enter in the first PMR 446 frequency

Press VOF/MR to until it says “Frequency Mode”

Type in 446006, it will show 446.006 you’ll see a tiny 25 to the right of it.

5. Save this as channel 1

Goto Menu 27, press Menu to move the selector down, press UP until you reach 001 – this is channel 1. Press Menu to store this current frequency as channel 1.

6. Setup the other 7 channels

This shouldn’t require any more typing of channel numbers.

Press VOF/MR until it says “frequency mode”. You should see your 466.00625 channel

Press UP twice and it should show 446.01875 this is channel 2.

Save it into channel 2 using the same process as step 5.

Exit the menu (Press Exit) and you’re back at your frequency 446.01875

Now it’s just a case of pressing UP twice to raise the frequency to the next channel and save each channel until you reach 8.

The full list of channels should look like:

  1. 446.00825
  2. 446.01875
  3. 446.03125
  4. 446.04375
  5. 446.05625
  6. 446.06875
  7. 446.08125
  8. 446.09375

7 . Deleting Channels

If you want to delete channels 0 and 127 just goto Menu 28, press Menu to drop the selector down, press UP or DOWN to choose the channel to delete and confirm by pressing Menu.

8. Show Channels instead of Frequencies

Just my preference, but in Channel Mode I want it to show the channel number not the 446 frequency.

Goto Menu 21 (MDF-A), press Menu to drop the selector, use UP or DOWN to scroll to CH. Do the same for Menu 22 and now you’ll see CH-001 etc. on the screen when in Channel Mode.

HTTPS on the Synology NAS — April 25, 2017

HTTPS on the Synology NAS

I love this Synology NAS. It’s so versatile and immensely capable. I use it for streaming my TV, movies and music. It also acts as my Couchpotato, Sonarr and NZBGet system. I think I’ll definitely get another when the time comes.

But enough glorification.

Using the free certificate services from Let’s Encrypt you can obtain a FREE TLS/SSL certificate that you can use on any of your encryption services with the one caveat that it will expire every 3 months.

Continue reading

Raspberry Echo – Alexa — February 21, 2017

Raspberry Echo – Alexa

When the Amazon Echo first came out I was looking at them in earnest, but decided I couldn’t justify the expense for something that I may lose interest in or not really make use of. A friend had an Amazon Echo Dot and combined that with a smart Lightwave RF lighting system in his new apartment I had to admit it was a very nice feature. But still I held back.

Then I discovered that you could install Alexa onto a Raspberry Pi!

As I have more than a few Raspberry Pi’s and a spare, here or there, left over from upgrading others, I thought I’d give it a go.

Continue reading