System hello world

 1'''
 2System_Wifi - hello_world.py with asynchronous mode.
 3
 4This example code is in the public domain 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        for i in range(10, 0, -1):
41            print(f"Restarting in {i} seconds...")
42            await asyncio.sleep(1) ## delay [s]
43
44        print(f"Restarting now")
45        await dev.Sys_reboot_async()
46    except Exception as err:
47        pywpc.printGenericError(err)
48
49    ## Disconnect network device
50    dev.disconnect()
51
52    ## Release device handle
53    dev.close()
54
55    return
56
57def main_for_spyder(*args):
58    if asyncio.get_event_loop().is_running():
59        return asyncio.create_task(main(*args)).result()
60    else:
61        return asyncio.run(main(*args))
62
63if __name__ == '__main__':
64    asyncio.run(main()) ## Use terminal
65    # await main() ## Use Jupyter or IPython(>=7.0)
66    # main_for_spyder() ## Use Spyder