Posts

Showing posts from March, 2019

Huawei Modem/Router sending encrypted requests

This relates to my Huawei python API here . I'm adding a dedicated post on this as I expect it may be useful for others. This took me quite a while to get working and I couldn't find any working solutions online. This implements the javascript RSA encryption used for encrypting requests to be sent to the modem's underlying API in python. The javascript code is: function RSAEncrypt(text) { var m = pkcs1pad2(text,(this.n.bitLength()+7)>>3); if(m == null) return null; var c = this.doPublic(m); if(c == null) return null; var h = c.toString(16); if((h.length & 1) == 0) return h; else return "0" + h; } The python code I got working is: import uuid import hashlib import hmac from binascii import hexlify import math import base64 from Crypto.Cipher import PKCS1_v1_5 from Crypto.PublicKey.RSA import construct def rsa_encrypt(rsae, rsan, data): if (data is None or data == ''): return '' N = long(rsan,16) E = long(rsae,16)

Caprice ceiling fan voice control - Part 2 of 2

Image
The Mission To enable voice control for the fans and lights of our new Mercator Caprice ceiling fans. So we can say things like: Alexa turn the office fan on/off Alexa start/stop the office fan Alexa turn the office fan to 80% (The same commands can be used for the fan light) The Steps Step 1. Figure out the radio frequency (RF) commands for the fans Step 2. Set up an RF sender on one of my Raspberry PIs Step 3. Develop a script to control the fan Step 4. Configure voice control via Alexa Step 1 and 2 are covered here . Step 3. Develop a script to control the fan I use two scripts, available here . send_rf.py -- Handles sending the command to the RF sender on the Raspberry Pi rf_control.py -- Receives commands in the format rf_control.py <room> <cmd>. For example: python rf_control.py office light These scripts handle converting the room and command into the string of 0's and 1's, which are then broadcast. Step 4. Configure voice

Caprice ceiling fan voice control - Part 1 of 2

Image
The Mission To enable voice control for the fans and lights of our new Mercator Caprice ceiling fans. The Steps Step 1. Figure out the radio frequency (RF) commands for the fans Step 2. Set up an RF sender on one of my Raspberry PIs Step 3. Develop a script to control the fan Step 4. Configure voice control via Alexa Step 1 - Determine the RF commands I purchased a DVB-T 820T2 radio tuner. Like  this one  on ebay. I used my Windows desktop, and installed the USB dongle and the Universal Radio Hacker (URH) software from here . (These would work on my Raspberry Pi3, but required quite a bit of memory and were a bit slow). 1. Determine fan radio frequency I fired up the URH Spectrum Analyzer. I knew the fans were likely be around 433 MHz or 315 MHz. Once running press a button on the remote, I could see a signal spike. Ok so close to 433 Mhz. 2. Analyse and decode the signals This probably took the longest amount of time, but decoding the signal was pretty fun. This time I