diff --git a/README.md b/README.md index 756d042b60fb4ab94b3b4d1f2f091024a39d9067..69c3bd5ae77f2a3ae9851827e9026ac34fd1c060 100644 --- a/README.md +++ b/README.md @@ -298,7 +298,7 @@ I only started messing around with Meshtastic last week *(as of time of this wri ##### constructor -• **new Device**(`debug?`, `configId?`): [`Device`](#classesdevicemd) +• **new Device**(`debug?`, `configId?`, `heartbeatInterval?`, `writeDelay?`): [`Device`](#classesdevicemd) Create a Device @@ -308,6 +308,8 @@ Create a Device | :------ | :------ | :------ | :------ | | `debug` | `boolean` | `false` | Enable debug logging (all sent and received frames, etc. - noisy) | | `configId?` | `number` | `undefined` | is a local identifier that appears in log messages but does not go out over the air | +| `heartbeatInterval` | `number` | `30` | is the time (in seconds) between heartbeat (keepalive) messages to the device | +| `writeDelay` | `number` | `2000` | is the time (in milliseconds) between writes of frames to the device *Notes on writeDelay:* I don't like `writeDelay`, but I found that if I sent multiple frames in quick succession some might be dropped silently despite there being room in the device's queue, and even when they didn't get dropped they were sometimes sent over the air out of sequence. It's not clear whether every frame sent to the device elicits a response to the client, so we can't necessarily wait for "ack" (To do: verify this), though this would be better than some dumb/arbitrary sleep. For now we'll a default 2000 ms between frames when writing. `2000` was arrived at by trial-and-error. This might be a problem with my device (Heltec v3), so you can try reducing this value and see what happens with your hardware. | ###### Returns @@ -319,7 +321,7 @@ js.global.EventEmitter.constructor ###### Defined in -src/lib/device.ts:45 +src/lib/device.ts:111 #### Properties @@ -331,7 +333,7 @@ A list of [Channel](https://buf.build/meshtastic/protobufs/docs/main:meshtastic# ###### Defined in -src/lib/device.ts:28 +src/lib/device.ts:72 ___ @@ -343,7 +345,7 @@ A local identifier that appears in log messages but does not go out over the air ###### Defined in -src/lib/device.ts:22 +src/lib/device.ts:66 ___ @@ -357,7 +359,7 @@ Enable debug logging (all sent and received frames, etc. - noisy) ###### Defined in -src/lib/device.ts:20 +src/lib/device.ts:64 ___ @@ -369,7 +371,7 @@ The [DeviceMetadata](https://buf.build/meshtastic/protobufs/docs/main:meshtastic ###### Defined in -src/lib/device.ts:26 +src/lib/device.ts:70 ___ @@ -381,7 +383,7 @@ Device type and connection details for log messages ###### Defined in -src/lib/device.ts:63 +src/lib/device.ts:135 ___ @@ -393,7 +395,7 @@ The [MyNodeInfo](https://buf.build/meshtastic/protobufs/docs/main:meshtastic#mes ###### Defined in -src/lib/device.ts:24 +src/lib/device.ts:68 ___ @@ -405,7 +407,7 @@ Becomes `true` once initialization has completed (configCompleteId received) ###### Defined in -src/lib/device.ts:30 +src/lib/device.ts:74 #### Methods @@ -437,7 +439,7 @@ ___ ##### beginEditSettings -▸ **beginEditSettings**(): `boolean` +▸ **beginEditSettings**(): `void` Many configuration changes will trigger a reboot of the device. If you're making several changes at once, call `beginEditSettings` beforehand, and `commitEditSettings` afterward. @@ -445,55 +447,55 @@ This will forestall the reboot until you're ready to bulk-commit your changes. ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:368 +src/lib/device.ts:467 ___ ##### cancelReboot -▸ **cancelReboot**(): `boolean` +▸ **cancelReboot**(): `void` ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:518 +src/lib/device.ts:617 ___ ##### cancelShutdown -▸ **cancelShutdown**(): `boolean` +▸ **cancelShutdown**(): `void` ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:504 +src/lib/device.ts:603 ___ ##### commitEditSettings -▸ **commitEditSettings**(): `boolean` +▸ **commitEditSettings**(): `void` The companion method to `beginEditSettings`. Call this when you're ready to commit changes and reboot. ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:379 +src/lib/device.ts:478 ___ @@ -513,7 +515,7 @@ ___ ###### Defined in -src/lib/device.ts:64 +src/lib/device.ts:136 ___ @@ -531,7 +533,7 @@ and perform maintenance. ###### Defined in -src/lib/device.ts:120 +src/lib/device.ts:193 ___ @@ -545,7 +547,7 @@ ___ ###### Defined in -src/lib/device.ts:65 +src/lib/device.ts:137 ___ @@ -594,7 +596,7 @@ ___ ##### factoryReset -▸ **factoryReset**(): `boolean` +▸ **factoryReset**(): `void` Danger Bay I've included this method here because it may be useful to provide a bootstrapping setup script for Synchronet+Meshtastic projects. @@ -602,17 +604,17 @@ Maybe we want to ensure factory defaults before applying common settings to any ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:563 +src/lib/device.ts:662 ___ ##### getChannel -▸ **getChannel**(`index`, `responseHandler`): `boolean` +▸ **getChannel**(`index`, `responseHandler`): `void` ###### Parameters @@ -623,17 +625,17 @@ ___ ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:434 +src/lib/device.ts:533 ___ ##### getConfig -▸ **getConfig**(`configType`, `responseHandler`): `boolean` +▸ **getConfig**(`configType`, `responseHandler`): `void` ###### Parameters @@ -644,17 +646,17 @@ ___ ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:444 +src/lib/device.ts:543 ___ ##### getMetadata -▸ **getMetadata**(`nodeNum`, `responseHandler`): `boolean` +▸ **getMetadata**(`nodeNum`, `responseHandler`): `void` ###### Parameters @@ -665,17 +667,17 @@ ___ ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:474 +src/lib/device.ts:573 ___ ##### getModuleConfig -▸ **getModuleConfig**(`moduleConfigType`, `responseHandler`): `boolean` +▸ **getModuleConfig**(`moduleConfigType`, `responseHandler`): `void` ###### Parameters @@ -686,11 +688,11 @@ ___ ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:454 +src/lib/device.ts:553 ___ @@ -716,13 +718,13 @@ This way, we can make that change without breaking stuff. ###### Defined in -src/lib/device.ts:591 +src/lib/device.ts:691 ___ ##### getOwner -▸ **getOwner**(`responseHandler`): `boolean` +▸ **getOwner**(`responseHandler`): `void` ###### Parameters @@ -732,11 +734,11 @@ ___ ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:464 +src/lib/device.ts:563 ___ @@ -906,13 +908,13 @@ Any associated event listeners (callbacks), ack or response handlers will be cal ###### Defined in -src/lib/device.ts:250 +src/lib/device.ts:331 ___ ##### reboot -▸ **reboot**(`seconds`): `boolean` +▸ **reboot**(`seconds`): `void` ###### Parameters @@ -922,11 +924,11 @@ ___ ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:508 +src/lib/device.ts:607 ___ @@ -956,15 +958,15 @@ ___ ##### removeFixedPosition -▸ **removeFixedPosition**(): `boolean` +▸ **removeFixedPosition**(): `void` ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:548 +src/lib/device.ts:647 ___ @@ -995,21 +997,21 @@ ___ ##### resetNodes -▸ **resetNodes**(): `boolean` +▸ **resetNodes**(): `void` ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:484 +src/lib/device.ts:583 ___ ##### sendAdminMessage -▸ **sendAdminMessage**(`adminMessage`, `responseHandler?`, `to?`): `boolean` +▸ **sendAdminMessage**(`adminMessage`, `responseHandler?`, `to?`): `void` Send an [AdminMessage](https://buf.build/meshtastic/protobufs/docs/main:meshtastic#meshtastic.AdminMessage) to the device @@ -1023,11 +1025,11 @@ Send an [AdminMessage](https://buf.build/meshtastic/protobufs/docs/main:meshtast ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:353 +src/lib/device.ts:452 ___ @@ -1043,13 +1045,13 @@ You probably don't need to call this directly. It's only really needed for Seria ###### Defined in -src/lib/device.ts:574 +src/lib/device.ts:673 ___ ##### sendPacket -▸ **sendPacket**(`«destructured»`): `boolean` +▸ **sendPacket**(`«destructured»`): `void` Assembles a [MeshPacket](https://buf.build/meshtastic/protobufs/docs/main:meshtastic#meshtastic.MeshPacket) based on your parameters and writes it to the device. @@ -1061,17 +1063,17 @@ Assembles a [MeshPacket](https://buf.build/meshtastic/protobufs/docs/main:meshta ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:273 +src/lib/device.ts:371 ___ ##### sendText -▸ **sendText**(`«destructured»`): `boolean` +▸ **sendText**(`«destructured»`): `void` Send a text message out into the mesh, optionally specifying a 'to' node address, channel, want-acknowledgement, and acknowledgement handler @@ -1083,17 +1085,17 @@ Send a text message out into the mesh, optionally specifying a 'to' node address ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:332 +src/lib/device.ts:427 ___ ##### setChannel -▸ **setChannel**(`channel`): `boolean` +▸ **setChannel**(`channel`): `void` ###### Parameters @@ -1103,17 +1105,17 @@ ___ ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:419 +src/lib/device.ts:518 ___ ##### setConfig -▸ **setConfig**(`config`): `boolean` +▸ **setConfig**(`config`): `void` ###### Parameters @@ -1123,17 +1125,17 @@ ___ ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:389 +src/lib/device.ts:488 ___ ##### setFixedPosition -▸ **setFixedPosition**(`position`): `boolean` +▸ **setFixedPosition**(`position`): `void` ###### Parameters @@ -1143,17 +1145,17 @@ ___ ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:538 +src/lib/device.ts:637 ___ ##### setHamMode -▸ **setHamMode**(`callSign`, `txPower`, `frequency`, `shortName?`): `boolean` +▸ **setHamMode**(`callSign`, `txPower`, `frequency`, `shortName?`): `void` ###### Parameters @@ -1166,17 +1168,17 @@ ___ ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:522 +src/lib/device.ts:621 ___ ##### setModuleConfig -▸ **setModuleConfig**(`moduleConfig`): `boolean` +▸ **setModuleConfig**(`moduleConfig`): `void` ###### Parameters @@ -1186,17 +1188,17 @@ ___ ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:399 +src/lib/device.ts:498 ___ ##### setOwner -▸ **setOwner**(`owner`): `boolean` +▸ **setOwner**(`owner`): `void` ###### Parameters @@ -1206,17 +1208,17 @@ ___ ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:409 +src/lib/device.ts:508 ___ ##### setPosition -▸ **setPosition**(`position`): `boolean` +▸ **setPosition**(`position`): `void` ###### Parameters @@ -1226,17 +1228,17 @@ ___ ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:429 +src/lib/device.ts:528 ___ ##### shutdown -▸ **shutdown**(`seconds`): `boolean` +▸ **shutdown**(`seconds`): `void` ###### Parameters @@ -1246,17 +1248,17 @@ ___ ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:494 +src/lib/device.ts:593 ___ ##### write -▸ **write**(`packet`): `boolean` +▸ **write**(`packet`): `void` Write a [ToRadio](https://buf.build/meshtastic/protobufs/docs/main:meshtastic#meshtastic.ToRadio) message to the device @@ -1268,11 +1270,11 @@ Write a [ToRadio](https://buf.build/meshtastic/protobufs/docs/main:meshtastic#me ###### Returns -`boolean` +`void` ###### Defined in -src/lib/device.ts:263 +src/lib/device.ts:358 <a name="classesserialdevicemd"></a> @@ -1353,7 +1355,7 @@ src/lib/device.ts:263 ##### constructor -• **new SerialDevice**(`port`, `baud`, `pollInterval?`, `heartbeatInterval?`, `debug?`, `configId?`): [`SerialDevice`](#classesserialdevicemd) +• **new SerialDevice**(`port`, `baud`, `pollInterval?`, `debug?`, `configId?`): [`SerialDevice`](#classesserialdevicemd) Create a SerialDevice @@ -1364,7 +1366,6 @@ Create a SerialDevice | `port` | `string` | `undefined` | The serial device path/name, eg. '/dev/ttyACM0', 'COM4' | | `baud` | `number` | `undefined` | The baud rate for the serial connection, eg. 115200, 921600 | | `pollInterval` | `number` | `10` | How often to check for incoming data from the device (in seconds) | -| `heartbeatInterval` | `number` | `30` | How often to send the heartbeat/keepalive message (in seconds) | | `debug` | `boolean` | `false` | Enable debug logging (all sent and received frames, etc. - noisy) | | `configId?` | `number` | `undefined` | Local identifier that appears in log messages but does not go out over the air | @@ -1378,7 +1379,7 @@ Create a SerialDevice ###### Defined in -src/lib/serial-device.ts:25 +src/lib/serial-device.ts:22 #### Properties @@ -1394,7 +1395,7 @@ A list of [Channel](https://buf.build/meshtastic/protobufs/docs/main:meshtastic# ###### Defined in -src/lib/device.ts:28 +src/lib/device.ts:72 ___ @@ -1410,7 +1411,7 @@ A local identifier that appears in log messages but does not go out over the air ###### Defined in -src/lib/device.ts:22 +src/lib/device.ts:66 ___ @@ -1428,7 +1429,7 @@ Enable debug logging (all sent and received frames, etc. - noisy) ###### Defined in -src/lib/device.ts:20 +src/lib/device.ts:64 ___ @@ -1444,7 +1445,7 @@ The [DeviceMetadata](https://buf.build/meshtastic/protobufs/docs/main:meshtastic ###### Defined in -src/lib/device.ts:26 +src/lib/device.ts:70 ___ @@ -1488,7 +1489,7 @@ The [MyNodeInfo](https://buf.build/meshtastic/protobufs/docs/main:meshtastic#mes ###### Defined in -src/lib/device.ts:24 +src/lib/device.ts:68 ___ @@ -1504,7 +1505,7 @@ Becomes `true` once initialization has completed (configCompleteId received) ###### Defined in -src/lib/device.ts:30 +src/lib/device.ts:74 #### Methods @@ -1536,7 +1537,7 @@ ___ ##### beginEditSettings -▸ **beginEditSettings**(): `boolean` +▸ **beginEditSettings**(): `void` Many configuration changes will trigger a reboot of the device. If you're making several changes at once, call `beginEditSettings` beforehand, and `commitEditSettings` afterward. @@ -1544,7 +1545,7 @@ This will forestall the reboot until you're ready to bulk-commit your changes. ###### Returns -`boolean` +`void` ###### Inherited from @@ -1552,17 +1553,17 @@ This will forestall the reboot until you're ready to bulk-commit your changes. ###### Defined in -src/lib/device.ts:368 +src/lib/device.ts:467 ___ ##### cancelReboot -▸ **cancelReboot**(): `boolean` +▸ **cancelReboot**(): `void` ###### Returns -`boolean` +`void` ###### Inherited from @@ -1570,17 +1571,17 @@ ___ ###### Defined in -src/lib/device.ts:518 +src/lib/device.ts:617 ___ ##### cancelShutdown -▸ **cancelShutdown**(): `boolean` +▸ **cancelShutdown**(): `void` ###### Returns -`boolean` +`void` ###### Inherited from @@ -1588,19 +1589,19 @@ ___ ###### Defined in -src/lib/device.ts:504 +src/lib/device.ts:603 ___ ##### commitEditSettings -▸ **commitEditSettings**(): `boolean` +▸ **commitEditSettings**(): `void` The companion method to `beginEditSettings`. Call this when you're ready to commit changes and reboot. ###### Returns -`boolean` +`void` ###### Inherited from @@ -1608,7 +1609,7 @@ The companion method to `beginEditSettings`. Call this when you're ready to comm ###### Defined in -src/lib/device.ts:379 +src/lib/device.ts:478 ___ @@ -1634,7 +1635,7 @@ Connect to the device and initialize ###### Defined in -src/lib/serial-device.ts:38 +src/lib/serial-device.ts:34 ___ @@ -1656,7 +1657,7 @@ and perform maintenance. ###### Defined in -src/lib/device.ts:120 +src/lib/device.ts:193 ___ @@ -1676,7 +1677,7 @@ Close the connection and cancel any timed events. ###### Defined in -src/lib/serial-device.ts:49 +src/lib/serial-device.ts:44 ___ @@ -1725,7 +1726,7 @@ ___ ##### factoryReset -▸ **factoryReset**(): `boolean` +▸ **factoryReset**(): `void` Danger Bay I've included this method here because it may be useful to provide a bootstrapping setup script for Synchronet+Meshtastic projects. @@ -1733,7 +1734,7 @@ Maybe we want to ensure factory defaults before applying common settings to any ###### Returns -`boolean` +`void` ###### Inherited from @@ -1741,13 +1742,13 @@ Maybe we want to ensure factory defaults before applying common settings to any ###### Defined in -src/lib/device.ts:563 +src/lib/device.ts:662 ___ ##### getChannel -▸ **getChannel**(`index`, `responseHandler`): `boolean` +▸ **getChannel**(`index`, `responseHandler`): `void` ###### Parameters @@ -1758,7 +1759,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -1766,13 +1767,13 @@ ___ ###### Defined in -src/lib/device.ts:434 +src/lib/device.ts:533 ___ ##### getConfig -▸ **getConfig**(`configType`, `responseHandler`): `boolean` +▸ **getConfig**(`configType`, `responseHandler`): `void` ###### Parameters @@ -1783,7 +1784,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -1791,13 +1792,13 @@ ___ ###### Defined in -src/lib/device.ts:444 +src/lib/device.ts:543 ___ ##### getMetadata -▸ **getMetadata**(`nodeNum`, `responseHandler`): `boolean` +▸ **getMetadata**(`nodeNum`, `responseHandler`): `void` ###### Parameters @@ -1808,7 +1809,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -1816,13 +1817,13 @@ ___ ###### Defined in -src/lib/device.ts:474 +src/lib/device.ts:573 ___ ##### getModuleConfig -▸ **getModuleConfig**(`moduleConfigType`, `responseHandler`): `boolean` +▸ **getModuleConfig**(`moduleConfigType`, `responseHandler`): `void` ###### Parameters @@ -1833,7 +1834,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -1841,7 +1842,7 @@ ___ ###### Defined in -src/lib/device.ts:454 +src/lib/device.ts:553 ___ @@ -1871,13 +1872,13 @@ This way, we can make that change without breaking stuff. ###### Defined in -src/lib/device.ts:591 +src/lib/device.ts:691 ___ ##### getOwner -▸ **getOwner**(`responseHandler`): `boolean` +▸ **getOwner**(`responseHandler`): `void` ###### Parameters @@ -1887,7 +1888,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -1895,7 +1896,7 @@ ___ ###### Defined in -src/lib/device.ts:464 +src/lib/device.ts:563 ___ @@ -2069,13 +2070,13 @@ Any associated event listeners (callbacks), ack or response handlers will be cal ###### Defined in -src/lib/device.ts:250 +src/lib/device.ts:331 ___ ##### reboot -▸ **reboot**(`seconds`): `boolean` +▸ **reboot**(`seconds`): `void` ###### Parameters @@ -2085,7 +2086,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -2093,7 +2094,7 @@ ___ ###### Defined in -src/lib/device.ts:508 +src/lib/device.ts:607 ___ @@ -2123,11 +2124,11 @@ ___ ##### removeFixedPosition -▸ **removeFixedPosition**(): `boolean` +▸ **removeFixedPosition**(): `void` ###### Returns -`boolean` +`void` ###### Inherited from @@ -2135,7 +2136,7 @@ ___ ###### Defined in -src/lib/device.ts:548 +src/lib/device.ts:647 ___ @@ -2166,11 +2167,11 @@ ___ ##### resetNodes -▸ **resetNodes**(): `boolean` +▸ **resetNodes**(): `void` ###### Returns -`boolean` +`void` ###### Inherited from @@ -2178,13 +2179,13 @@ ___ ###### Defined in -src/lib/device.ts:484 +src/lib/device.ts:583 ___ ##### sendAdminMessage -▸ **sendAdminMessage**(`adminMessage`, `responseHandler?`, `to?`): `boolean` +▸ **sendAdminMessage**(`adminMessage`, `responseHandler?`, `to?`): `void` Send an [AdminMessage](https://buf.build/meshtastic/protobufs/docs/main:meshtastic#meshtastic.AdminMessage) to the device @@ -2198,7 +2199,7 @@ Send an [AdminMessage](https://buf.build/meshtastic/protobufs/docs/main:meshtast ###### Returns -`boolean` +`void` ###### Inherited from @@ -2206,7 +2207,7 @@ Send an [AdminMessage](https://buf.build/meshtastic/protobufs/docs/main:meshtast ###### Defined in -src/lib/device.ts:353 +src/lib/device.ts:452 ___ @@ -2226,13 +2227,13 @@ You probably don't need to call this directly. It's only really needed for Seria ###### Defined in -src/lib/device.ts:574 +src/lib/device.ts:673 ___ ##### sendPacket -▸ **sendPacket**(`«destructured»`): `boolean` +▸ **sendPacket**(`«destructured»`): `void` Assembles a [MeshPacket](https://buf.build/meshtastic/protobufs/docs/main:meshtastic#meshtastic.MeshPacket) based on your parameters and writes it to the device. @@ -2244,7 +2245,7 @@ Assembles a [MeshPacket](https://buf.build/meshtastic/protobufs/docs/main:meshta ###### Returns -`boolean` +`void` ###### Inherited from @@ -2252,13 +2253,13 @@ Assembles a [MeshPacket](https://buf.build/meshtastic/protobufs/docs/main:meshta ###### Defined in -src/lib/device.ts:273 +src/lib/device.ts:371 ___ ##### sendText -▸ **sendText**(`«destructured»`): `boolean` +▸ **sendText**(`«destructured»`): `void` Send a text message out into the mesh, optionally specifying a 'to' node address, channel, want-acknowledgement, and acknowledgement handler @@ -2270,7 +2271,7 @@ Send a text message out into the mesh, optionally specifying a 'to' node address ###### Returns -`boolean` +`void` ###### Inherited from @@ -2278,13 +2279,13 @@ Send a text message out into the mesh, optionally specifying a 'to' node address ###### Defined in -src/lib/device.ts:332 +src/lib/device.ts:427 ___ ##### setChannel -▸ **setChannel**(`channel`): `boolean` +▸ **setChannel**(`channel`): `void` ###### Parameters @@ -2294,7 +2295,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -2302,13 +2303,13 @@ ___ ###### Defined in -src/lib/device.ts:419 +src/lib/device.ts:518 ___ ##### setConfig -▸ **setConfig**(`config`): `boolean` +▸ **setConfig**(`config`): `void` ###### Parameters @@ -2318,7 +2319,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -2326,13 +2327,13 @@ ___ ###### Defined in -src/lib/device.ts:389 +src/lib/device.ts:488 ___ ##### setFixedPosition -▸ **setFixedPosition**(`position`): `boolean` +▸ **setFixedPosition**(`position`): `void` ###### Parameters @@ -2342,7 +2343,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -2350,13 +2351,13 @@ ___ ###### Defined in -src/lib/device.ts:538 +src/lib/device.ts:637 ___ ##### setHamMode -▸ **setHamMode**(`callSign`, `txPower`, `frequency`, `shortName?`): `boolean` +▸ **setHamMode**(`callSign`, `txPower`, `frequency`, `shortName?`): `void` ###### Parameters @@ -2369,7 +2370,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -2377,13 +2378,13 @@ ___ ###### Defined in -src/lib/device.ts:522 +src/lib/device.ts:621 ___ ##### setModuleConfig -▸ **setModuleConfig**(`moduleConfig`): `boolean` +▸ **setModuleConfig**(`moduleConfig`): `void` ###### Parameters @@ -2393,7 +2394,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -2401,13 +2402,13 @@ ___ ###### Defined in -src/lib/device.ts:399 +src/lib/device.ts:498 ___ ##### setOwner -▸ **setOwner**(`owner`): `boolean` +▸ **setOwner**(`owner`): `void` ###### Parameters @@ -2417,7 +2418,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -2425,13 +2426,13 @@ ___ ###### Defined in -src/lib/device.ts:409 +src/lib/device.ts:508 ___ ##### setPosition -▸ **setPosition**(`position`): `boolean` +▸ **setPosition**(`position`): `void` ###### Parameters @@ -2441,7 +2442,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -2449,13 +2450,13 @@ ___ ###### Defined in -src/lib/device.ts:429 +src/lib/device.ts:528 ___ ##### shutdown -▸ **shutdown**(`seconds`): `boolean` +▸ **shutdown**(`seconds`): `void` ###### Parameters @@ -2465,7 +2466,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -2473,13 +2474,13 @@ ___ ###### Defined in -src/lib/device.ts:494 +src/lib/device.ts:593 ___ ##### write -▸ **write**(`packet`): `boolean` +▸ **write**(`packet`): `void` Write a [ToRadio](https://buf.build/meshtastic/protobufs/docs/main:meshtastic#meshtastic.ToRadio) message to the device @@ -2491,7 +2492,7 @@ Write a [ToRadio](https://buf.build/meshtastic/protobufs/docs/main:meshtastic#me ###### Returns -`boolean` +`void` ###### Inherited from @@ -2499,7 +2500,7 @@ Write a [ToRadio](https://buf.build/meshtastic/protobufs/docs/main:meshtastic#me ###### Defined in -src/lib/device.ts:263 +src/lib/device.ts:358 <a name="classessocketdevicemd"></a> @@ -2605,7 +2606,7 @@ Create a SocketDevice ###### Defined in -src/lib/socket-device.ts:23 +src/lib/socket-device.ts:24 #### Properties @@ -2621,7 +2622,7 @@ A list of [Channel](https://buf.build/meshtastic/protobufs/docs/main:meshtastic# ###### Defined in -src/lib/device.ts:28 +src/lib/device.ts:72 ___ @@ -2637,7 +2638,7 @@ A local identifier that appears in log messages but does not go out over the air ###### Defined in -src/lib/device.ts:22 +src/lib/device.ts:66 ___ @@ -2655,7 +2656,7 @@ Enable debug logging (all sent and received frames, etc. - noisy) ###### Defined in -src/lib/device.ts:20 +src/lib/device.ts:64 ___ @@ -2671,7 +2672,7 @@ The [DeviceMetadata](https://buf.build/meshtastic/protobufs/docs/main:meshtastic ###### Defined in -src/lib/device.ts:26 +src/lib/device.ts:70 ___ @@ -2687,7 +2688,7 @@ Device type and connection details for log messages ###### Defined in -src/lib/socket-device.ts:7 +src/lib/socket-device.ts:8 ___ @@ -2699,7 +2700,7 @@ The device hostname or IP address ###### Defined in -src/lib/socket-device.ts:9 +src/lib/socket-device.ts:10 ___ @@ -2715,7 +2716,7 @@ The [MyNodeInfo](https://buf.build/meshtastic/protobufs/docs/main:meshtastic#mes ###### Defined in -src/lib/device.ts:24 +src/lib/device.ts:68 ___ @@ -2727,7 +2728,7 @@ The TCP port to connect to (default: 4403) ###### Defined in -src/lib/socket-device.ts:11 +src/lib/socket-device.ts:12 ___ @@ -2743,7 +2744,7 @@ Becomes `true` once initialization has completed (configCompleteId received) ###### Defined in -src/lib/device.ts:30 +src/lib/device.ts:74 ___ @@ -2755,7 +2756,7 @@ A Synchronet JavaScript [Socket Class](https://synchro.net/docs/jsobjs.html#Sock ###### Defined in -src/lib/socket-device.ts:13 +src/lib/socket-device.ts:14 #### Methods @@ -2787,7 +2788,7 @@ ___ ##### beginEditSettings -▸ **beginEditSettings**(): `boolean` +▸ **beginEditSettings**(): `void` Many configuration changes will trigger a reboot of the device. If you're making several changes at once, call `beginEditSettings` beforehand, and `commitEditSettings` afterward. @@ -2795,7 +2796,7 @@ This will forestall the reboot until you're ready to bulk-commit your changes. ###### Returns -`boolean` +`void` ###### Inherited from @@ -2803,17 +2804,17 @@ This will forestall the reboot until you're ready to bulk-commit your changes. ###### Defined in -src/lib/device.ts:368 +src/lib/device.ts:467 ___ ##### cancelReboot -▸ **cancelReboot**(): `boolean` +▸ **cancelReboot**(): `void` ###### Returns -`boolean` +`void` ###### Inherited from @@ -2821,17 +2822,17 @@ ___ ###### Defined in -src/lib/device.ts:518 +src/lib/device.ts:617 ___ ##### cancelShutdown -▸ **cancelShutdown**(): `boolean` +▸ **cancelShutdown**(): `void` ###### Returns -`boolean` +`void` ###### Inherited from @@ -2839,19 +2840,19 @@ ___ ###### Defined in -src/lib/device.ts:504 +src/lib/device.ts:603 ___ ##### commitEditSettings -▸ **commitEditSettings**(): `boolean` +▸ **commitEditSettings**(): `void` The companion method to `beginEditSettings`. Call this when you're ready to commit changes and reboot. ###### Returns -`boolean` +`void` ###### Inherited from @@ -2859,7 +2860,7 @@ The companion method to `beginEditSettings`. Call this when you're ready to comm ###### Defined in -src/lib/device.ts:379 +src/lib/device.ts:478 ___ @@ -2885,7 +2886,7 @@ Connect to the device and initialize ###### Defined in -src/lib/socket-device.ts:36 +src/lib/socket-device.ts:37 ___ @@ -2907,7 +2908,7 @@ and perform maintenance. ###### Defined in -src/lib/device.ts:120 +src/lib/device.ts:193 ___ @@ -2927,7 +2928,7 @@ Close the connection and cancel any timed events. ###### Defined in -src/lib/socket-device.ts:46 +src/lib/socket-device.ts:47 ___ @@ -2976,7 +2977,7 @@ ___ ##### factoryReset -▸ **factoryReset**(): `boolean` +▸ **factoryReset**(): `void` Danger Bay I've included this method here because it may be useful to provide a bootstrapping setup script for Synchronet+Meshtastic projects. @@ -2984,7 +2985,7 @@ Maybe we want to ensure factory defaults before applying common settings to any ###### Returns -`boolean` +`void` ###### Inherited from @@ -2992,13 +2993,13 @@ Maybe we want to ensure factory defaults before applying common settings to any ###### Defined in -src/lib/device.ts:563 +src/lib/device.ts:662 ___ ##### getChannel -▸ **getChannel**(`index`, `responseHandler`): `boolean` +▸ **getChannel**(`index`, `responseHandler`): `void` ###### Parameters @@ -3009,7 +3010,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -3017,13 +3018,13 @@ ___ ###### Defined in -src/lib/device.ts:434 +src/lib/device.ts:533 ___ ##### getConfig -▸ **getConfig**(`configType`, `responseHandler`): `boolean` +▸ **getConfig**(`configType`, `responseHandler`): `void` ###### Parameters @@ -3034,7 +3035,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -3042,13 +3043,13 @@ ___ ###### Defined in -src/lib/device.ts:444 +src/lib/device.ts:543 ___ ##### getMetadata -▸ **getMetadata**(`nodeNum`, `responseHandler`): `boolean` +▸ **getMetadata**(`nodeNum`, `responseHandler`): `void` ###### Parameters @@ -3059,7 +3060,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -3067,13 +3068,13 @@ ___ ###### Defined in -src/lib/device.ts:474 +src/lib/device.ts:573 ___ ##### getModuleConfig -▸ **getModuleConfig**(`moduleConfigType`, `responseHandler`): `boolean` +▸ **getModuleConfig**(`moduleConfigType`, `responseHandler`): `void` ###### Parameters @@ -3084,7 +3085,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -3092,7 +3093,7 @@ ___ ###### Defined in -src/lib/device.ts:454 +src/lib/device.ts:553 ___ @@ -3122,13 +3123,13 @@ This way, we can make that change without breaking stuff. ###### Defined in -src/lib/device.ts:591 +src/lib/device.ts:691 ___ ##### getOwner -▸ **getOwner**(`responseHandler`): `boolean` +▸ **getOwner**(`responseHandler`): `void` ###### Parameters @@ -3138,7 +3139,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -3146,7 +3147,7 @@ ___ ###### Defined in -src/lib/device.ts:464 +src/lib/device.ts:563 ___ @@ -3320,13 +3321,13 @@ Any associated event listeners (callbacks), ack or response handlers will be cal ###### Defined in -src/lib/device.ts:250 +src/lib/device.ts:331 ___ ##### reboot -▸ **reboot**(`seconds`): `boolean` +▸ **reboot**(`seconds`): `void` ###### Parameters @@ -3336,7 +3337,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -3344,7 +3345,7 @@ ___ ###### Defined in -src/lib/device.ts:508 +src/lib/device.ts:607 ___ @@ -3374,11 +3375,11 @@ ___ ##### removeFixedPosition -▸ **removeFixedPosition**(): `boolean` +▸ **removeFixedPosition**(): `void` ###### Returns -`boolean` +`void` ###### Inherited from @@ -3386,7 +3387,7 @@ ___ ###### Defined in -src/lib/device.ts:548 +src/lib/device.ts:647 ___ @@ -3417,11 +3418,11 @@ ___ ##### resetNodes -▸ **resetNodes**(): `boolean` +▸ **resetNodes**(): `void` ###### Returns -`boolean` +`void` ###### Inherited from @@ -3429,13 +3430,13 @@ ___ ###### Defined in -src/lib/device.ts:484 +src/lib/device.ts:583 ___ ##### sendAdminMessage -▸ **sendAdminMessage**(`adminMessage`, `responseHandler?`, `to?`): `boolean` +▸ **sendAdminMessage**(`adminMessage`, `responseHandler?`, `to?`): `void` Send an [AdminMessage](https://buf.build/meshtastic/protobufs/docs/main:meshtastic#meshtastic.AdminMessage) to the device @@ -3449,7 +3450,7 @@ Send an [AdminMessage](https://buf.build/meshtastic/protobufs/docs/main:meshtast ###### Returns -`boolean` +`void` ###### Inherited from @@ -3457,7 +3458,7 @@ Send an [AdminMessage](https://buf.build/meshtastic/protobufs/docs/main:meshtast ###### Defined in -src/lib/device.ts:353 +src/lib/device.ts:452 ___ @@ -3477,13 +3478,13 @@ You probably don't need to call this directly. It's only really needed for Seria ###### Defined in -src/lib/device.ts:574 +src/lib/device.ts:673 ___ ##### sendPacket -▸ **sendPacket**(`«destructured»`): `boolean` +▸ **sendPacket**(`«destructured»`): `void` Assembles a [MeshPacket](https://buf.build/meshtastic/protobufs/docs/main:meshtastic#meshtastic.MeshPacket) based on your parameters and writes it to the device. @@ -3495,7 +3496,7 @@ Assembles a [MeshPacket](https://buf.build/meshtastic/protobufs/docs/main:meshta ###### Returns -`boolean` +`void` ###### Inherited from @@ -3503,13 +3504,13 @@ Assembles a [MeshPacket](https://buf.build/meshtastic/protobufs/docs/main:meshta ###### Defined in -src/lib/device.ts:273 +src/lib/device.ts:371 ___ ##### sendText -▸ **sendText**(`«destructured»`): `boolean` +▸ **sendText**(`«destructured»`): `void` Send a text message out into the mesh, optionally specifying a 'to' node address, channel, want-acknowledgement, and acknowledgement handler @@ -3521,7 +3522,7 @@ Send a text message out into the mesh, optionally specifying a 'to' node address ###### Returns -`boolean` +`void` ###### Inherited from @@ -3529,13 +3530,13 @@ Send a text message out into the mesh, optionally specifying a 'to' node address ###### Defined in -src/lib/device.ts:332 +src/lib/device.ts:427 ___ ##### setChannel -▸ **setChannel**(`channel`): `boolean` +▸ **setChannel**(`channel`): `void` ###### Parameters @@ -3545,7 +3546,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -3553,13 +3554,13 @@ ___ ###### Defined in -src/lib/device.ts:419 +src/lib/device.ts:518 ___ ##### setConfig -▸ **setConfig**(`config`): `boolean` +▸ **setConfig**(`config`): `void` ###### Parameters @@ -3569,7 +3570,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -3577,13 +3578,13 @@ ___ ###### Defined in -src/lib/device.ts:389 +src/lib/device.ts:488 ___ ##### setFixedPosition -▸ **setFixedPosition**(`position`): `boolean` +▸ **setFixedPosition**(`position`): `void` ###### Parameters @@ -3593,7 +3594,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -3601,13 +3602,13 @@ ___ ###### Defined in -src/lib/device.ts:538 +src/lib/device.ts:637 ___ ##### setHamMode -▸ **setHamMode**(`callSign`, `txPower`, `frequency`, `shortName?`): `boolean` +▸ **setHamMode**(`callSign`, `txPower`, `frequency`, `shortName?`): `void` ###### Parameters @@ -3620,7 +3621,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -3628,13 +3629,13 @@ ___ ###### Defined in -src/lib/device.ts:522 +src/lib/device.ts:621 ___ ##### setModuleConfig -▸ **setModuleConfig**(`moduleConfig`): `boolean` +▸ **setModuleConfig**(`moduleConfig`): `void` ###### Parameters @@ -3644,7 +3645,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -3652,13 +3653,13 @@ ___ ###### Defined in -src/lib/device.ts:399 +src/lib/device.ts:498 ___ ##### setOwner -▸ **setOwner**(`owner`): `boolean` +▸ **setOwner**(`owner`): `void` ###### Parameters @@ -3668,7 +3669,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -3676,13 +3677,13 @@ ___ ###### Defined in -src/lib/device.ts:409 +src/lib/device.ts:508 ___ ##### setPosition -▸ **setPosition**(`position`): `boolean` +▸ **setPosition**(`position`): `void` ###### Parameters @@ -3692,7 +3693,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -3700,13 +3701,13 @@ ___ ###### Defined in -src/lib/device.ts:429 +src/lib/device.ts:528 ___ ##### shutdown -▸ **shutdown**(`seconds`): `boolean` +▸ **shutdown**(`seconds`): `void` ###### Parameters @@ -3716,7 +3717,7 @@ ___ ###### Returns -`boolean` +`void` ###### Inherited from @@ -3724,13 +3725,13 @@ ___ ###### Defined in -src/lib/device.ts:494 +src/lib/device.ts:593 ___ ##### write -▸ **write**(`packet`): `boolean` +▸ **write**(`packet`): `void` Write a [ToRadio](https://buf.build/meshtastic/protobufs/docs/main:meshtastic#meshtastic.ToRadio) message to the device @@ -3742,7 +3743,7 @@ Write a [ToRadio](https://buf.build/meshtastic/protobufs/docs/main:meshtastic#me ###### Returns -`boolean` +`void` ###### Inherited from @@ -3750,7 +3751,7 @@ Write a [ToRadio](https://buf.build/meshtastic/protobufs/docs/main:meshtastic#me ###### Defined in -src/lib/device.ts:263 +src/lib/device.ts:358 ## Enums diff --git a/src/lib/device.ts b/src/lib/device.ts index b669757ad17fb7e817f143945273aa46acc0b567..71962fb71814cc31ac11ff5790d5e9378de91a3c 100644 --- a/src/lib/device.ts +++ b/src/lib/device.ts @@ -84,14 +84,31 @@ export default abstract class Device extends js.global.EventEmitter { private initTimeout: number; private queue: Uint8Array[]; // Queue of outbound ToRadio frames private queueEvent: number; + private writeDelay: number; private readonly timeoutMs: number = RESPONSE_TIMEOUT * 1000; /** * Create a Device * @param debug Enable debug logging (all sent and received frames, etc. - noisy) * @param configId is a local identifier that appears in log messages but does not go out over the air + * @param heartbeatInterval is the time (in seconds) between heartbeat (keepalive) messages to the device + * @param writeDelay is the time (in milliseconds) between writes of frames to the device + * + * *Notes on writeDelay:* + * + * I don't like `writeDelay`, but I found that if I sent multiple frames in quick succession + * some might be dropped silently despite there being room in the device's queue, and even + * when they didn't get dropped they were sometimes sent over the air out of sequence. + * + * It's not clear whether every frame sent to the device elicits a response to the client, + * so we can't necessarily wait for "ack" (To do: verify this), though this would be better + * than some dumb/arbitrary sleep. + * + * For now we'll a default 2000 ms between frames when writing. + * `2000` was arrived at by trial-and-error. This might be a problem with my device (Heltec v3), + * so you can try reducing this value and see what happens with your hardware. */ - constructor(debug: boolean = false, configId?: number, heartbeatInterval: number = 30) { + constructor(debug: boolean = false, configId?: number, heartbeatInterval: number = 30, writeDelay: number = 2000) { super(); this.debug = debug; this.ready = false; @@ -111,6 +128,7 @@ export default abstract class Device extends js.global.EventEmitter { this.initTimeout = CONNECT_TIMEOUT * 1000; this.queue = []; this.queueEvent = -1; + this.writeDelay = writeDelay; } /** Device type and connection details for log messages */ @@ -199,6 +217,7 @@ export default abstract class Device extends js.global.EventEmitter { // Should be called from any implementation's 'disconnect' method protected destroy(): void { if (this.readyEvent > -1) js.clearTimeout(this.readyEvent); + if (this.queueEvent > -1) js.clearTimeout(this.queueEvent); js.clearInterval(this.purgeEvent); js.clearInterval(this.heartbeatInterval); this.purgeHandlers(true); @@ -329,7 +348,7 @@ export default abstract class Device extends js.global.EventEmitter { this.lastWrite = Date.now(); if (this.queue.length > 0) { - this.queueEvent = js.setTimeout(this.dequeue, 2000, this); + this.queueEvent = js.setTimeout(this.dequeue, this.writeDelay, this); } else { this.queueEvent = -1; } @@ -344,7 +363,7 @@ export default abstract class Device extends js.global.EventEmitter { const buffer = new Uint8Array([...header, ...data]); this.queue.push(buffer); if (this.queueEvent < 0) { - this.queueEvent = js.setTimeout(this.dequeue, Math.max(200, 2000 - (Date.now() - this.lastWrite)), this); + this.queueEvent = js.setTimeout(this.dequeue, Math.max(0, this.writeDelay - (Date.now() - this.lastWrite)), this); } } diff --git a/src/lib/serial-device.ts b/src/lib/serial-device.ts index ee6e90de44febd35d7d8737a30ed0d624820b6cc..e74fea393791753a35a549b2fd11791830abfa42 100644 --- a/src/lib/serial-device.ts +++ b/src/lib/serial-device.ts @@ -55,6 +55,7 @@ export default class SerialDevice extends Device { if (byte === undefined) break; buf.push(byte); } + if (buf.length < 1) return; const data = new Uint8Array(buf); return data; } diff --git a/src/lib/socket-device.ts b/src/lib/socket-device.ts index bd4cdb7f61c3900282f00324527716faf2f69cdd..ba953deb18c1ed882b1981e772f4711c29b702a1 100644 --- a/src/lib/socket-device.ts +++ b/src/lib/socket-device.ts @@ -53,7 +53,6 @@ export default class SocketDevice extends Device { protected readFromDevice(timeout: number = 0): Uint8Array | undefined { if (timeout > 0) { - this.log(sbbsdefs.LOG_DEBUG, `waiting ${timeout} seconds for data`); const stime = js.global.time(); while (!this.socket.data_waiting && js.global.time() - stime < timeout) { js.global.mswait(5); @@ -62,12 +61,12 @@ export default class SocketDevice extends Device { if (!this.socket.data_waiting) return; - this.log(sbbsdefs.LOG_DEBUG, `reading ${this.socket.nread} bytes from device`); + if (this.debug) this.log(sbbsdefs.LOG_DEBUG, `reading ${this.socket.nread} bytes from device`); const buf = []; while (this.socket.data_waiting) { buf.push(this.socket.recvBin(1)); } - this.log(sbbsdefs.LOG_DEBUG, `read ${buf.length} bytes from device`); + if (this.debug) this.log(sbbsdefs.LOG_DEBUG, `read ${buf.length} bytes from device`); const data = new Uint8Array(buf); return data; @@ -75,6 +74,7 @@ export default class SocketDevice extends Device { protected sendToDevice(data: Uint8Array): boolean { if (!this.socket.is_connected) this.error(`disconnected from ${this.host}:${this.port}`); + if (this.debug) this.log(sbbsdefs.LOG_DEBUG, `sending ${data.length} bytes to device`); for (let n = 0; n < data.length; n++) { if (!this.socket.sendBin(data[n], 1)) return false; }