naneos
naneos-devices: talk to naneos particle solutions devices over serial and BLE.
ConnectionType
Bases: StrEnum
How a data point reached us. Ordered by trust: serial > connected.
Source code in src/naneos/data_point.py
16 17 18 19 20 21 22 23 | |
DeviceType
Bases: IntEnum
Numeric device type as used by the upload backend. Do not renumber.
Source code in src/naneos/data_point.py
7 8 9 10 11 12 | |
NaneosDeviceDataPoint
dataclass
One measurement of one device. Every field is optional; None means "not reported".
Source code in src/naneos/data_point.py
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 | |
to_dict(remove_nan=True)
Field values by name; with remove_nan only the fields that are set.
Source code in src/naneos/data_point.py
100 101 102 103 104 105 | |
NaneosDeviceManager
Bases: Thread
Connects to every Partector on USB and BLE, gathers their data in snapshots and hands each snapshot to the output queue and / or the naneos upload.
Source code in src/naneos/manager/naneos_device_manager.py
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 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
__init__(use_serial=True, use_ble=True, upload_active=True, gathering_interval_seconds=30, ble_serial_numbers=None, ble_max_links=PartectorBleManager.DEFAULT_MAX_LINKS)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_serial
|
bool
|
connect to Partectors on USB. |
True
|
use_ble
|
bool
|
connect to Partectors over Bluetooth (data comes from the links only). |
True
|
upload_active
|
bool
|
upload every snapshot to the naneos IoT service. |
True
|
gathering_interval_seconds
|
int
|
snapshot interval, clamped to 10-600 s. |
30
|
ble_serial_numbers
|
Iterable[int] | None
|
only link to these devices over BLE; None means any in reach. |
None
|
ble_max_links
|
int
|
upper bound of simultaneous BLE links. |
DEFAULT_MAX_LINKS
|
Source code in src/naneos/manager/naneos_device_manager.py
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 | |
get_connected_ble_devices()
Returns a list of connected BLE devices.
Source code in src/naneos/manager/naneos_device_manager.py
127 128 129 130 131 132 133 134 | |
get_connected_serial_devices()
Returns a list of connected serial devices.
Source code in src/naneos/manager/naneos_device_manager.py
118 119 120 121 122 123 124 125 | |
get_pending_upload_count()
Number of snapshots waiting to be uploaded, including retries.
Source code in src/naneos/manager/naneos_device_manager.py
136 137 138 | |
get_seconds_until_next_upload()
Returns the number of seconds until the next upload. This is used to determine when to upload data.
Source code in src/naneos/manager/naneos_device_manager.py
140 141 142 143 144 145 | |
NaneosUploadThread
Bases: Thread
Source code in src/naneos/iotweb/naneos_upload_thread.py
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 | |
__init__(data, callback)
Adding the data that should be uploaded to the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[int, DataFrame]
|
Data to upload, keyed by device serial number. |
required |
callback
|
Callable[[bool], None] | None
|
Called with the upload result. |
required |
Source code in src/naneos/iotweb/naneos_upload_thread.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
build_combined_entry(data, abs_time)
classmethod
The protobuf message for a snapshot, with timestamps relative to abs_time.
Source code in src/naneos/iotweb/naneos_upload_thread.py
82 83 84 85 86 87 88 | |
get_body(upload_string)
staticmethod
The JSON envelope the backend expects around the base64 protobuf.
Source code in src/naneos/iotweb/naneos_upload_thread.py
54 55 56 57 58 59 60 61 62 63 | |
to_upload_frame(df)
staticmethod
Prepare one device frame for the backend: index in whole seconds, no inf.
Frames are indexed by unix time in milliseconds (see naneos.frames). The index is rounded, not truncated: the devices sample at ~1Hz with a phase of their own, so truncating puts the two samples that straddle a second boundary into the same second, where one of them wins, and leaves the neighbouring second without a row at all.
Source code in src/naneos/iotweb/naneos_upload_thread.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
PartectorBleManager
Bases: Thread
Connects to the Partectors in reach and collects the data they send over the link.
Only connected devices deliver data. The scanner is used to find devices, to gate connects by signal strength and to refresh stale device handles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
serial_numbers
|
Iterable[int] | None
|
Only connect to these devices. None connects to every Partector in reach, first come first served. |
None
|
max_links
|
int
|
Upper bound of simultaneous links (including ones that are still retrying). BlueZ handles about seven reliably. |
DEFAULT_MAX_LINKS
|
Source code in src/naneos/partector_ble/partector_ble_manager.py
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 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | |
get_connected_device_strings()
Devices with a live BLE link, P2 Pro first. A link whose family is not known yet is listed as P2. Devices that are only being retried are not listed.
Source code in src/naneos/partector_ble/partector_ble_manager.py
112 113 114 115 116 117 118 | |
get_connected_serial_numbers()
Serial numbers of the devices with a live BLE link.
Source code in src/naneos/partector_ble/partector_ble_manager.py
120 121 122 | |
get_data()
Returns the collected data as DataFrames and clears the buffer.
Source code in src/naneos/partector_ble/partector_ble_manager.py
91 92 93 94 95 96 97 98 99 100 | |
PartectorSerialManager
Bases: Thread
Connects to every Partector on USB, keeps the links alive and collects their data.
Source code in src/naneos/partector/partector_serial_manager.py
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 | |
get_connected_device_strings()
Human readable list of connected devices, grouped P1, P2, P2 Pro.
Source code in src/naneos/partector/partector_serial_manager.py
62 63 64 65 66 67 68 | |
get_data()
Returns the data the manager loop collected since the last call.
The devices are read by the manager thread only (see _fetch_data), so this can be called from any thread.
Source code in src/naneos/partector/partector_serial_manager.py
43 44 45 46 47 48 49 50 51 | |
get_gain_test_activating_devices()
Serial numbers of devices still warming up after a gain test was started.
Source code in src/naneos/partector/partector_serial_manager.py
70 71 72 73 | |
enable_console_logging(level=logging.INFO, colored=True)
Print naneos log messages of at least level to stderr.
Calling it again replaces the previous console handler, so the output is never duplicated. Returns the "naneos" logger.
Source code in src/naneos/logger/custom_logger.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
enable_file_logging(path, level=logging.INFO)
Append naneos log messages of at least level to a file.
path may be a directory, in which case naneos-devices.log is created in
it. Calling it again replaces the previous file handler. Returns the
"naneos" logger.
Source code in src/naneos/logger/custom_logger.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |