Skip to content

Instantly share code, notes, and snippets.

@tomvdb
Created October 24, 2022 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomvdb/5287b90b4350c3f82d0b81963e4e96e1 to your computer and use it in GitHub Desktop.
Save tomvdb/5287b90b4350c3f82d0b81963e4e96e1 to your computer and use it in GitHub Desktop.
Example Python Script to send Weather Station data to QO-100 HS Modem
# external weather application example for hsmodem
# tom - zr6tg - 2022/10/23
import socket
import time
import random
while True:
'''
read data from weather station, using random values only as an example
'''
###########################################
temperature = random.randint(20,30);
humidity = random.randint(50,90);
windspeed = random.randint(1,5);
winddirection = random.randint(1,4)
###########################################
ext_message = []
extDataID = 0x7743fa9f
# special id for all messages
ext_message = bytearray(extDataID.to_bytes(4, byteorder='big'))
# special message type
ext_message.append(0x19)
# message data from weather station
ext_message.append(temperature)
ext_message.append(humidity)
ext_message.append(windspeed)
ext_message.append(winddirection)
# send data to local hsmodem
UDP_IP = "127.0.0.1"
UDP_PORT = 40135
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.sendto(ext_message, (UDP_IP, UDP_PORT))
# lets wait a second before sending more data
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment