microsoft / pi-azure-recipes

Collection of quickstart guides using a Raspberry Pi and Azure services
MIT License
21 stars 8 forks source link

No telemetry transmission #20

Open mariusz1602 opened 2 years ago

mariusz1602 commented 2 years ago

In RAW DATA and Overview - no telemetry data.

In RaspberryPi it only displays:

pi@raspberrypi:~ $ cd client pi@raspberrypi:~/client $ source ./.venv/bin/activate (04_iot_central) pi@raspberrypi:~/client $ python raspberry_pi_client.py Press Q to quit Sending reported property: {'remaining_disk_space': '19G'}

Errors are displayed when the program is interrupted by Q.

Press Q to quit q Quitting... Traceback (most recent call last): File "/home/pi/client/raspberry_pi_client.py", line 296, in asyncio.run(main()) File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete return future.result() File "/home/pi/client/raspberry_pi_clie

nt.py", line 288, in main await asyncio.gather(telemetry_loop, reported_loop) File "/home/pi/client/raspberry_pi_client.py", line 161, in send_telemetry payload = f'{{"cpu_temp": {get_current_cpu_temp()}, "cpu_freq": {get_cpu_frequency_statistics()["current"]}, "cpu_usage": {get_cpu_usage()}, "ram_usage": {get_memory_statistics()["used"]}}}' File "/home/pi/client/raspberry_pi_client.py", line 91, in get_cpu_usage return float(cpu_usage) ValueError: could not convert string to float: '' Task was destroyed but it is pending!

Please, can you tell me where this error came from ? "line 91, in get_cpu_usage return float(cpu_usage)** ValueError: could not convert string to float: ''"

About, Commands - works ok.

raw_data Overwiew

mariusz1602 commented 2 years ago

That was a problem:

get CPU usage

def get_cpu_usage(): cpu_usage = str(os.popen("top -n1 | awk '/Cpu(s):/ {print $2}'").readline().strip()) return float(cpu_usage)

When I commented on this, the telemetry transmission works. so something wrong in the definition of reading CPU.

mariusz1602 commented 2 years ago

This work: def get_cpu_usage(): cpu_usage = str(os.popen("top -n1 | awk '/%CPU:/ {print $3 + $5}' | tr ',' '.'").readline().strip()) return float(cpu_usage)