Files @ 94cab616b578
Branch filter:

Location: HydroBot/hydrobot-software/hydrobot_sensor_sim.py

matthewreed
Added data simulation and influxdb logging script
import time
import random
from canard import can, bus
from canard.hw import socketcan
from canard.file import jsondb

parser = jsondb.JsonDbParser()
b = parser.parse('hydrobot_can.json')

dev = socketcan.SocketCanDev("can1")
dev.start()

temp = 65.5
humid = 0.90
press = 100

while True:
    
    temp = max(0x00, min(0xFF, random.randint(-1, 1)/2 + temp))
    humid = max(0x00, min(0xFF, random.randint(-1, 1)/100 + humid))
    press = max(0x00, min(0xFF, random.randint(-1, 1) + press))
    
    message = b.get_message("AirTemp")
    message.get_signal("Temperature").value = temp
    message.get_signal("Humidity").value = humid
    message.get_signal("Pressure").value = press
    
    frame = b.build_frame("AirTemp")
    dev.send(frame)
    
    time.sleep(1)