Reading Data from HC-12 on Raspberry Pi and sending it to Domoticz

Hardware.

Okay, to read data from HC-12 to the Raspberry PI is practically very easy :). All you need to do is hook it up and power from RPi.

  • VIN – Connect to RPi 5V (PIN 4)
  • GND – Connect to RPi GND (PIN 6)
  • RX – Connect to RPi GPIO14 (PIN 8, UART0_TXD)
  • TX – Connect to RPi GPIO15 (PIN 10, UART0_RXD)

I “stole” that image from Internet, so you can see which pins exactly are those that we need:

Software.

Simple Python script can be downloaded here. It’s not that “pretty”, but I just learned python, lol :). The idea of the script is to read the HC-12 sensor’s values on the serial port as text lines, split them, and depending on some basic configuration, send the value to the dummy device in Domoticz, by it’s idx. You need to add the dummy devices before that, in our case – One dummy device type temperature, it has idx 26 in our sample, and another one type lux, it has idx 27 in the example.

You will need to make the script run at start, if you need persistency. For my test purposes I will not explain that right now. Btw, make sure you have python3, pip3, and wiringPi libraries installed, and also make sure the serial port at /dev/ttyS0 is activated and accessible ( you can configure it in raspi-config -> Interfacing Options -> Serial ).

After this, you can see the values being read to Domoticz.

and

That’s it, very very simple 🙂

4 comments On Reading Data from HC-12 on Raspberry Pi and sending it to Domoticz

Leave a reply:

Your email address will not be published.

Site Footer

Sliding Sidebar