I’ve started working on the Block Context plugin for Gutenberg — a companion to my Widget Context plugin which has around 70,000 active users. You’ll be able to show and hide content blocks for certain users, user roles, etc.

]]>https://kaspars.net/blog/wordpress/gutenberg-block-context/feed0Low Power ESP8266https://kaspars.net/blog/electronics/low-power-esp8266
https://kaspars.net/blog/electronics/low-power-esp8266#respondWed, 14 Nov 2018 12:13:37 +0000https://kaspars.net/?p=6836Read more →]]>Reduced power usage is the main reason for building custom boards with ESP8266 since most of the modules such as Wemos and NodeMCU use power regulators and UART to USB chips that draw a lot more current than the 20μA required by the ESP8266 during the deep sleep. In my own testing with Wemos D1 mini v3.0.0 the power consumption during the deep sleep was around 18mW because of all the extra components.

It delays the button press event for 200ms after the last interrupt trigger. There is no way of knowing if you’ve actually released the button so it will most likely trigger another event if the button press lasts for more than 200ms.

Are there better ways of doing this? Please share you ideas in the comments.

]]>https://kaspars.net/blog/electronics/micropython-button-debounce/feed1Solid, WebID and OpenID Connecthttps://kaspars.net/blog/observatory/solid-webid-oidc
https://kaspars.net/blog/observatory/solid-webid-oidc#respondWed, 03 Oct 2018 20:32:52 +0000https://kaspars.net/?p=6808Read more →]]>The last time I looked at anything OpenID related was back in 2008 when federated authentication was the hype before it was overtaken by the blockchain, machine learning and artificial intelligence. Times have changed and all of that is back as project Solidrun by Sir Tim Berners-Lee.

Here is the best overview of the OpenID Connect protocol that I could ever find by Nate Barbettini:

WebID and OpenID Connect

WebID is the key here — it adds the Semantic Web and linked data on top of the OpenID Connect for data discovery and exchange. Probably the nicest thing about WebID is the name Turtle — a markup language for writing up RDF graphs. Good luck understanding those.

I’ll be adding to this section as I dig deeper.

Personal Data

The Solid project builds on a recent revelation among the regular web users that having full control over their personal data and identity online is very important. This is a huge change from the previous narrative of linked data and the Semantic Web which was focused on computers harvesting and using that data which is hard to relate to for most of us.

]]>https://kaspars.net/blog/observatory/solid-webid-oidc/feed0WordPress Development Environment as a Composer Dependancyhttps://kaspars.net/blog/wordpress/wordpress-environment-composer
https://kaspars.net/blog/wordpress/wordpress-environment-composer#respondFri, 21 Sep 2018 18:15:46 +0000https://kaspars.net/?p=6797Read more →]]>Wouldn’t it be awesome to have a virtual WordPress development environment added to any plugin or theme as a Composer dependancy? Today I discovered the Drupal VM project which enables exactly that.

It should be relatively easy to add this kind of support for both VVV and Chassis — it only has to sync the VAGRANT_OLD_ENV_PWD directory to a theme or plugin directory within the WP install.

]]>https://kaspars.net/blog/wordpress/wordpress-environment-composer/feed0Google Smart Lock for Allhttps://kaspars.net/blog/wordpress/u2f-google-smart-lock
https://kaspars.net/blog/wordpress/u2f-google-smart-lock#commentsWed, 05 Sep 2018 13:14:13 +0000https://kaspars.net/?p=6788Read more →]]>Google Smart Lock is an app for iOS and Android devices that can talk to U2F security keys over bluetooth and NFC. Wouldn’t it be great to use it with the WordPress Two Factor plugin?

Turns out the app registers a custom u2f-google URL protocol with the iOS which can be used by any other app (including the Safari browser) to open the app with the necessary payload for the U2F authentication, which has the following format:

u2f-google://auth?data=PAYLOAD&returnUrl=RETURNURL

where PAYLOAD is a JSON string (urlencoded twice) with the following schema:

where CHALLENGEFROMTHEAPP is a cryptographic challenge generated by the U2F client (the WordPress plugin) and registeredKeys is a list of all the registered U2F devices with the U2F client (which must include the U2F key to be used over bluetooth).

The app now sends this data to the U2F key via bluetooth which responds with a message that gets added to the RETURNURL as a URL hash RETURNURL#chaldt=PAYLOAD where PAYLOAD is again double-urlencoded and has the following format:

The Hack

To make the Google Smart Lock app work with the Two Factor plugin, we should adjust the u2f-google link payload with our own data and set the correct returnUrl.

