SequentMicrosystems / megaind-rpi

Command Line, Python, and Node-Red for Industrial Automation Card
https://www.sequentmicrosystems.com
MIT License
14 stars 13 forks source link

Python Implementation of Industrial Automation HAT #32

Open un1997 opened 3 weeks ago

un1997 commented 3 weeks ago

I'm trying to make use of the HAT for gathering digital and analog input and giving outputs with a Python program and AWS IoT. This would run indefinitely and send and receive information from my script ideally. When i try to implement the same in the following manner.

def on_connect(client, userdata, flags, rc): if rc == 0: print("Connected to AWS IoT") client.subscribe(MQTT_TOPIC_SUBSCRIBE) else: print("Connection to AWS IoT failed")

def on_message(client, userdata, msg): print(f"Received message from topic {msg.topic}: {str(msg.payload.decode('utf-8'))}") message = json.loads(msg.payload) if "desiredTemperature" in message: desired_temperature = message["desiredTemperature"] print(f"Setting desired temperature to: {desired_temperature}") set_temperature(desired_temperature)

def read_sensors(): temperature = ind.get0_10In(STACK_LEVEL, TEMP_INPUT_CHANNEL) humidity = ind.get0_10In(STACK_LEVEL, HUMIDITY_INPUT_CHANNEL) return temperature, humidity

I get an error stating "An error occurred in the publish thread: [Errno 2] No such file or directory: '/dev/i2c-1'

The program works ideally when i comment out any code with regards to the megaind library and use dummy data.

alexburcea2877 commented 3 weeks ago

Did you enable the I2C port? Do your tests with the "megaind" command line first to validate the setup.