Created
October 24, 2022 09:25
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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