Unfortunately, the Smart Lock app ignores all requests where the returnUrl doesn’t start with https://accounts.google.com/signin which is a real shame because it would allow any site to offer U2F authentication without creating a custom middleware app for talking to U2F keys over bluetooth or NFC.

Use Contact Form 7 to collect business leads and enquiries? I created Storage for Contact Form 7 plugin which stores them safely in WordPress database.

]]>https://kaspars.net/blog/wordpress/u2f-google-smart-lock/feed2MySensors, RFM69 and ATTiny841https://kaspars.net/blog/home-automation/attiny841-rfm69-mysensors
https://kaspars.net/blog/home-automation/attiny841-rfm69-mysensors#respondWed, 18 Jul 2018 21:04:03 +0000https://kaspars.net/?p=6753Read more →]]>I want to design a wireless light switch that works for years without charging and doesn’t require mains connection and provides complete flexibility over the set of devices it controls. The actual switching would happen through relays in the home electricity distribution board.

The MySensors project provides software libraries for sensors and gateways that integrate well with the Home Assistant automation platform which in turn works with the Apple Home. It supports all of the popular wireless radios such as RFM69, NRF24L01+ and ESP8266 attached to most of the popular microcontrollers such as Atmel AVR, STM32 and the BCM in Raspberry Pi.

The Prototype

So I designed a single device that could be used both as a standalone sensor/switch transmitter and as a receiver when attached to the Raspberry Pi. Here is the very first prototype PCB with just the required wiring (and no passives) for connecting the radio module to both the Raspberry Pi and the ATTiny841 microcontroller via the SPI bus:

First prototype of the sensor module with RFM69CW radio connected to both ATTiny841 and Raspberry Pi via SPI

Reset Trouble

The next step was to get the ATTiny841 talking to the RFM69CW radio and that took me days because it would just fail uploading the firmware as soon as I soldered the radio to the PCB. Turns out the reset pins of both ATTiny841 and RFM69CW were connected which caused the radio module to toggle the MISO and MOSI lines and interfere with the programming. Cutting the reset line to the radio fixed the issue 🤦.

MySensors and RFM69

There are dozens of ways to configure the RFM69 radio so it is important that both the transmitter and receiver use the same data encoding and encryption. At first the MySensors gateway on Raspberry Pi wouldn’t pick up any radio transmission from the ATTiny841 sensor so I spent hours finding differences in the register setup for MySensors and the RFM69 library.

Next Steps

The prototype module is now transmitting the internal RFM69 temperature data to another module attached to the Raspberry Pi and running the MySensors gateway. In the next few weeks I plan to publish the Arduino sketch and work on the updated PCB.

And the source command is a bash built-in which simply isn’t available in dash. The solution is to replace all instances of source something.sh with . something.sh (note the space between the dot and the script filename).

]]>https://kaspars.net/blog/dev/composer-travis-bash-source/feed0Notes on Webpack Hot Module Replacementhttps://kaspars.net/blog/dev/webpack-hmr-vagrant-docker
https://kaspars.net/blog/dev/webpack-hmr-vagrant-docker#respondTue, 27 Mar 2018 14:57:54 +0000https://kaspars.net/?p=6691Read more →]]>It took me a few days to read through the relevant parts of the webpack and webpack-dev-server source code and figure out how to enable Webpack Hot Module Replacement for any project that doesn’t use the webpack-dev-server for serving the JS bundle. I wanted to use HMR with Vagrant running Docker for a local WordPress theme development workflow.

How Does It Work?

The main requirement for HMR is for the browser to receive notifications when a new bundle file is built as you edit the source files. Unfortunately, the default notification logic in webpack/dev-server.js relies on the native Node.js events instead of the websocket messages sent by the webpack-dev-server.

Therefore, HMR will never work if the bundle file is not server by the same webpack-dev-server which also watches for the file changes and triggers the builds.

However, only the native Node.js event webpackHotUpdate is used by the HMR client side logic in webpack/hot/dev-server to apply the patch. This is why your bundle will never receive notifications about HMR events if it’s not served by the webpack-dev-server because native Node events are not supported outside the Node environment.

How to Fix It?

Clone the HMR client side logic in webpack/hot/dev-server and make it listen for webpackHotUpdate messages on a websocket instead of the native node events.

