Program for using ESP8266 to hack a certain 6LoWPAN to WiFi bridge system to use O-MI. Data is sniffed from a serial connection.
This program creates Open Messaging Interface write requests to following Open Data Format paths:
- Objects/K1/Gateways/ : Information about this hacking program
- Objects/K1/ : Received sensor information from sensor box installed at room name
Certificate and key need to be in unencrypted (empty passphrase) DER format.
Example for making keys: generate the private key (a 1024 bit key is used in this example)
> openssl genrsa -out my_private_key.pem 1024
convert the private key into DER format
> openssl rsa -in ./my_private_key.pem -out ./my_private_key -outform DER
generate the certificate request using the previously generated private key
> openssl req -new -key my_private_key.pem -out my_cert_req.pem
get the certificate from Certificate Authority (see other guides if you are managing your own CA)
convert the certificate into DER format
> openssl x509 -in my_cert.pem -out my_cert -outform DER
Then you can use SPIFFS or convert the keys to C code header with
> xxd -i client.crt > MyCertificates.cpp
> xxd -i client.key >> MyCertificates.cpp
- Run
./setup.sh
- Install the Arduino for ESP8266
- Depending on installation type, fix the
ESP_ROOT
in./Makefile
to point to your installation directory. - Depending on your target ESP8266 module, fix other settings in the top of the Makefile
$ make
$ make upload
for uploading the program to ESP8266 connected toUPLOAD_PORT
This project supports OTA update from the target server via secure HTTPS. This program ensures by default the identity of the server and sends its own client certificate to server for authentication, so unknown users cannot steal our client certificate from the update image.
To update:
$ make clean
(otherwise the saved build time might be wrong)$ make version
- The image needs to be copied to the target HTTPS server from
/tmp/KMEG-WSN-OMI-bridge/KMEG-WSN-OMI-bridge.bin
- The WHOLE VERSION STRING is sent by the esp when looking for updates and can be compared to the new one
- This esp program checks updates only on boot.
- Check that the program updated and is not in a reboot loop (update shouldn't take more than 5 mins)
Our current server setup has the image on path /opt/k1update/KMEG-WSN-OMI-bridge.bin
and requires
modifying and reloading the nginx site config. This all is handled by an update
script that can be run by make httpserver_upload
if Makefile SSH_UPLOAD_SERVER
is configured right.
Serial pin configuration can be changed in the Makefile. The default configuration is below, NodeMCU pin name is in parens.
Description | Transmit(NodeMcu) | Receive(NodeMcu) |
---|---|---|
Serial UART0: Usb, |
GPIO 1 (TX) | GPIO 3 (RX) |
-DSWAPSERIAL0 puts Serial to |
GPIO 15 (D8) | GPIO 13 (D7) |
Serial1 UART1: RX from flash |
GPIO 2 (D4) |
Use Serial1 for debug transmission (it can only transmit) and Serial for hacking the bridge. Now GPIO 1 is not used but is connected to usb serial for debugging, (not needed for production) Connection to wifi-bridge can now send AT commands and receive everything TinyOs is sending but cannot communicate to TinyOs MCU, which is not needed. Also everything sent is also echoed back. NOTE: Not good, TX is High when not transmitting? => requires modifications to the original bridge
USB Host ESP8266 WizFi220 TinyOs MCU
USB RX <---+---< USB TX > < TX >----------> RX
| < GPIO 15 TX > > RX <-----+----< TX
`---< GPIO 2 TX > |
> GPIO 13 RX <--------------------´
Header is the text marked row of islands next to WizFi220 chip.
VCC
ESP <-->VCC
headerGND
ESP <-->GND
headerGPIO13
(D7) ESP <-->TX
headerGPIO04
(D2) ESP <-->RX
header
WizFi connection replacements:
GPIO31
WizFI220 pin44: Cut before resistor (near MCU) and attach MCU side toGND
(keep the resistor on the MCU side)EXT_nRESET
WizFI220 pin35: (It's the extra wire; no pcb trace) Cut and attach MCU side toGND
Table for ESP boot mode pin configurations. for restarting in case of crash
D8 GPIO15 | D3 GPIO0 | D4 GPIO2 | Mode |
---|---|---|---|
0V | 0V | 3.3V | Uart Bootloader |
0V | 3.3V | 3.3V | (RE)BOOT SKETCH, use this configuration |
3.3V | x | x | SDIO mode (not used for Arduino) |
GPIO2 (D4) is already connected to TX for debug output, TX is connected to VCC via 10k resistor in many boards.
In other words, connect (use 10kOhm resistors for the safety of your ESP):
GPIO15
(D8) <-->GND
GPIO0
(D3) <-->VCC
GPIO2
(D4) <-->GPIO1
(TX)