System get Wifi DAQ status

 1'''
 2System_Wifi - get_Wifi_DAQ_status.py with asynchronous mode.
 3
 4This example demonstrates how to get basic information such as RSSI & battery & thermo & power & charge status from WifiDAQE3AH.
 5
 6-------------------------------------------------------------------------------------
 7Please change correct serial number or IP and port number BEFORE you run example code.
 8
 9For other examples please check:
10    https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
11See README.md file to get detailed usage of this example.
12
13Copyright (c) 2022-2024 WPC Systems Ltd. All rights reserved.
14'''
15
16## Python
17import asyncio
18
19## WPC
20
21from wpcsys import pywpc
22
23async def main():
24    ## Get Python driver version
25    print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
26
27    ## Create device handle
28    dev = pywpc.WifiDAQE3AH()
29
30    ## Connect to device
31    try:
32        dev.connect("192.168.5.38") ## Depend on your device
33    except Exception as err:
34        pywpc.printGenericError(err)
35        ## Release device handle
36        dev.close()
37        return
38
39    try:
40        ## Get firmware model & version
41        driver_info = await dev.Sys_getDriverInfo_async()
42        print("Firmware model:" + driver_info[0])
43        print("Firmware version:" + driver_info[-1])
44
45        ## Get RSSI, battery and thermo
46        rssi = await dev.Wifi_readRSSI_async()
47        battery = await dev.Wifi_readBattery_async()
48
49        ## Get power & charge status
50        power_status  = await dev.Wifi_getPowerGoodStatus_async()
51        charge_status = await dev.Wifi_getChargeStatus_async()
52
53        print(f"RSSI: {rssi} dBm")
54        print(f"Battery: {battery} mV")
55        print(f"Power status: {power_status}")
56        print(f"Charge status: {charge_status}")
57    except Exception as err:
58        pywpc.printGenericError(err)
59
60    ## Disconnect network device
61    dev.disconnect()
62
63    ## Release device handle
64    dev.close()
65
66    return
67
68def main_for_spyder(*args):
69    if asyncio.get_event_loop().is_running():
70        return asyncio.create_task(main(*args)).result()
71    else:
72        return asyncio.run(main(*args))
73
74if __name__ == '__main__':
75    asyncio.run(main()) ## Use terminal
76    # await main() ## Use Jupyter or IPython(>=7.0)
77    # main_for_spyder() ## Use Spyder