Hacker Public Radio

HPR4058: Radio Thermometer


Listen Later

# If you ever want to make this code better, please do
# but for the love of God, please save this code first.
# It is written in circuitpython to prevent the need
# to compile code, and the RFM69 does not work with
# micropython.
import board
import analogio
import digitalio
from time import sleep
import math
import adafruit_rfm69
import busio
RoomNum = 10 # What room number is this in
SenderRoom = 10 # What room number reports to the receiver
RoomQuant = 12 # How many rooms are there
RecAddr = 254 # What's the address of the receiver
Radio_Freq_Mhz = 915.0 # What's the frequency of the radio
RetryAmount = 3 # How many times to retry sending the packet
min_okay = 12493 # Approx 20 deg C
max_okay = 9571 # Approx 26 deg C
led = digitalio.DigitalInOut(board.GP25) # Onboard LED
led.direction = digitalio.Direction.OUTPUT
CS = digitalio.DigitalInOut(board.GP13) # Pin 17
CS.direction = digitalio.Direction.OUTPUT
RESET = digitalio.DigitalInOut(board.GP6) # Pin 9
RESET.direction = digitalio.Direction.OUTPUT
SCK = board.GP10 # Pin 14
MOSI = board.GP11 # Pin 15
MISO = board.GP12 # Pin 16
spi = busio.SPI(SCK, MOSI, MISO)
rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, Radio_Freq_Mhz, baudrate=1000000)
#rfm69.reset()
rfm69.xmit_timeout = 10.0
#rfm69.freq_mhz = Radio_Freq_Mhz
rfm69.tx_power = 20
rfm69.node = RoomNum
rfm69.destination = RecAddr
#rfm69.encryption_key = (b'x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00')
adcpin = board.GP26 # Pin 31
thermistor = analogio.AnalogIn(adcpin)
resend_time = 1
def ask_all(radio):
send_packet = ''
temp_list = []
room_packet = ''
for a in range(RoomQuant):
temp_list.append('')
for b in range(RoomQuant):
digitnum = str(b + 1)
if len(digitnum) == 1:
digitnum = '0' + str(b + 1)
if not int(digitnum) == RoomNum:
radio.send(bytes('query','utf-8'), destination = int(digitnum))
sleep(.5)
room_packet = radio.receive(timeout = 1.0)
if room_packet == None:
room_packet = str('0')
else:
room_packet = temp_retrieve()
temp_list[b] = digitnum+room_packet
for c in range(RoomQuant):
send_packet = send_packet + temp_list[c]
return send_packet
def temp_retrieve():
#Voltage dividor
Vin = 3.3 # Pin 35
Ro = 7500 # 10k resistor 10000 was initial setting, changed for calibration
#Steinhart constants
A = 0.00110683
B = 0.000238464
C = 0.00000006507394
# Get voltage value from ADC
adc = thermistor.value
print(adc)
Vout = (Vin/65535)*adc
# Calculate resistance
Rt = round((Vout * Ro) / (Vin - Vout),0)
# Rt = 10000 # Used for testing. Setting Rt to 10k equates approx 25C
# Steinhart - Hart equation
TempK = 1 / (A + (B * math.log(Rt)) + C * math.pow(math.log(Rt), 3))
# Convert from K to C
TempC = TempK - 273.15
TempF = (TempC * (9/5)) + 32
print(Rt, TempC, TempF)
return temp_check(Rt)
def temp_check(digis):
if digis < max_okay:
return '1'
elif digis >= max_okay and digis < min_okay:
return '2'
elif digis >= min_okay:
return '3'
temp_retrieve()
while True:
led.value = True
if SenderRoom == RoomNum:
tx_packet = ask_all(rfm69)
print(tx_packet)
for x in range(RetryAmount):
rfm69.send(bytes(tx_packet, 'utf-8'))
sleep(5)
else:
rx_packet = rfm69.receive(timeout = 10, keep_listening = False)
if not rx_packet == None:
tx_packet = temp_retrieve()
print(tx_packet)
sleep(.2)
led.value = False
Click the image for the full-sized version
...more
View all episodesView all episodes
Download on the App Store

Hacker Public RadioBy Hacker Public Radio

  • 4.2
  • 4.2
  • 4.2
  • 4.2
  • 4.2

4.2

34 ratings


More shows like Hacker Public Radio

View all
The Changelog: Software Development, Open Source by Changelog Media

The Changelog: Software Development, Open Source

289 Listeners

Defensive Security Podcast - Malware, Hacking, Cyber Security & Infosec by Jerry Bell and Andrew Kalat

Defensive Security Podcast - Malware, Hacking, Cyber Security & Infosec

373 Listeners

LINUX Unplugged by Jupiter Broadcasting

LINUX Unplugged

268 Listeners

SANS Internet Stormcenter Daily Cyber Security Podcast (Stormcast) by Johannes B. Ullrich

SANS Internet Stormcenter Daily Cyber Security Podcast (Stormcast)

653 Listeners

Curious Cases by BBC Radio 4

Curious Cases

826 Listeners

The Strong Towns Podcast by Strong Towns

The Strong Towns Podcast

422 Listeners

Late Night Linux by The Late Night Linux Family

Late Night Linux

164 Listeners

Darknet Diaries by Jack Rhysider

Darknet Diaries

8,035 Listeners

Cybersecurity Today by Jim Love

Cybersecurity Today

181 Listeners

CISO Series Podcast by David Spark, Mike Johnson, and Andy Ellis

CISO Series Podcast

189 Listeners

TechCrunch Daily Crunch by TechCrunch

TechCrunch Daily Crunch

42 Listeners

Strict Scrutiny by Crooked Media

Strict Scrutiny

5,799 Listeners

2.5 Admins by The Late Night Linux Family

2.5 Admins

98 Listeners

Cyber Security Headlines by CISO Series

Cyber Security Headlines

139 Listeners

What the Hack? by DeleteMe

What the Hack?

221 Listeners