# LoRa Thermometer Example using Mikroelektronica Thermo Click thermocouple # interface # Copyright (C)2025, Philip Munts dba Munts Technologies. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # Installation: # # mkdir -p /usr/local/etc/therm # install -cm 0644 wioe5_ham1_thermometer.py /usr/local/etc/therm # chmod -R ugo-w /usr/local/etc/therm # mount -orw /boot # install -cm 0644 wioe5_ham1_thermometer sh /boot/autoexec.d # umount /boot # sysconfig --save # Reference Hardware Stack: # # Raspberry Pi 2 v1.2 (64-bit) # Mikroelektronika Pi 3 Click Shield MIKROE-2756 # Mikroelektronika LoRa 10 Click MIKROE-5986 in mikrobus socket 1 # Mikroelektronika Thermo Click MIKROE-5767 in mikroBUS socket 2 # # Add the following device tree overlay commands to /boot/config.txt: # # dtoverlay=Pi3ClickShield # dtoverlay=anyspi:spi0-1,dev="maxim,max31855k",speed=5000000 __author__ = 'Philip Munts ' import ctypes import os import time # Initialize the Wio-E5 LoRa Transceiver Module LoRa = ctypes.cdll.LoadLibrary('libwioe5ham1.so') portname = bytes(os.environ['WIOE5_PORT'], encoding='ascii') baudrate = int(os.environ['WIOE5_BAUD']) network = bytes(os.environ['WIOE5_NETWORK'], encoding='ascii') node = int(os.environ['WIOE5_NODE']) freq = ctypes.c_float(float(os.environ['WIOE5_FREQ'])) handle = ctypes.c_int() error = ctypes.c_int() relay = int(os.environ['WIOE5_RELAY']) LoRa.wioe5ham1_init(portname, baudrate, network, node, freq, 7, 500, 12, 15, 22, ctypes.byref(handle), ctypes.byref(error)) if error.value != 0: print('ERROR: LoRa.wioe5ham1_init() failed') exit(1) # Open temperature sensor files rawfile = open('/sys/bus/iio/devices/iio:device0/in_temp_raw', 'r') scalefile = open('/sys/bus/iio/devices/iio:device0/in_temp_scale', 'r') while True: # Measure the thermocouple temperature rawfile.seek(0) scalefile.seek(0) temp = float(rawfile.read())*float(scalefile.read())/1000.0 # Build temperature measurement string resp = '.Sensor.Temperature ' + str(temp) + ' C' # Transmit sensor measurement string LoRa.wioe5ham1_send(handle.value, bytes(resp, encoding='ascii'), len(resp), relay, ctypes.byref(error)) if error.value != 0: print('ERROR: wioe5ham1_send() failed, error=' + str(error.value)) time.sleep(5)