forked from doniks/pycom-examples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_state.py
187 lines (173 loc) · 5.11 KB
/
get_state.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import os
import binascii
import machine
def print_wifi_mode(m):
if m == WLAN.AP:
print("AP", end='')
elif m == WLAN.STA:
print("STA", end='')
elif m == WLAN.STA_AP:
print("STA_AP", end='')
print(os.uname().sysname.lower() + '-' + binascii.hexlify(machine.unique_id()).decode("utf-8")[-4:], "get_state.py")
print("===== machine ====================================")
print("unique_id", binascii.hexlify(machine.unique_id()))
try:
print("temperature", machine.temperature())
except:
pass
mrc = machine.reset_cause()
print('reset_cause', mrc, end=' ')
if mrc == machine.PWRON_RESET:
print("PWRON_RESET")
# plug in
# press reset button on module
# reset button on JTAG board
# core dump
elif mrc == machine.HARD_RESET:
print("HARD_RESET")
elif mrc == machine.WDT_RESET:
print("WDT_RESET")
# machine.reset()
# machine.lte_reset()
elif mrc == machine.DEEPSLEEP_RESET:
print("DEEPSLEEP_RESET")
# machine.deepsleep()
elif mrc == machine.SOFT_RESET:
print("SOFT_RESET")
# Ctrl-D
elif mrc == machine.BROWN_OUT_RESET:
print("BROWN_OUT_RESET")
mwr = machine.wake_reason()
print("wake_reason", mwr, end=' ')
if mwr[0] == machine.PWRON_WAKE:
print("PWRON_WAKE")
# reset button
elif mwr[0] == machine.PIN_WAKE:
print("PIN_WAKE")
elif mwr[0] == machine.RTC_WAKE:
print("RTC_WAKE")
# from deepsleep
elif mwr[0] == machine.ULP_WAKE:
print("ULP_WAKE")
print("===== os =========================================")
print("sysname", os.uname().sysname) # e.g., GPy
print("release", os.uname().release) # e.g., 1.20.1.r1
print("release", os.uname().version)
print("uname", os.uname())
import pycom
print("===== pycom ======================================")
try:
print("free_heap", pycom.get_free_heap())
# print("bootmgr", pycom.bootmgr())
print("partition", pycom.bootmgr()[0])
print("fs_type", pycom.bootmgr()[1])
print("free", os.getfree('/flash'))
print(pycom.bootmgr()[2]) # safeboot
print(pycom.bootmgr()[3]) # status
print("ota_slot", hex(pycom.ota_slot()))
if (pycom.ota_slot() == 0x210000):
print("ota_slot is", "'ota_0' in 'new' 8MB layout")
elif (pycom.ota_slot() == 0x1A0000):
print("ota_slot is", "'ota_0' in 'old' 4MB layout")
elif (pycom.ota_slot() == 0x10000):
print("ota_slot is", "'Factory'")
else:
raise Exception("Unkown ota_slot"+ str(pycom.ota_slot()))
except:
pass
try:
print("smart_config_on_boot", pycom.smart_config_on_boot())
except:
pass
try:
print("pybytes_on_boot", pycom.pybytes_on_boot())
except:
pass
try:
print("wifi_on_boot", pycom.wifi_on_boot())
except:
pass
from network import WLAN
try:
m = pycom.wifi_mode_on_boot()
print("wifi_mode_on_boot", m, end=" ")
print_wifi_mode(m)
print()
except:
pass
try:
print("wifi_ssid", pycom.wifi_ssid())
print("wifi_pwd", pycom.wifi_pwd())
except:
pass
try:
# v1.20.1.r1
print("wifi_ssid_sta", pycom.wifi_ssid_sta())
print("wifi_pwd_sta", pycom.wifi_pwd_sta())
print("wifi_ssid_ap", pycom.wifi_ssid_ap())
print("wifi_pwd_ap", pycom.wifi_pwd_ap())
except:
pass
print("===== wlan =======================================")
wlan = WLAN()
try:
print("sta_mac", binascii.hexlify(wlan.mac().sta_mac))
print("ap_mac", binascii.hexlify(wlan.mac().ap_mac))
except:
print("mac", binascii.hexlify(wlan.mac()))
print("is_connected", wlan.isconnected())
print("ssid", wlan.ssid())
print("bssid", binascii.hexlify(wlan.bssid()))
try:
print("country", wlan.country())
except:
pass
print("ifconfig", wlan.ifconfig())
print('IP:', wlan.ifconfig()[0])
print("mode", wlan.mode(), end=' ')
print_wifi_mode(wlan.mode())
print()
try:
print("===== lora =======================================")
from network import LoRa
lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868)
print("mac", binascii.hexlify(lora.mac()))
print(lora.frequency())
print(lora.has_joined())
print(lora.tx_power())
print(lora.power_mode())
#print(lora.stats())
except:
pass
try:
print("===== sigfox =====================================")
from network import Sigfox
sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ1)
print("id", binascii.hexlify(sigfox.id()))
print("mac", binascii.hexlify(sigfox.mac()))
print("pac", binascii.hexlify(sigfox.pac()))
print("frequencies", sigfox.frequencies())
except:
pass
try:
print("===== lte ========================================")
from network import LTE
lte = LTE()
print("imei", lte.imei())
print("iccid", lte.iccid())
print("is_connected", lte.isconnected())
print("ue_coverage", lte.ue_coverage())
def send_at_cmd_pretty(cmd):
return lte.send_at_cmd(cmd).replace('\r', '').strip().replace('\n\n','\n')
print('AT+CGCONTRDP=1', send_at_cmd_pretty('AT+CGCONTRDP=1'))
print('AT!="config"', send_at_cmd_pretty('AT!="ifconfig"'))
print("time", lte.time())
except:
pass
try:
print("===== eth ========================================")
from network import ETH
eth = ETH()
print("mac", binascii.hexlify(eth.mac()))
except:
pass