Open MoucheTaMoustache opened 2 years ago
Hi, I didn't saw that before. I didn't get any with VS Code, but I removed some indents that might be the cause. Let me know if it's fixed, if not, a screenshot (or a PR with the fixes) would help a lo.
Hi! Thank you for the reply! Since your intervention, VS code don't find indents errors. Thank you!
I have modified "address" and "UUID" corresponding to my ANENG9002 on LogData.py (I obtained it with bleak script). When I launch logdata.py on venv, I have an asyncio and bleak error:
Do you know what is going on? Moustache
PS : another scan with bleak give me these UUIDS for my Aneng9002 : 00001800-0000-1000-8000-00805f9b34fb (Handle: 1): Generic Access Profile 00001801-0000-1000-8000-00805f9b34fb (Handle: 6): Generic Attribute Profile 0000fff0-0000-1000-8000-00805f9b34fb (Handle: 7): Vendor specific 0000180a-0000-1000-8000-00805f9b34fb (Handle: 11): Device Information f000ffc0-0451-4000-b000-000000000000 (Handle: 30): Unknown
Which one is the good?
Hi! I have found a way to resolve this bug. I have adapted an example code from github's bleak's page and your code.
import sys
import asyncio
import platform
import logging
import keyboard
import csv
from multimeter import *
import matplotlib.pyplot as plt
from bleak import BleakClient
ADDRESS = ("FC:58:FA:53:61:C0") #address of my aneng
CHARACTERISTIC_UUID = "0000fff4-0000-1000-8000-00805f9b34fb" # <--- Change to the characteristic you want to enable notifications from.
dataGraph = []
multimeter = AN9002()
lastDisplayedUnit = ""
def notification_handler(sender, data):
global dataGraph
global multimeter
global lastDisplayedUnit
# Simple notification handler which prints the data received.
# print("Data multimeter: {0}".format(data.hex(' ') ))
multimeter.SetMeasuredValue(data)
displayedData = multimeter.GetDisplayedValue()
if multimeter.overloadFlag:
displayedData = 99999
print("Overload")
unit = multimeter.GetDisplayedUnit()
if lastDisplayedUnit == "":
lastDisplayedUnit = unit
if unit != lastDisplayedUnit:
lastDisplayedUnit = unit
dataGraph.clear()
plt.clf()
dataGraph.append(displayedData)
plt.ylabel(unit)
print(str(displayedData) + " " + unit)
async def run(address):
client = BleakClient(address)
async with BleakClient(address) as client:
await client.start_notify(CHARACTERISTIC_UUID, notification_handler)
await asyncio.sleep(15.0) #show data for 15"
while(1):
if keyboard.is_pressed("q"):
print("Shutting down!");
break;
else:
plt.plot(dataGraph, color='b')
plt.draw()
plt.pause(0.1)
await asyncio.sleep(0.5)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.set_debug(False)
loop.run_until_complete(run(ADDRESS))
with open('plot.csv', 'w') as f:
wr = csv.writer(f)
wr.writerow(dataGraph)`
However, I have difficulty to exit script. VS Code asked me to delete some script's line... (It doesn't understand :
except Exception as e:
print(e)
finally:).``
except Exception as e:
print(e)
Look I have obtained my first graph :
So, modifications of your code let me difficult to stop script with 'q' touch. And, I don't obtain csv file for the moment. Do you have an idea?
Good sunday! Moustache
A nice to see you got a graph now :)
I had a look at the libraries, it seems that to use the "keyboard" library, the script needs to run as root. After I installed the keyboard and bleak library as root and ran the script as root, it worked on my side, with a plot.csv file as well. I updated the readme to match this.
Hi! On LogData.py file, VS Code found unexpected indentations. Do you knew that ?