Good day all. I am currently building a gen 2 weather station, this time using the arduino mega 2560 as the gatherer (no issues) and transmit the data to the Pi 3b+ (issue here). Bullseye is the OS. Mariadb is the database. Data comes through when using line.ser.readline().decode('utf-8').rstrip()...it prints to the screen what it's being told from the arduino. My thought is that I need to maybe manipulate the arduino strings and pull the needed data out...I'm not clear on how to do that...IF that's the solution.
Here is what I have for Pi code so far:
My goal is to get temp_f, h, press, rainfall, Uva, Uvb, Uvi, Uvi2, and li (all arduino variables) to be assigned to similar variables on the pi so that I can uncomment the database portion and log them into the assigned database table.
If I add in global variables...all set to 0, and uncomment the INSERT lines, they are inserted into the database as 0's just fine. Issue is getting each arduino variable assigned to an equal variable on the Pi. I did this 3 years ago or so for an aquaponics project so I know it can be done...problem is that miraculously...all bookmarked tabs for the instructions have disappeared and I am back at square 1.
Thank you for your time
Here is what I have for Pi code so far:
Code:
#!/usr/bin/env python3# -*- coding: utf-8 -*-#comms.pyimport serialimport mariadbimport sysimport timeif __name__ == '__main__': ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1) ser.flush() while True: if (ser.in_waiting > 0): line = ser.readline().decode('utf-8').rstrip() print(line) #just to see the data being passed try: conn = mariadb.connect(user="$$$$$$$$$$", password="$$$$$$$$$$", host="127.0.0.1", port=3306, database="$$$$$") except mariadb.Error as e: print(f"Error connecting with Mariadb: {e}") sys.exit(1) cur = conn.cursor() #try: #cur.execute("INSERT INTO $$$$$ (temp, humid, bar, rain, uva, uvb, uvi, power, intensity) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", (temp_f, h, press, rainfall, Uva, Uvb, Uvi, Uvi2, li)) #except mariadb.Error as e: #print(f"Error: {e}") #conn.rollback() conn.commit() conn.close()
If I add in global variables...all set to 0, and uncomment the INSERT lines, they are inserted into the database as 0's just fine. Issue is getting each arduino variable assigned to an equal variable on the Pi. I did this 3 years ago or so for an aquaponics project so I know it can be done...problem is that miraculously...all bookmarked tabs for the instructions have disappeared and I am back at square 1.
Thank you for your time
Statistics: Posted by Osprey72 — Mon Apr 14, 2025 6:38 pm