Use Contact Form 7 to collect business leads and enquiries? I created Storage for Contact Form 7 plugin which stores them safely in WordPress database.

]]>https://kaspars.net/blog/dev/webpack-hmr-vagrant-docker/feed0Retiring the WordPress Blogrollhttps://kaspars.net/blog/wordpress/retiring-wproll
https://kaspars.net/blog/wordpress/retiring-wproll#commentsTue, 23 Jan 2018 21:13:18 +0000https://kaspars.net/?p=6663Read more →]]>I’ve decided to retire the WordPress blogroll project that I started in 2013. It was originally built to share the list of WordPress related blogs that I was following on Google Reader. I’ve since switched to Feedly and here is my current list of WordPress related feeds (also available as OPML).

I remember how hard it was to build a screenshot engine that could render web fonts and handle all kinds or redirects and TLS certificate errors. Here are the scripts that have been running reliably for the past few years with PhantomJS. It also had a PHP script that automatically published all posts to this Flipboard magazine.

Finally, here are a few screenshots of how the website looked at the beginning of 2018:

Use Contact Form 7 to collect business leads and enquiries? I created Storage for Contact Form 7 plugin which stores them safely in WordPress database.

]]>https://kaspars.net/blog/wordpress/retiring-wproll/feed1Relays for Home Automationhttps://kaspars.net/blog/home-automation/relays-power-consumption
https://kaspars.net/blog/home-automation/relays-power-consumption#respondWed, 10 Jan 2018 22:54:29 +0000https://kaspars.net/?p=6642Read more →]]>Switching things off and on again is one of the main features of home automation. It is usually achieved through electronic switches or relays that are controlled by NPN or PNP transistor outputs which in turn are toggled by even lower power and isolated microcontroller output pins.

Songle, Omron and Panasonic Relays on a DIN rail.

Turns out that relays themselves have very different power requirements — from 0.1W to 1W or 0.8kWh to 8kWh of energy to stay “on” for a full year. I recently order samples of the following relays for switching the room lights:

Use Contact Form 7 to collect business leads and enquiries? I created Storage for Contact Form 7 plugin which stores them safely in WordPress database.

]]>https://kaspars.net/blog/home-automation/relays-power-consumption/feed0Static Websites with Headless WordPress via REST APIhttps://kaspars.net/blog/wordpress/static-headless-rest
https://kaspars.net/blog/wordpress/static-headless-rest#respondTue, 02 Jan 2018 16:34:40 +0000https://kaspars.net/?p=6632Read more →]]>Static websites are great but they still need some kind of content management system. And committing Markdown files to GitHub isn’t a friendly option for the majority of users including developers. So we end up using tools such as Prose, Netlify CMS or Contentful for the editing interface, user authentication and handling the media files.

Usually it is only the WordPress PHP templating layer that bothers the proponents of static websites and is perceived as the performance bottleneck. However, we now have the WordPress REST API which is way more flexible than any collection of Markdown files.

How?

Use WordPress REST API during the build process to create the content source files with the necessary front-matter.

]]>https://kaspars.net/blog/wordpress/static-headless-rest/feed0MacOS Photos Backuphttps://kaspars.net/blog/meta/macos-photos-backup
https://kaspars.net/blog/meta/macos-photos-backup#respondTue, 26 Dec 2017 11:45:14 +0000https://kaspars.net/?p=6621Read more →]]>All photos, videos and the associated meta data for the MacOS Photos library is stored in the Photos Library directory under Pictures in your home directory. However, the original files are placed in randomly named directories that are impossible to navigate outside of the Photos app.

For a simple backup I wanted to create a directory of all original photos and videos organised by year and month. So I wrote a PHP script which does the following:

parses the Photos database file to find the location of all originals,

creates symbolic links to the originals organized in directories named by year and month of the original YYYY-MM and prefixes all filenames with an md5 hash of the file.

We end up with a flat directory structure that can be easily synced to any remote location using rsync which takes care of resolving the symbolic links:

Use Contact Form 7 to collect business leads and enquiries? I created Storage for Contact Form 7 plugin which stores them safely in WordPress database.

]]>https://kaspars.net/blog/meta/macos-photos-backup/feed0Notes on Grunthttps://kaspars.net/blog/dev/grunt-notes
https://kaspars.net/blog/dev/grunt-notes#respondSat, 09 Dec 2017 09:41:17 +0000https://kaspars.net/?p=6569Read more →]]>Grunt is a very powerful task runner for automating and improving your development workflow. Even in 2017 when Webpack seems to be the cool kid on the block for concatenating and bundling static assets, there are plenty of tasks that are better handled by Grunt (or Gulp).

Setting Up Grunt

You don’t need grunt-cli to run Grunt tasks! Use npm scripts to define all project related tasks as npm run task-name instead. This way you can swap out Grunt for anything else in the future without changing the name of the related task. For example, here is an excerpt of package.json that uses both Grunt and Webpack for separate tasks:

