F
Felipe Mateus
Sonoff: Keyboard Key Reuse – Part 2

sonoff: Keyboard key reuse – Part 2

By Felipe Mateus
Posted on 03/09/2023

Some time ago I wrote a text talking about a sonoff software I made to replace a notebook key that had no use. However, I owed a version 2 of the project running in the background, this is the objective of this new project. 

Before starting to explain more about the sonoff program, you must be wondering why I'm making a version 2? This program is very useful for me because I can turn the light on and off without taking my hand off the computer keyboard. 

Starting the Sonoff Project

There are some differences between this and another project, not only in the way it works but also in the operating system built into the software. As you can see in the previous project, the system was Windows 10, now I'm using Pop Os.

First of all I tried to create the new version based on previous project however, I encountered some difficulties such as: lib outdated, slowness in the execution of the application and the fact that it generated several files to generate the binary.

All these python limitations were bothering me a little, so I decided to research in other languages a way to make this project better. 

Then I looked in Rust and I didn't get much success until I found a lib in golang that did exactly what it did in python besides promising access to private keys that didn't work.

How the sonoff project works

The program, run in the background of the computer as a service, maintains an always active connection with sonoff ewelink.cc So this makes it run much faster than the previous program. 

Linux terminal with service running sonoff service.
Image 1: shows terminal with service running]

To turn the light off or on, press the keys Ctrl + Alt + num0 so it does not depend on the operating system shortcut to execute it is implemented directly in the program. 

However it is possible to install only on Linux I did not make the version of this program compatible with Windows different from the previous program.

The program issues a notification at each execution of the command, indicating the current status of the changed lamp.

Image shows program notifications.
Image 2: Shows notifications of the running program.

Creation Challenges

The main challenge of this version was trying to capture the keys that are pressed using the hotkey lib, but it was not possible. So I searched the internet for another lib that ended up working, but if I want to capture a special key, like in the previous project, I'll have a hard time.

Another thing that I got stuck was when creating the service, I was creating the service in system mode, so he was not able to see the x11 settings that are necessary for the hotkey. However, searching the internet I managed to solve this problem until quickly.

Technologies Used

Leave a Reply

Your email address will not be published. Required fields are marked *