|
5 | 5 |
|
6 | 6 | # To operate the emnify SDK, you need to generate an application token.
|
7 | 7 | # Step-by-step guide: https://www.emnify.com/developer-blog/how-to-use-an-application-token-for-api-authentication
|
8 |
| -emnify = EMnify(app_token='YOUR_TOKEN') |
| 8 | +emnify = EMnify(app_token="YOUR_TOKEN") |
9 | 9 |
|
10 | 10 | # [endblock]
|
11 | 11 |
|
|
14 | 14 | unassigned_sims = [i for i in emnify.sim.get_sim_list(without_device=True)]
|
15 | 15 | # If there aren't any unassigned SIMs, register a new one via batch code:
|
16 | 16 | if not unassigned_sims:
|
17 |
| - registered_sim = emnify.sim.register_sim(bic='EXAMPLE_BIC_CODE') # Returns a list |
| 17 | + registered_sim = emnify.sim.register_sim(bic="EXAMPLE_BIC_CODE") # Returns a list |
18 | 18 | sim = emnify.sim.retrieve_sim(registered_sim[0].id)
|
19 | 19 | else:
|
20 | 20 | sim = unassigned_sims[0] # Takes the first unassigned SIM
|
|
25 | 25 | service_profile = emnify.devices.service_profile_model(id=1)
|
26 | 26 | tariff_profile = emnify.devices.tariff_profile_model(id=1)
|
27 | 27 | device_status = emnify.devices.status_model(id=0)
|
28 |
| -name = 'new_device' |
| 28 | +name = "new_device" |
29 | 29 | device_model = emnify.devices.device_create_model(
|
30 | 30 | tariff_profile=tariff_profile,
|
31 | 31 | status=device_status,
|
32 | 32 | service_profile=service_profile,
|
33 | 33 | sim=sim,
|
34 |
| - name=name |
| 34 | + name=name, |
35 | 35 | )
|
36 | 36 |
|
37 | 37 | # After creating a model, the SDK returns the device ID.
|
|
53 | 53 | # Get device details
|
54 | 54 | device = emnify.devices.retrieve_device(device_id=device_id)
|
55 | 55 |
|
56 |
| -tags = 'arduino, meter, temp' # Example tags |
57 |
| -name = 'new name' # Example name |
| 56 | +tags = "arduino, meter, temp" # Example tags |
| 57 | +name = "new name" # Example name |
58 | 58 |
|
59 | 59 | # Adjust the device configuration
|
60 |
| -update_device_fields = emnify.devices.device_update_model(name='new name', tags='arduino') |
| 60 | +update_device_fields = emnify.devices.device_update_model( |
| 61 | + name="new name", tags="arduino" |
| 62 | +) |
61 | 63 | emnify.devices.update_device(device_id=device.id, device=update_device_fields)
|
62 | 64 |
|
63 | 65 | # Get updated device details
|
|
73 | 75 |
|
74 | 76 | # Add three operators to the blacklist:
|
75 | 77 | device_id = 0 # Your device ID
|
76 |
| -emnify.devices.add_device_blacklist_operator(operator_id=all_operators[0].id, device_id=device_id) |
77 |
| -emnify.devices.add_device_blacklist_operator(operator_id=all_operators[1].id, device_id=device_id) |
78 |
| -emnify.devices.add_device_blacklist_operator(operator_id=all_operators[2].id, device_id=device_id) |
| 78 | +emnify.devices.add_device_blacklist_operator( |
| 79 | + operator_id=all_operators[0].id, device_id=device_id |
| 80 | +) |
| 81 | +emnify.devices.add_device_blacklist_operator( |
| 82 | + operator_id=all_operators[1].id, device_id=device_id |
| 83 | +) |
| 84 | +emnify.devices.add_device_blacklist_operator( |
| 85 | + operator_id=all_operators[2].id, device_id=device_id |
| 86 | +) |
79 | 87 |
|
80 | 88 | # Get all blacklist operators of the device by device ID:
|
81 | 89 | device_blacklist = emnify.devices.get_device_operator_blacklist(device_id=device_id)
|
|
88 | 96 | operator_id = operator.id
|
89 | 97 |
|
90 | 98 | # Removes the last operator from the blacklist
|
91 |
| -emnify.devices.delete_device_blacklist_operator(device_id=device_id, operator_id=operator_id) |
| 99 | +emnify.devices.delete_device_blacklist_operator( |
| 100 | + device_id=device_id, operator_id=operator_id |
| 101 | +) |
92 | 102 |
|
93 | 103 | # [endblock]
|
94 | 104 |
|
95 | 105 | # === Example: Disable a device ===
|
96 | 106 |
|
97 | 107 | # Get a list of all devices with SIM cards and the "Enabled" device status
|
98 |
| -device_filter = emnify.devices.get_device_filter_model(status=emnify_constants.DeviceStatuses.ENABLED_ID.value) |
| 108 | +device_filter = emnify.devices.get_device_filter_model( |
| 109 | + status=emnify_constants.DeviceStatuses.ENABLED_ID.value |
| 110 | +) |
99 | 111 | all_devices_with_sim = [
|
100 |
| - device for device in emnify.devices.get_devices_list(filter_model=device_filter) if device.sim |
| 112 | + device |
| 113 | + for device in emnify.devices.get_devices_list(filter_model=device_filter) |
| 114 | + if device.sim |
101 | 115 | ]
|
102 | 116 |
|
103 | 117 | device = all_devices_with_sim[0]
|
|
107 | 121 |
|
108 | 122 | disabled_device = emnify.devices.retrieve_device(device_id=device.id)
|
109 | 123 | device_status = disabled_device.status.description # Device status is "Disabled"
|
110 |
| -sim_status = disabled_device.sim.status.description # SIM status is "Suspended" |
| 124 | +sim_status = disabled_device.sim.status.description # SIM status is "Suspended" |
111 | 125 |
|
112 | 126 | # [endblock]
|
113 | 127 |
|
|
117 | 131 | old_devices_list = [device for device in emnify.devices.get_devices_list()]
|
118 | 132 |
|
119 | 133 | device_to_delete = list(
|
120 |
| - filter( |
121 |
| - lambda device: device.sim and device.status.id == emnify_constants.DeviceStatuses.ENABLED_ID, |
122 |
| - old_devices_list |
123 |
| - ) |
| 134 | + filter( |
| 135 | + lambda device: device.sim |
| 136 | + and device.status.id == emnify_constants.DeviceStatuses.ENABLED_ID, |
| 137 | + old_devices_list, |
| 138 | + ) |
124 | 139 | )[0]
|
125 | 140 |
|
126 | 141 | # Choose a device to delete with an assigned SIM and the "Enabled" device status
|
|
142 | 157 |
|
143 | 158 | # === Example: Manage device connectivity ===
|
144 | 159 |
|
145 |
| -# There are many reasons why connection issues arise. |
| 160 | +# There are many reasons why connection issues arise. |
146 | 161 | # For example:
|
147 | 162 | # - The device executes the wrong procedures due to a bad firmware update.
|
148 | 163 | # - The device executes network registration too frequently, so the network no longer allows it to register.
|
149 | 164 | # - You changed a policy due to a blocked device.
|
150 | 165 |
|
151 |
| -# To reset device connectivity, use the following methods: |
| 166 | +# To reset device connectivity, use the following methods: |
152 | 167 | # - Reset the device's connectivity
|
153 | 168 | device_id = 0
|
154 | 169 | emnify.devices.reset_connectivity_data(device_id=device_id)
|
|
157 | 172 |
|
158 | 173 | # Use the following method to check the connectivity:
|
159 | 174 | connectivity = emnify.devices.get_device_connectivity_status(device_id=device_id)
|
160 |
| -print(connectivity.status.description) # Status is either "Attached", "Online", "Offline", or "Blocked" |
| 175 | +print( |
| 176 | + connectivity.status.description |
| 177 | +) # Status is either "Attached", "Online", "Offline", or "Blocked" |
161 | 178 |
|
162 | 179 | # [endblock]
|
0 commit comments