Grunt for wp-dev-lib

So I began to wondered if we could convert most of the wp-dev-lib magic into Grunt tasks that are written in Javascript instead of Bash. The greatest feature of the wp-dev-lib is that it can report errors only for the parts of code that have changed in the particular commit or pull request. This is especially valuable when working with legacy projects that don’t adhere to any coding standards.

The following scripts are the easiest to convert:

install-pre-commit-hook.sh creates a symbolic link to the pre-commit script in the project .git/hooks directory. This can be replaced with husky which runs anything you have defined for the precommit script in the package.json file instead.

The challenge here is to duplicate the patch-level linter reporting. So far I haven’t figured the best way to do that but it’s been an interesting thought experiment.

Finally, we wouldn’t actually need the patch level filtering if the whole codebase matched the coding standards required by each linter. Maybe for legacy projects it’s easier to start by running automated code fixers such as phpcbf and fixmyjs.

]]>https://kaspars.net/blog/dev/grunt-notes/feed0Notes on Metalsmith and Jekyllhttps://kaspars.net/blog/dev/jekyll-vs-metalsmith
https://kaspars.net/blog/dev/jekyll-vs-metalsmith#respondSun, 03 Dec 2017 09:25:00 +0000https://kaspars.net/?p=6558Read more →]]>I love the concept of building project documentation websites out of simple Markdown and Mustache files. Recently I used Metalsmith (with Node.js) for creating the un-official Latvian eID documentation site and more recently Jekyll for the WP Shuttle project. In this post I want to note and compare these tools.

Metalsmith

Metalsmith uses Javascript and is very easy to setup and configure via package.json and a single build file.

The KEY-ID FIDO U2F security keys are a nice alternative to YubiKey 4 Nano because they cost only $12 instead of $50. However they include a green LED that is always enabled which makes it unsuitable for a permanent installation. In this video I explain how to open the device and remove the LED.

]]>https://kaspars.net/blog/wordpress/atom-wpcs-flags/feed010 Years of Blogginghttps://kaspars.net/blog/meta/10-years
https://kaspars.net/blog/meta/10-years#commentsWed, 20 Sep 2017 05:00:54 +0000https://kaspars.net/?p=6478Read more →]]>This was my first blog post on this day ten years ago. This WordPress plugin tells me the following statistics:

In 10 years since September 9, 2007 I have written 384 blog posts mostly on Wednesdays and Thursdays (one post per 1 week on average) which have received 1720 comments. Posts are composed of 56412 words and 269 images in total with 146 words and 1 image per post on average which would be a book of 225 pages.

It has been an amazing ride and I’m really excited about the addition of the video blog that I started on January 1st, 2017.

All the 0x00 bytes in the UART traffic were clearly mapped to 0x68 in the firmware.

Having read plenty of firmware related articles on Hackaday I thought of trying to check for XOR obfuscation and with 0x68 mapping to 0x00 the XOR value is simply 0x68. Here is how to XOR all bytes of a file with PHP:

]]>https://kaspars.net/blog/observatory/poker3-mac/feed7WordPress.com Usability Issueshttps://kaspars.net/blog/design/wordpress-com-usability
https://kaspars.net/blog/design/wordpress-com-usability#commentsFri, 16 Jun 2017 09:42:30 +0000https://kaspars.net/?p=6381Read more →]]>Every few month I need to use WordPress.com to create or update a site for a friend. And every time I get frustrated with how confusing and convoluted the user interface is.

“Reader” is the default homepage

WordPress.com is about publishing so why do I get to see the empty “Reader” as my homepage? Getting to the actual site dashboard requires an additional click or even more if the site is not your default site.

Adding a new site is impossible

For logged-in users the only link to adding a new site is grayed out and hidden in the bottom left corner of the “Switch Site” section. I tried everything from visiting the homepage, my profile page to manually entering random URLs such as wordpress.com/new before I found that link.

Custom domain email settings don’t include MX records

The “Email” tab of the domain settings includes only an upsell for the Google Apps. Adding the MX records for an existing account is only possible under the individual domain “DNS Records” which is another three clicks away. Why not link to that section from the “Email” tab, too?

Overwhelming upsells

I already pay for a custom domain and I don’t need the banners reminding me of features I don’t need.

Invited users are invisible

There is no way to see users that have been invited to the site.

What about you?

These are just the highlights of what I could remember this morning. Do you also have things you find confusing on WordPress.com? What about the WP-Admin section 😊

Use Contact Form 7 to collect business leads and enquiries? I created Storage for Contact Form 7 plugin which stores them safely in WordPress database.

]]>https://kaspars.net/blog/design/wordpress-com-usability/feed3How to Get YouTube Channel Subscriber Count without Using APIhttps://kaspars.net/blog/dev/youtube-subscriber-count
https://kaspars.net/blog/dev/youtube-subscriber-count#commentsSat, 06 May 2017 10:44:23 +0000https://kaspars.net/?p=6356Read more →]]>YouTube provides these subscribe buttons which include the number of your channel subscribers which can be extracted using a simple regular expression.

The 3.5mm input jack on the PCB can be soldered directly to the three audio signal wires of the Sony MDR-7508 headphones and placed inside the left headphone after drilling the required holes for the on/off switch, the micro-USB charging port and the 3.5mm audio input port which continues to work just like before the modifications:

]]>https://kaspars.net/blog/linux/spi-display-orange-pi-zero/feed39Orange Pi Zero GPIO Pinshttps://kaspars.net/blog/linux/orange-pi-zero-gpio
https://kaspars.net/blog/linux/orange-pi-zero-gpio#commentsSat, 25 Feb 2017 13:06:01 +0000https://kaspars.net/?p=6265Read more →]]>The 26-pin expansion port of the Orange Pi Zero is placed on the opposite side of the board compared to Raspberry Pi while the pinout is exactly the same:

Orange Pi Zero GPIO Pins

It took me a while to discover that the General Purpose Input/Output (GPIO) numbering on the Orange Pi Zero with Armbian Legacy 3.4.113 is different from the Raspberry Pi and Raspbian. Here is how Allwinner SoC port names (such as PB12) are mapped to their GPIO pin numbers in the Linux kernel:

]]>https://kaspars.net/blog/linux/orange-pi-zero-gpio/feed5Wiring Maytech Hub Motors to Flier Twin ESChttps://kaspars.net/blog/electronics/maytech-hub-motor-flier-esc-wiring
https://kaspars.net/blog/electronics/maytech-hub-motor-flier-esc-wiring#commentsMon, 13 Feb 2017 11:05:49 +0000https://kaspars.net/?p=6216Read more →]]>It took me a while to figure out the wiring for the dual Maytech 90mm sensored hub motors to the Flier twin-motor 120A ESC so I decided to share my findings. Here is the diagram when looking at the bottom of the skateboard:

Motor Rotation Direction

Each motor has to turn in a different direction if mounted on the opposite sites of the board. This can be achieved by swapping two motor phase wires (B and C) while the hall sensor wiring remains the same for both motors.

Motor Phase Wires

The phase wires of the Maytech hub motors are actually the wires from the stator windings so you have to properly remove the isolation before soldering them to any connectors.

For the counterclockwise rotation or the left wheel when looking from the top of the board:

ESC phase A to Maytech red

ESC phase B to Maytech black

ESC phase C to Maytech yellow

For the clockwise rotation (or the right wheel when looking from the top of the board) you switch ESC phase A and B or yellow and black wires:

ESC phase A to Maytech red

ESC phase B to Maytech yellow

ESC phase C to Maytech black

Hall Sensor Wires

Hall sensor wires use the 6-pin JST ZH connectors (model number JST ZHR-6) which are much smaller than the JST-XH which are used for balance chargers, for example.

ESC blue to Maytech green for phase A

ESC green to Maytech white for phase B

ESC yellow to Maytech yellow for phase C

Here is a photo of the prototype. I’m planning on moving this to a bigger longboard for improved handling since the wheels are so large.

PiJack uses the Microchip ENC28J60 Ethernet controller which is capable of 10 Mbps (or just 1.25MB/s). While the Raspberry Pi Zero will recognize and configure the PiJack automatically, the actual networking speed didn’t exceed 5 Mbps with the iperf test or when downloading a large file over a local network using wget.

PiJack uses the Microchip ENC28J60 Ethernet controller.

Here is the ethtool report with the PiJack connected:

Ethtool Report of PiJack.

Power Consumption

Transferring a 1GB file over a local network using PiJack attached to the Raspberry Pi Zero consumes around 170mA or 0.85W while the Orange Pi Zero uses around 100mA or 0.5W for the same task. These are only very rough figures and will probably be different with your setup.

Conclusions

PiJack is a good product if you don’t want to move away from the Raspberry Pi ecosystem for your project and you need to transfer only limited amounts of data. The Orange Pi Zero and NanoPi NEO are much cheaper at $10 and offer higher networking speeds and lower power consumption. The Armbian operating system has a great community and plenty people interested in improving both the performance and power consumption of these well documented Allwinner SoC based computers.