diff --git a/README.md b/README.md index 73fa960c1..cb68c9609 100644 --- a/README.md +++ b/README.md @@ -97,10 +97,10 @@ Here are some general principals you should try to adhere to: There are a number of fairly major features in the pipeline, with no particular time-frames attached yet. In very rough chronological order: - [X] Companion radio: UI redesign -- [ ] Repeater + Room Server: add ACL's (like Sensor Node has) -- [ ] Standardise Bridge mode for repeaters +- [X] Repeater + Room Server: add ACL's (like Sensor Node has) +- [X] Standardise Bridge mode for repeaters - [ ] Repeater/Bridge: Standardise the Transport Codes for zoning/filtering -- [ ] Core + Repeater: enhanced zero-hop neighbour discovery +- [X] Core + Repeater: enhanced zero-hop neighbour discovery - [ ] Core: round-trip manual path support - [ ] Companion + Apps: support for multiple sub-meshes (and 'off-grid' client repeat mode) - [ ] Core + Apps: support for LZW message compression @@ -113,12 +113,3 @@ There are a number of fairly major features in the pipeline, with no particular - Report bugs and request features on the [GitHub Issues](https://github.com/ripplebiz/MeshCore/issues) page. - Find additional guides and components on [my site](https://buymeacoffee.com/ripplebiz). - Join [MeshCore Discord](https://discord.gg/BMwCtwHj5V) to chat with the developers and get help from the community. - -## RAK Wireless Board Support in PlatformIO - -Before building/flashing the RAK4631 targets in this project, there is, unfortunately, some patching you have to do to your platformIO packages to make it work. There is a guide here on the process: - [RAK Wireless: How to Perform Installation of Board Support Package in PlatformIO](https://learn.rakwireless.com/hc/en-us/articles/26687276346775-How-To-Perform-Installation-of-Board-Support-Package-in-PlatformIO) - -After building, you will need to convert the output firmware.hex file into a .uf2 file you can copy over to your RAK4631 device (after doing a full erase) by using the command `uf2conv.py -f 0xADA52840 -c firmware.hex` with the python script available from: - [GitHub: Microsoft - uf2](https://github.com/Microsoft/uf2/blob/master/utils/uf2conv.py) - diff --git a/docs/faq.md b/docs/faq.md index efed5a864..c69077d1d 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -1,10 +1,6 @@ **MeshCore-FAQ** A list of frequently-asked questions and answers for MeshCore -The current version of this MeshCore FAQ is at https://github.com/meshcore-dev/MeshCore/blob/main/docs/faq.md. -This MeshCore FAQ is also mirrored at https://github.com/LitBomb/MeshCore-FAQ and might have newer updates if pull requests on Scott's MeshCore repo are not approved yet. - -author: https://github.com/LitBomb --- - [1. Introduction](#1-introduction) @@ -61,22 +57,23 @@ author: https://github.com/LitBomb - [5.14.3. Python MeshCore](#5143-python-meshcore) - [5.14.4. meshcore-cli](#5144-meshcore-cli) - [5.14.5. meshcore.js](#5145-meshcorejs) + - [5.14.6. pyMC\_core](#5146-pymc_core) - [6. Troubleshooting](#6-troubleshooting) - [6.1. Q: My client says another client or a repeater or a room server was last seen many, many days ago.](#61-q-my-client-says-another-client-or-a-repeater-or-a-room-server-was-last-seen-many-many-days-ago) - [6.2. Q: A repeater or a client or a room server I expect to see on my discover list (on T-Deck) or contact list (on a smart device client) are not listed.](#62-q-a-repeater-or-a-client-or-a-room-server-i-expect-to-see-on-my-discover-list-on-t-deck-or-contact-list-on-a-smart-device-client-are-not-listed) - [6.3. Q: How to connect to a repeater via BLE (Bluetooth)?](#63-q-how-to-connect-to-a-repeater-via-ble-bluetooth) - [6.4. Q: My companion isn't showing up over Bluetooth?](#64-q-my-companion-isnt-showing-up-over-bluetooth) - - [6.5. Q: I can't connect via Bluetooth, what is the Bluetooth pairing code?](#64-q-i-cant-connect-via-bluetooth-what-is-the-bluetooth-pairing-code) - - [6.6. Q: My Heltec V3 keeps disconnecting from my smartphone. It can't hold a solid Bluetooth connection.](#65-q-my-heltec-v3-keeps-disconnecting-from-my-smartphone--it-cant-hold-a-solid-bluetooth-connection) - - [6.7. Q: My RAK/T1000-E/xiao\_nRF52 device seems to be corrupted, how do I wipe it clean to start fresh?](#66-q-my-rakt1000-exiao_nrf52-device-seems-to-be-corrupted-how-do-i-wipe-it-clean-to-start-fresh) - - [6.8. Q: WebFlasher fails on Linux with failed to open](#67-q-webflasher-fails-on-linux-with-failed-to-open) + - [6.5. Q: I can't connect via Bluetooth, what is the Bluetooth pairing code?](#65-q-i-cant-connect-via-bluetooth-what-is-the-bluetooth-pairing-code) + - [6.6. Q: My Heltec V3 keeps disconnecting from my smartphone. It can't hold a solid Bluetooth connection.](#66-q-my-heltec-v3-keeps-disconnecting-from-my-smartphone--it-cant-hold-a-solid-bluetooth-connection) + - [6.7. Q: My RAK/T1000-E/xiao\_nRF52 device seems to be corrupted, how do I wipe it clean to start fresh?](#67-q-my-rakt1000-exiao_nrf52-device-seems-to-be-corrupted-how-do-i-wipe-it-clean-to-start-fresh) + - [6.8. Q: WebFlasher fails on Linux with failed to open](#68-q-webflasher-fails-on-linux-with-failed-to-open) - [7. Other Questions:](#7-other-questions) - [7.1. Q: How to update nRF (RAK, T114, Seed XIAO) repeater and room server firmware over the air using the new simpler DFU app?](#71-q-how-to-update-nrf-rak-t114-seed-xiao-repeater-and-room-server-firmware-over-the-air-using-the-new-simpler-dfu-app) - [7.2. Q: How to update ESP32-based devices over the air?](#72-q-how-to-update-esp32-based-devices-over-the-air) - [7.3. Q: Is there a way to lower the chance of a failed OTA device firmware update (DFU)?](#73-q-is-there-a-way-to-lower-the-chance-of-a-failed-ota-device-firmware-update-dfu) - [7.4. Q: are the MeshCore logo and font available?](#74-q-are-the-meshcore-logo-and-font-available) - [7.5. Q: What is the format of a contact or channel QR code?](#75-q-what-is-the-format-of-a-contact-or-channel-qr-code) - - [7.6. Q: How do I connect to the companion via WIFI, e.g. using a heltec v3?](#76-q-how-do-i-connect-to-the-comnpanion-via-wifi-eg-using-a-heltec-v3) + - [7.6. Q: How do I connect to the companion via WIFI, e.g. using a heltec v3?](#76-q-how-do-i-connect-to-the-companion-via-wifi-eg-using-a-heltec-v3) ## 1. Introduction @@ -91,7 +88,7 @@ MeshCore is free and open source: * The T-Deck firmware is developed by Scott at Ripple Radios, the creator of MeshCore, is also free to flash on your devices and use -Some more advanced, but optional features are available on T-Deck if you register your device for a key to unlock. On the MeshCore smartphone clients for Android and iOS/iPadOS, you can unlock the wait timer for repeater and room server remote management over RF feature. +Some more advanced, but optional features are available on T-Deck if you register your device for a key to unlock. On the MeshCore smartphone clients for Android and iOS/iPadOS, you can unlock the wait timer for repeater and room server remote management over RF feature. These features are completely optional and aren't needed for the core messaging experience. They're like super bonus features and to help the developers continue to work on these amazing features, they may charge a small fee for an unlock code to utilise the advanced features. @@ -105,7 +102,7 @@ Anyone is able to build anything they like on top of MeshCore without paying any MeshCore Firmware GitHub: https://github.com/ripplebiz/MeshCore NOTE: Andy Kirby has a very useful [intro video](https://www.youtube.com/watch?v=t1qne8uJBAc) for beginners. - + You need LoRa hardware devices to run MeshCore firmware as clients or server (repeater and room server). @@ -114,7 +111,7 @@ MeshCore is available on a variety of 433MHz, 868MHz and 915MHz LoRa devices. Fo For an up-to-date list of supported devices, please go to https://flasher.meshcore.co.uk/ -To use MeshCore without using a phone as the client interface, you can run MeshCore on a LiLygo's T-Deck, T-Deck Plus, T-Pager, T-Watch, or T-Display Pro. MeshCore Ultra firmware running on these devices are a complete off-grid secure communication solution. +To use MeshCore without using a phone as the client interface, you can run MeshCore on a LiLygo's T-Deck, T-Deck Plus, T-Pager, T-Watch, or T-Display Pro. MeshCore Ultra firmware running on these devices are a complete off-grid secure communication solution. #### 1.2.2. Firmware MeshCore has four firmware types that are not available on other LoRa systems. MeshCore has the following: @@ -122,30 +119,30 @@ MeshCore has four firmware types that are not available on other LoRa systems. M #### 1.2.3. Companion Radio Firmware Companion radios are for connecting to the Android app or web app as a messenger client. There are two different companion radio firmware versions: -1. **BLE Companion** - BLE Companion firmware runs on a supported LoRa device and connects to a smart device running the Android or iOS MeshCore client over BLE +1. **BLE Companion** + BLE Companion firmware runs on a supported LoRa device and connects to a smart device running the Android or iOS MeshCore client over BLE -2. **USB Serial Companion** - USB Serial Companion firmware runs on a supported LoRa device and connects to a smart device or a computer over USB Serial running the MeshCore web client - +2. **USB Serial Companion** + USB Serial Companion firmware runs on a supported LoRa device and connects to a smart device or a computer over USB Serial running the MeshCore web client + #### 1.2.4. Repeater -Repeaters are used to extend the range of a MeshCore network. Repeater firmware runs on the same devices that run client firmware. A repeater's job is to forward MeshCore packets to the destination device. It does **not** forward or retransmit every packet it receives, unlike other LoRa mesh systems. +Repeaters are used to extend the range of a MeshCore network. Repeater firmware runs on the same devices that run client firmware. A repeater's job is to forward MeshCore packets to the destination device. It does **not** forward or retransmit every packet it receives, unlike other LoRa mesh systems. A repeater can be remotely administered using a T-Deck running the MeshCore firmware with remote administration features unlocked, or from a BLE Companion client connected to a smartphone running the MeshCore app. #### 1.2.5. Room Server -A room server is a simple BBS server for sharing posts. T-Deck devices running MeshCore firmware or a BLE Companion client connected to a smartphone running the MeshCore app can connect to a room server. +A room server is a simple BBS server for sharing posts. T-Deck devices running MeshCore firmware or a BLE Companion client connected to a smartphone running the MeshCore app can connect to a room server. Room servers store message history on them and push the stored messages to users. Room servers allow roaming users to come back later and retrieve message history. With channels, messages are either received when it's sent, or not received and missed if the channel user is out of range. Room servers are different and more like email servers where you can come back later and get your emails from your mail server. -A room server can be remotely administered using a T-Deck running the MeshCore firmware with remote administration features unlocked, or from a BLE Companion client connected to a smartphone running the MeshCore app. +A room server can be remotely administered using a T-Deck running the MeshCore firmware with remote administration features unlocked, or from a BLE Companion client connected to a smartphone running the MeshCore app. When a client logs into a room server, the client will receive the previously 32 unseen messages. -Although room server can also repeat with the command line command `set repeat on`, it is not recommended nor encouraged. A room server with repeat set to `on` lacks the full set of repeater and remote administration features that are only available in the repeater firmware. +Although room server can also repeat with the command line command `set repeat on`, it is not recommended nor encouraged. A room server with repeat set to `on` lacks the full set of repeater and remote administration features that are only available in the repeater firmware. The recommendation is to run repeater and room server on separate devices for the best experience. @@ -168,37 +165,32 @@ After you flashed the latest firmware onto your repeater device, keep the device The repeater and room server CLI reference is here: https://github.com/meshcore-dev/MeshCore/wiki/Repeater-&-Room-Server-CLI-Reference -If you have more supported devices, you can use your additional devices with the room server firmware. +If you have more supported devices, you can use your additional devices with the room server firmware. ### 2.2. Q: Does MeshCore cost any money? -**A:** All radio firmware versions (e.g. for Heltec V3, RAK, T-1000E, etc) are free and open source developed by Scott at Ripple Radios. +**A:** All radio firmware versions (e.g. for Heltec V3, RAK, T-1000E, etc) are free and open source developed by Scott at Ripple Radios. -The native Android and iOS client uses the freemium model and is developed by Liam Cottle, developer of meshtastic map at [meshtastic.liamcottle.net](https://meshtastic.liamcottle.net) on [GitHub](https://github.com/liamcottle/meshtastic-map) and [reticulum-meshchat on github](https://github.com/liamcottle/reticulum-meshchat). +The native Android and iOS client uses the freemium model and is developed by Liam Cottle, developer of meshtastic map at [meshtastic.liamcottle.net](https://meshtastic.liamcottle.net) on [GitHub](https://github.com/liamcottle/meshtastic-map) and [reticulum-meshchat on github](https://github.com/liamcottle/reticulum-meshchat). -The T-Deck firmware is free to download and most features are available without cost. To support the firmware developer, you can pay for a registration key to unlock your T-Deck for deeper map zoom and remote server administration over RF using the T-Deck. You do not need to pay for the registration to use your T-Deck for direct messaging and connecting to repeaters and room servers. +The T-Deck firmware is free to download and most features are available without cost. To support the firmware developer, you can pay for a registration key to unlock your T-Deck for deeper map zoom and remote server administration over RF using the T-Deck. You do not need to pay for the registration to use your T-Deck for direct messaging and connecting to repeaters and room servers. ### 2.3. Q: What frequencies are supported by MeshCore? -**A:** It supports the 868MHz range in the UK/EU and the 915MHz range in New Zealand, Australia, and the USA. Countries and regions in these two frequency ranges are also supported. The firmware and client allow users to set their preferred frequency. -- Australia and New Zealand are on **915.8MHz** -- UK and EU are on **869.525MHz** -- Canada and USA are on **910.525MHz** -- For other regions and countries, please check your local LoRa frequency +**A:** It supports the 868MHz range in the UK/EU and the 915MHz range in New Zealand, Australia, and the USA. Countries and regions in these two frequency ranges are also supported. + +Use the smartphone client or the repeater setup feature on there web flasher to set your radios' RF settings by choosing the preset for your regions. + +Recently, as of October 2025, many regions have moved to the "narrow" setting, aka using BW62.5 and a lower SF number (instead of the original SF11). For example, USA/Canada (Recommended) preset is 910.525MHz, SF7, BW62.5, CR5. -In UK and EU, 867.5MHz is not allowed to use 250kHz bandwidth and it only allows 2.5% duty cycle for clients. 869.525Mhz allows an airtime of 10%, 250KHz bandwidth, and a higher EIRP, therefore MeshCore nodes can send more often and with more power. That is why this frequency is chosen for UK and EU. This is also why Meshtastic also uses this frequency. +After extensive testing, many regions have switched or about to switch over to BW62.5 and SF7, 8, or 9. Narrower bandwidth setting and lower SF setting allow MeshCore's radio signals to fit between interference in the ISM band, provide for a lower noise floor, better SNR, and faster transmissions. -[Source](https://discord.com/channels/826570251612323860/1330643963501351004/1356540643853209641) +If you have consensus from your community in your region to update your region's preset recommendation, please post your update request on the [#meshcore-app](https://discord.com/channels/1343693475589263471/1391681655911088241) channel on the [MeshCore Discord server ](https://discord.gg/cYtQNYCCRK) to let Liam Cottle know. -the rest of the radio settings are the same for all frequencies: -- Spread Factor (SF): 11 -- Coding Rate (CR): 5 -- Bandwidth (BW): 250.00 -(Originally MeshCore started with SF 10. recently (as of late April 2025) the community has advocated SF 11 also a viable option for longer range but a little slower transmission. Currently there are MeshCore meshes with SF 10 and SF 11. Liam Cottle's smartphone app's presets now recommend SF 10 for Australia and SF 11 for all other regions and countries. EU and UK has SF 10 and SF 11 presets. Work with your local meshers on deciding with SF number is best for your use cases. In the future, there may be bridge nodes that can bridge SF 10 and SF 11 (or even different frequencies) traffic.) ### 2.4. Q: What is an "advert" in MeshCore? -**A:** +**A:** Advert means to advertise yourself on the network. In Reticulum terms it would be to announce. In Meshtastic terms it would be the node sending its node info. MeshCore allows you to manually broadcast your name, position and public encryption key, which is also signed to prevent spoofing. When you click the advert button, it broadcasts that data over LoRa. MeshCore calls that an Advert. There's two ways to advert, "zero hop" and "flood". @@ -214,7 +206,7 @@ As of Aug 20 2025, a pending PR on github will change the flood advert to 12 hou ### 2.5. Q: Is there a hop limit? -**A:** Internally the firmware has maximum limit of 64 hops. In real world settings it will be difficult to get close to the limit due to the environments and timing as packets travel further and further. We want to hear how far your MeshCore conversations go. +**A:** Internally the firmware has maximum limit of 64 hops. In real world settings it will be difficult to get close to the limit due to the environments and timing as packets travel further and further. We want to hear how far your MeshCore conversations go. --- @@ -224,14 +216,14 @@ As of Aug 20 2025, a pending PR on github will change the flood advert to 12 hou ### 3.1. Q: How do you configure a repeater or a room server? -**A:** - When MeshCore is flashed onto a LoRa device is for the first time, it is necessary to set the server device's frequency to make it utilize the frequency that is legal in your country or region. +**A:** - When MeshCore is flashed onto a LoRa device is for the first time, it is necessary to set the server device's frequency to make it utilize the frequency that is legal in your country or region. Repeater or room server can be administered with one of the options below: - + - After a repeater or room server firmware is flashed on to a LoRa device, go to and use the web user interface to connect to the LoRa device via USB serial. From there you can set the name of the server, its frequency and other related settings, location, passwords etc. ![image](https://github.com/user-attachments/assets/2a9d9894-e34d-4dbe-b57c-fc3c250a2d34) - + - Connect the server device using a USB cable to a computer running Chrome on https://flasher.meshcore.co.uk/, then use the `console` feature to connect to the device - Use a MeshCore smartphone clients to remotely administer servers via LoRa. @@ -240,10 +232,10 @@ Repeater or room server can be administered with one of the options below: - + ### 3.2. Q: Do I need to set the location for a repeater? -**A:** With location set for a repeater, it can show up on a MeshCore map in the future. Set location with the following commands: +**A:** While not required, with location set for a repeater it will show up on the MeshCore map in the future. Set location with the following command: `set lat set long ` @@ -270,14 +262,14 @@ You can get the latitude and longitude from Google Maps by right-clicking the lo **A:** Yes, it is available on https://buymeacoffee.com/ripplebiz/ultra-v7-7-guide-meshcore-users ### 4.2. Q: What are the steps to get a T-Deck into DFU (Device Firmware Update) mode? -**A:** -1. Device off -2. Connect USB cable to device -3. Hold down trackball (keep holding) -4. Turn on device -5. Hear USB connection sound -6. Release trackball -7. T-Deck in DFU mode now +**A:** +1. Device off +2. Connect USB cable to device +3. Hold down trackball (keep holding) +4. Turn on device +5. Hear USB connection sound +6. Release trackball +7. T-Deck in DFU mode now 8. At this point you can begin flashing using ### 4.3. Q: Why is my T-Deck Plus not getting any satellite lock? @@ -294,8 +286,8 @@ GPS on T-Deck is always enabled. You can skip the "GPS clock sync" and the T-De **A:** Users have had no issues using 16GB or 32GB SD cards. Format the SD card to **FAT32**. ### 4.6. Q: what is the public key for the default public channel? -**A:** -T-Deck uses the same key the smartphone apps use but in base64 +**A:** +T-Deck uses the same key the smartphone apps use but in base64 `izOH6cXN6mrJ5e26oRXNcg==` The third character is the capital letter 'O', not zero `0` @@ -305,24 +297,24 @@ The smartphone app key is in hex: [Source](https://discord.com/channels/826570251612323860/1330643963501351004/1354194409213792388) ### 4.7. Q: How do I get maps on T-Deck? -**A:** You need map tiles. You can get pre-downloaded map tiles here (a good way to support development): -- (Europe) +**A:** You need map tiles. You can get pre-downloaded map tiles here (a good way to support development): +- (Europe) - (US) -Another way to download map tiles is to use this Python script to get the tiles in the areas you want: - +Another way to download map tiles is to use this Python script to get the tiles in the areas you want: + -There is also a modified script that adds additional error handling and parallel downloads: - +There is also a modified script that adds additional error handling and parallel downloads: + -UK map tiles are available separately from Andy Kirby on his discord server: +UK map tiles are available separately from Andy Kirby on his discord server: ### 4.8. Q: Where do the map tiles go? Once you have the tiles downloaded, copy the `\tiles` folder to the root of your T-Deck's SD card. ### 4.9. Q: How to unlock deeper map zoom and server management features on T-Deck? -**A:** You can download, install, and use the T-Deck firmware for free, but it has some features (map zoom, server administration) that are enabled if you purchase an unlock code for \$10 per T-Deck device. +**A:** You can download, install, and use the T-Deck firmware for free, but it has some features (map zoom, server administration) that are enabled if you purchase an unlock code for \$10 per T-Deck device. Unlock page: ### 4.10. Q: How to decipher the diagnostics screen on T-Deck? @@ -330,17 +322,17 @@ Unlock page: **A: ** Space is tight on T-Deck's screen, so the information is a bit cryptic. The format is : `{hops} l:{packet-length}({payload-len}) t:{packet-type} snr:{n} rssi:{n}` -See here for packet-type: +See here for packet-type: https://github.com/meshcore-dev/MeshCore/blob/main/src/Packet.h#L19 - - - #define PAYLOAD_TYPE_REQ 0x00 // request (prefixed with dest/src hashes, MAC) (enc data: timestamp, blob) - #define PAYLOAD_TYPE_RESPONSE 0x01 // response to REQ or ANON_REQ (prefixed with dest/src hashes, MAC) (enc data: timestamp, blob) - #define PAYLOAD_TYPE_TXT_MSG 0x02 // a plain text message (prefixed with dest/src hashes, MAC) (enc data: timestamp, text) - #define PAYLOAD_TYPE_ACK 0x03 // a simple ack #define PAYLOAD_TYPE_ADVERT 0x04 // a node advertising its Identity - #define PAYLOAD_TYPE_GRP_TXT 0x05 // an (unverified) group text message (prefixed with channel hash, MAC) (enc data: timestamp, "name: msg") - #define PAYLOAD_TYPE_GRP_DATA 0x06 // an (unverified) group datagram (prefixed with channel hash, MAC) (enc data: timestamp, blob) - #define PAYLOAD_TYPE_ANON_REQ 0x07 // generic request (prefixed with dest_hash, ephemeral pub_key, MAC) (enc data: ...) + + + #define PAYLOAD_TYPE_REQ 0x00 // request (prefixed with dest/src hashes, MAC) (enc data: timestamp, blob) + #define PAYLOAD_TYPE_RESPONSE 0x01 // response to REQ or ANON_REQ (prefixed with dest/src hashes, MAC) (enc data: timestamp, blob) + #define PAYLOAD_TYPE_TXT_MSG 0x02 // a plain text message (prefixed with dest/src hashes, MAC) (enc data: timestamp, text) + #define PAYLOAD_TYPE_ACK 0x03 // a simple ack #define PAYLOAD_TYPE_ADVERT 0x04 // a node advertising its Identity + #define PAYLOAD_TYPE_GRP_TXT 0x05 // an (unverified) group text message (prefixed with channel hash, MAC) (enc data: timestamp, "name: msg") + #define PAYLOAD_TYPE_GRP_DATA 0x06 // an (unverified) group datagram (prefixed with channel hash, MAC) (enc data: timestamp, blob) + #define PAYLOAD_TYPE_ANON_REQ 0x07 // generic request (prefixed with dest_hash, ephemeral pub_key, MAC) (enc data: ...) #define PAYLOAD_TYPE_PATH 0x08 // returned path (prefixed with dest/src hashes, MAC) (enc data: path, extra) [Source](https://discord.com/channels/1343693475589263471/1343693475589263474/1350611321040932966) @@ -370,14 +362,30 @@ https://github.com/meshcore-dev/MeshCore/blob/main/src/Packet.h#L19 ### 5.1. Q: What are BW, SF, and CR? -**A:** +**A:** **BW is bandwidth** - width of frequency spectrum that is used for transmission **SF is spreading factor** - how much should the communication spread in time -**CR is coding rate** - https://www.thethingsnetwork.org/docs/lorawan/fec-and-code-rate/ -Making the bandwidth 2x wider (from BW125 to BW250) allows you to send 2x more bytes in the same time. Making the spreading factor 1 step lower (from SF10 to SF9) allows you to send 2x more bytes in the same time. +**CR is coding rate** - from: https://www.thethingsnetwork.org/docs/lorawan/fec-and-code-rate/ + +TL;DR: default CR to 5 for good stable links. If it is not a solid link and is intermittent, change to CR to 7 or 8. + +Forward Error Correction is a process of adding redundant bits to the data to be transmitted. During the transmission, data may get corrupted by interference (changes from 0 to 1 / 1 to 0). These error correction bits are used at the receivers for restoring corrupted bits. + +The Code Rate of a forward error correction expresses the proportion of bits in a data stream that actually carry useful information. + +There are 4 code rates used in LoRaWAN: + +4/5 +4/6 +5/7 +4/8 + +For example, if the code rate is 5/7, for every 5 bits of useful information, the coder generates a total of 7 bits of data, of which 2 bits are redundant. + +Making the bandwidth 2x wider (from BW125 to BW250) allows you to send 2x more bytes in the same time. Making the spreading factor 1 step lower (from SF10 to SF9) allows you to send 2x more bytes in the same time. Lowering the spreading factor makes it more difficult for the gateway to receive a transmission, as it will be more sensitive to noise. You could compare this to two people taking in a noisy place (a bar for example). If you’re far from each other, you have to talk slow (SF10), but if you’re close, you can talk faster (SF7) @@ -385,14 +393,14 @@ So, it's balancing act between speed of the transmission and resistance to noise things network is mainly focused on LoRaWAN, but the LoRa low-level stuff still checks out for any LoRa project ### 5.2. Q: Do MeshCore clients repeat? -**A:** No, MeshCore clients do not repeat. This is the core of MeshCore's messaging-first design. This is to avoid devices flooding the air ware and create endless collisions, so messages sent aren't received. -In MeshCore, only repeaters and room server with `set repeat on` repeat. +**A:** No, MeshCore clients do not repeat. This is the core of MeshCore's messaging-first design. This is to avoid devices flooding the air ware and create endless collisions, so messages sent aren't received. +In MeshCore, only repeaters and room server with `set repeat on` repeat. ### 5.3. Q: What happens when a node learns a route via a mobile repeater, and that repeater is gone? **A:** If you used to reach a node through a repeater and the repeater is no longer reachable, the client will send the message using the existing (but now broken) known path, the message will fail after 3 retries, and the app will reset the path and send the message as flood on the last retry by default. This can be turned off in settings. If the destination is reachable directly or through another repeater, the new path will be used going forward. Or you can set the path manually if you know a specific repeater to use to reach that destination. -In the case if users are moving around frequently, and the paths are breaking, they just see the phone client retries and revert to flood to attempt to re-establish a path. +In the case if users are moving around frequently, and the paths are breaking, they just see the phone client retries and revert to flood to attempt to re-establish a path. ### 5.4. Q: How does a node discovery a path to its destination and then use it to send messages in the future, instead of flooding every message it sends like Meshtastic? @@ -411,14 +419,14 @@ Routes are stored in sender's contact list. When you send a message the first t **A:** The smartphone app key is in hex: ` 8b3387e9c5cdea6ac9e5edbaa115cd72` -T-Deck uses the same key but in base64 +T-Deck uses the same key but in base64 `izOH6cXN6mrJ5e26oRXNcg==` The third character is the capital letter 'O', not zero `0` [Source](https://discord.com/channels/826570251612323860/1330643963501351004/1354194409213792388) ### 5.7. Q: Is MeshCore open source? -**A:** Most of the firmware is freely available. Everything is open source except the T-Deck firmware and Liam's native mobile apps. -- Firmware repo: https://github.com/meshcore-dev/MeshCore +**A:** Most of the firmware is freely available. Everything is open source except the T-Deck firmware and Liam's native mobile apps. +- Firmware repo: https://github.com/meshcore-dev/MeshCore ### 5.8. Q: How can I support MeshCore? **A:** Provide your honest feedback on GitHub and on [MeshCore Discord server](https://discord.gg/BMwCtwHj5V). Spread the word of MeshCore to your friends and communities; help them get started with MeshCore. Support Scott's MeshCore development at . @@ -428,7 +436,7 @@ Support Liam Cottle's smartphone client development by unlocking the server admi Support Rastislav Vysoky (recrof)'s flasher web site and the map web site development through [PayPal](https://www.paypal.com/donate/?business=DREHF5HM265ES&no_recurring=0&item_name=If+you+enjoy+my+work%2C+you+can+support+me+here%3A¤cy_code=EUR) or [Revolut](https://revolut.me/recrof) ### 5.9. Q: How do I build MeshCore firmware from source? -**A:** See instructions here: +**A:** See instructions here: https://discord.com/channels/826570251612323860/1330643963501351004/1341826372120608769 Build instructions for MeshCore: @@ -448,7 +456,7 @@ Then it should be the same for all platforms: python3 -m venv meshcore cd meshcore && source bin/activate pip install -U platformio -git clone https://github.com/ripplebiz/MeshCore.git +git clone https://github.com/ripplebiz/MeshCore.git cd MeshCore ``` open platformio.ini and in `[arduino_base]` edit the `LORA_FREQ=867.5` @@ -458,8 +466,8 @@ pio run -e RAK_4631_Repeater ``` then you'll find `firmware.zip` in `.pio/build/RAK_4631_Repeater` -Andy also has a video on how to build using VS Code: -*How to build and flash Meshcore repeater firmware | Heltec V3* +Andy also has a video on how to build using VS Code: +*How to build and flash Meshcore repeater firmware | Heltec V3* *(Link referenced in the Discord post)* ### 5.10. Q: Are there other MeshCore related open source projects? @@ -476,13 +484,13 @@ Meshcore would not be best suited to ATAK because MeshCore: clients do not repeat and therefore you would need a network of repeaters in place will not have a stable path where all clients are constantly moving between repeaters -MeshCore clients would need to reset path constantly and flood traffic across the network which could lead to lots of collisions with something as chatty as ATAK. +MeshCore clients would need to reset path constantly and flood traffic across the network which could lead to lots of collisions with something as chatty as ATAK. This could change in the future if MeshCore develops a client firmware that repeats. [Source](https://discord.com/channels/826570251612323860/1330643963501351004/1354780032140054659) ### 5.12. Q: How do I add a node to the [MeshCore Map]([url](https://meshcore.co.uk/map.html)) -**A:** +**A:** To add a BLE Companion radio, connect to the BLE Companion radio from the MeshCore smartphone app. In the app, tap the `3 dot` menu icon at the top right corner, then tap `Internet Map`. Tap the `3 dot` menu icon again and choose `Add me to the Map` @@ -501,7 +509,7 @@ For ESP-based devices (e.g. Heltec V3) you need: - Download firmware file from flasher.meshcore.co.uk - Go to the web site on a browser, find the section that has the firmware up need - Click the Download button, right click on the file you need, for example, - - `Heltec_V3_companion_radio_ble-v1.7.1-165fb33.bin` + - `Heltec_V3_companion_radio_ble-v1.7.1-165fb33.bin` - Non-merged bin keeps the existing Bluetooth pairing database - `Heltec_v3_companion_radio_usb-v1.7.1-165fb33-merged.bin` - Merged bin overwrites everything including the bootloader, existing Bluetooth pairing database, but keeps configurations. @@ -520,7 +528,7 @@ For ESP-based devices (e.g. Heltec V3) you need: - `esptool.py -p /dev/ttyUSB0 --chip esp32-s3 write_flash 0x10000 .bin` - For merged bin: - `esptool.py -p /dev/ttyUSB0 --chip esp32-s3 write_flash 0x00000 .bin` - + **Instructions for nRF devices:** @@ -541,24 +549,25 @@ For nRF devices (e.g. RAK, Heltec T114) you need the following: - `pip install adafruit-nrfutil --break-system-packages` - Use this command to flash the nRF device: - `adafruit-nrfutil --verbose dfu serial --package RAK_4631_companion_radio_usb-v1.7.1-165fb33.zip -p /dev/ttyACM0 -b 115200 --singlebank --touch 1200` - - + + To manage a repeater or room server connected to a Pi over USB serial using shell commands, you need to install `picocom`. To install `picocom`, run the following command: - `sudo apt install picocom` To start managing your USB serial-connected device using picocom, use the following command: - `picocom -b 115200 /dev/ttyUSB0 --imap lfcrlf` -From here, reference repeater and room server command line commands on MeshCore github wiki here: +From here, reference repeater and room server command line commands on MeshCore github wiki here: - https://github.com/meshcore-dev/MeshCore/wiki/Repeater-&-Room-Server-CLI-Reference - + ### 5.14. Q: Are there are projects built around MeshCore? **A:** Yes. See the following: #### 5.14.1. meshcoremqtt -A Python script to send meshore debug and packet capture data to MQTT for analysis +A Python script to send meshcore debug and packet capture data to MQTT for analysis. Cisien's version is a fork of Andrew-a-g's and is being used to to collect data for https://map.w0z.is/messages and https://analyzer.letsme.sh/ +https://github.com/Cisien/meshcoretomqtt https://github.com/Andrew-a-g/meshcoretomqtt #### 5.14.2. MeshCore for Home Assistant @@ -569,7 +578,7 @@ https://github.com/awolden/meshcore-ha Bindings to access your MeshCore companion radio nodes in python. https://github.com/fdlamotte/meshcore_py -#### 5.14.4. meshcore-cli +#### 5.14.4. meshcore-cli CLI interface to MeshCore companion radio over BLE, TCP, or serial. Uses Python MeshCore above. https://github.com/fdlamotte/meshcore-cli @@ -577,15 +586,19 @@ CLI interface to MeshCore companion radio over BLE, TCP, or serial. Uses Python A JavaScript library for interacting with a MeshCore device running the companion radio firmware https://github.com/liamcottle/meshcore.js +#### 5.14.6. pyMC_core +pyMC_Core is a Python port of MeshCore, designed for Raspberry Pi and similar hardware, it talks to LoRa modules over SPI. +https://github.com/rightup/pyMC_core + --- ## 6. Troubleshooting ### 6.1. Q: My client says another client or a repeater or a room server was last seen many, many days ago. ### 6.2. Q: A repeater or a client or a room server I expect to see on my discover list (on T-Deck) or contact list (on a smart device client) are not listed. -**A:** -- If your client is a T-Deck, it may not have its time set (no GPS installed, no GPS lock, or wrong GPS baud rate). -- If you are using the Android or iOS client, the other client, repeater, or room server may have the wrong time. +**A:** +- If your client is a T-Deck, it may not have its time set (no GPS installed, no GPS lock, or wrong GPS baud rate). +- If you are using the Android or iOS client, the other client, repeater, or room server may have the wrong time. You can get the epoch time on and use it to set your T-Deck clock. For a repeater and room server, the admin can use a T-Deck to remotely set their clock (clock sync), or use the `time` command in the USB serial console with the server device connected. @@ -606,23 +619,23 @@ You can get the epoch time on and use it to se ### 6.7. Q: My RAK/T1000-E/xiao_nRF52 device seems to be corrupted, how do I wipe it clean to start fresh? -**A:** +**A:** 1. Connect USB-C cable to your device, per your device's instruction, get it to flash mode: - For RAK, click the reset button **TWICE** - For T1000-e, quickly disconnect and reconnect the magnetic side of the cable from the device **TWICE** - For Heltec T114, click the reset button **TWICE** (the bottom button) - For Xiao nRF52, click the reset button once. If that doesn't work, quickly double click the reset button twice. If that doesn't work, disconnection the board from your PC and reconnect again ([seeed studio wiki](https://wiki.seeedstudio.com/XIAO_BLE/#access-the-swd-pins-for-debugging-and-reflashing-bootloader)) 5. A new folder will appear on your computer's desktop -6. Download the `flash_erase*.uf2` file for your device on flasher.meshcore.co.uk +6. Download the `flash_erase*.uf2` file for your device on flasher.meshcore.co.uk - RAK WisBlock and Heltec T114: `Flash_erase-nRF32_softdevice_v6.uf2` - Seeed Studio Xiao nRF52 WIO: `Flash_erase-nRF52_softdevice_v7.uf2` 8. drag and drop the uf2 file for your device to the root of the new folder 9. Wait for the copy to complete. You might get an error dialog, you can ignore it -10. Go to https://flasher.meshcore.co.uk/, click `Console` and select the serial port for your connected device +10. Go to https://flasher.meshcore.co.uk/, click `Console` and select the serial port for your connected device 11. In the console, press enter. Your flash should now be erased 12. You may now flash the latest MeshCore firmware onto your device -Separately, starting in firmware version 1.7.0, there is a CLI Rescue mode. If your device has a user button (e.g. some RAK, T114), you can activate the rescue mode by hold down the user button of the device within 8 seconds of boot. Then you can use the 'Console' on flasher.meshcore.co.uk +Separately, starting in firmware version 1.7.0, there is a CLI Rescue mode. If your device has a user button (e.g. some RAK, T114), you can activate the rescue mode by hold down the user button of the device within 8 seconds of boot. Then you can use the 'Console' on flasher.meshcore.co.uk ### 6.8. Q: WebFlasher fails on Linux with failed to open @@ -645,12 +658,12 @@ Allow the browser user on it: 4. Go to the Command Line tab, type `start ota` and hit enter. 5. you should see `OK` to confirm the repeater device is now in OTA mode 6. Run the DFU app,tab `Settings` on the top right corner -7. Enable `Packets receipt notifications`, and change `Number of Packets` to 10 for RAK, 8 for T114. 8 also works for RAK. +7. Enable `Packets receipt notifications`, and change `Number of Packets` to 10 for RAK, 8 for T114. 8 also works for RAK. 9. Select the firmware zip file you downloaded 10. Select the device you want to update. If the device you want to update is not on the list, try enabling`OTA` on the device again 11. If the device is not found, enable `Force Scanning` in the DFU app 12. Tab the `Upload` to begin OTA update -13. If it fails, try turning off and on Bluetooth on your phone. If that doesn't work, try rebooting your phone. +13. If it fails, try turning off and on Bluetooth on your phone. If that doesn't work, try rebooting your phone. 14. Wait for the update to complete. It can take a few minutes. @@ -662,13 +675,13 @@ Allow the browser user on it: 4. Go to the Command Line tab, type `start ota` and hit enter. 5. you should see `OK` to confirm the repeater device is now in OTA mode 6. The command `start ota` on an ESP32-based device starts a wifi hotspot named `MeshCore OTA` -7. From your phone or computer connect to the 'MeshCore OTA' hotspot +7. From your phone or computer connect to the 'MeshCore OTA' hotspot 8. From a browser, go to http://192.168.4.1/update and upload the non-merged bin from the flasher ### 7.3. Q: Is there a way to lower the chance of a failed OTA device firmware update (DFU)? -**A:** Yes, developer `che aporeps` has an enhanced OTA DFU bootloader for nRF52 based devices. With this bootloader, if it detects that the application firmware is invalid, it falls back to OTA DFU mode so you can attempt to flash again to recover. This bootloader has other changes to make the OTA DFU process more fault tolerant. +**A:** Yes, developer `che aporeps` has an enhanced OTA DFU bootloader for nRF52 based devices. With this bootloader, if it detects that the application firmware is invalid, it falls back to OTA DFU mode so you can attempt to flash again to recover. This bootloader has other changes to make the OTA DFU process more fault tolerant. Refer to https://github.com/oltaco/Adafruit_nRF52_Bootloader_OTAFIX for the latest information. @@ -680,7 +693,7 @@ Currently, the following boards are supported: ### 7.4. Q: are the MeshCore logo and font available? -**A:** Yes, it is on the MeshCore github repo here: +**A:** Yes, it is on the MeshCore github repo here: https://github.com/meshcore-dev/MeshCore/tree/main/logo ### 7.5. Q: What is the format of a contact or channel QR code? @@ -699,7 +712,7 @@ where `&type` is: `sensor = 4` ### 7.6. Q: How do I connect to the companion via WIFI, e.g. using a heltec v3? - **A:** + **A:** WiFi firmware requires you to compile it yourself, as you need to set the wifi ssid and password. Edit WIFI_SSID and WIFI_PWD in `./variants/heltec_v3/platformio.ini` and then flash it to your device. diff --git a/docs/payloads.md b/docs/payloads.md index 5a41e69ce..f86a70bc4 100644 --- a/docs/payloads.md +++ b/docs/payloads.md @@ -218,4 +218,4 @@ The plaintext contained in the ciphertext matches the format described in [plain # Custom packet -Custom packets have no defined format. \ No newline at end of file +Custom packets have no defined format. diff --git a/examples/simple_room_server/MyMesh.cpp b/examples/simple_room_server/MyMesh.cpp index de06b4c67..91b6fd740 100644 --- a/examples/simple_room_server/MyMesh.cpp +++ b/examples/simple_room_server/MyMesh.cpp @@ -809,7 +809,7 @@ void MyMesh::loop() { if (c->extra.room.pending_ack && millisHasNowPassed(c->extra.room.ack_timeout)) { c->extra.room.push_failures++; c->extra.room.pending_ack = 0; // reset (TODO: keep prev expected_ack's in a list, incase they arrive LATER, after we retry) - MESH_DEBUG_PRINTLN("pending ACK timed out: push_failures: %d", (uint32_t)c->push_failures); + MESH_DEBUG_PRINTLN("pending ACK timed out: push_failures: %d", (uint32_t)c->extra.room.push_failures); } } // check next Round-Robin client, and sync next new post diff --git a/variants/arduino_nesso_n1/ArduinoNessoN1Board.cpp b/variants/arduino_nesso_n1/ArduinoNessoN1Board.cpp new file mode 100644 index 000000000..777befb32 --- /dev/null +++ b/variants/arduino_nesso_n1/ArduinoNessoN1Board.cpp @@ -0,0 +1,51 @@ +#include "ArduinoNessoN1Board.h" +#include + +void ArduinoNessoN1Board::begin() { + ESP32Board::begin(); + +#ifdef MESH_DEBUG + // delay for 2s after boot to ensure early output below makes it to the serial logger + delay(2000); +#endif + +#ifdef P_LORA_TX_LED + MESH_DEBUG_PRINTLN("ArduinoNessoN1.begin(): setup TX LED mode"); + pinMode(P_LORA_TX_LED, OUTPUT); + digitalWrite(P_LORA_TX_LED, HIGH); +#endif + + battery.begin(); + battery.enableCharge(); + + MESH_DEBUG_PRINTLN("ArduinoNessoN1.begin(): set Nesso N1 pin modes and default states..."); + pinMode(LORA_ENABLE, OUTPUT); // RESET + pinMode(LORA_ANTENNA_SWITCH, OUTPUT); // ANTENNA_SWITCH + pinMode(LORA_LNA_ENABLE, OUTPUT); // LNA_ENABLE + pinMode(LCD_BACKLIGHT, OUTPUT); + pinMode(BEEP_PIN, OUTPUT); + + // Toggle LoRa reset via expander + MESH_DEBUG_PRINTLN("ArduinoNessoN1.begin(): Enable LoRa..."); + digitalWrite(LORA_ENABLE, LOW); + delay(10); + digitalWrite(LORA_ENABLE, HIGH); + + // Configure antenna switch and LNA + digitalWrite(LORA_ANTENNA_SWITCH, HIGH); // enable antenna switch + digitalWrite(LORA_LNA_ENABLE, HIGH); // enable LNA + + // Configure initial state of further devices on expander + MESH_DEBUG_PRINTLN("ArduinoNessoN1.begin(): Set LCD_BACKLIGHT and BEEP_PIN to low initial state..."); + digitalWrite(LCD_BACKLIGHT, LOW); + digitalWrite(BEEP_PIN, LOW); + + // Toggle LCD backlight to show the device has powered on until we get the screen working + MESH_DEBUG_PRINTLN("ArduinoNessoN1.begin(): Now high..."); + digitalWrite(LCD_BACKLIGHT, HIGH); + digitalWrite(BEEP_PIN, HIGH); + delay(2000); + digitalWrite(LCD_BACKLIGHT, LOW); + digitalWrite(BEEP_PIN, LOW); + MESH_DEBUG_PRINTLN("ArduinoNessoN1.begin(): Now low..."); +} \ No newline at end of file diff --git a/variants/arduino_nesso_n1/ArduinoNessoN1Board.h b/variants/arduino_nesso_n1/ArduinoNessoN1Board.h new file mode 100644 index 000000000..67fdce08f --- /dev/null +++ b/variants/arduino_nesso_n1/ArduinoNessoN1Board.h @@ -0,0 +1,50 @@ +#pragma once + +#include +#include +#include +#include "pins_arduino.h" + +#define P_LORA_TX_LED LED_BUILTIN // defined in pins_arduino.h / expander.cpp through pin handling functions specific to the IO expander +// #define PIN_TFT_RST LCD_RESET +// #define PIN_TFT_LEDA_CTL LCD_BACKLIGHT + +class ArduinoNessoN1Board : public ESP32Board { +private: + NessoBattery battery; + +public: + void begin(); // Defined in ArduinoNessoN1Board.cpp + +#ifdef P_LORA_TX_LED + void onBeforeTransmit() override { + MESH_DEBUG_PRINTLN("onBeforeTransmit: LOW LED for On"); + digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED on + } + void onAfterTransmit() override { + MESH_DEBUG_PRINTLN("onBeforeTransmit: HIGH LED for Off"); + digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED off + } +#endif + + const char* getManufacturerName() const override { + return "Arduino Nesso N1"; + } + + uint16_t getBattMilliVolts() override { +#ifdef MESH_DEBUG + MESH_DEBUG_PRINTLN("getBattMilliVolts(): isCharging(): %u", battery.isCharging()); + MESH_DEBUG_PRINTLN("getBattMilliVolts(): Current charge level %u %%", battery.getChargeLevel()); + MESH_DEBUG_PRINTLN("getBattMilliVolts(): Current voltage %f V", battery.getVoltage()); + MESH_DEBUG_PRINTLN("getBattMilliVolts(): Current voltage %u mV", battery.getMilliVoltage()); +#endif + return battery.getMilliVoltage(); + } + + void reboot() override { + MESH_DEBUG_PRINTLN("ArduinoNessoN1.reboot(): noop() instead"); + // esp_restart(); + } +}; + + diff --git a/variants/arduino_nesso_n1/expander.cpp b/variants/arduino_nesso_n1/expander.cpp new file mode 100644 index 000000000..0e281e759 --- /dev/null +++ b/variants/arduino_nesso_n1/expander.cpp @@ -0,0 +1,233 @@ +#pragma once +// Based off here https://github.com/espressif/arduino-esp32/blob/d1eb62d7c6dda16c254c374504aa93188d7c386b/variants/arduino_nesso_n1/expander.cpp +// Should be OK based on this? https://opensource.stackexchange.com/a/6406 + +#include "pins_arduino.h" +#include +#include + +static bool wireInitialized = true; // initialised in ESP32Board.begin() ; ToDo: Remove all these conditions in future +static bool expanderInitialized = false; + +// From https://www.diodes.com/datasheet/download/PI4IOE5V6408.pdf +static void writeRegister(uint8_t address, uint8_t reg, uint8_t value) { + Wire.beginTransmission(address); + Wire.write(reg); + Wire.write(value); + Wire.endTransmission(); +} + +static uint8_t readRegister(uint8_t address, uint8_t reg) { + Wire.beginTransmission(address); + Wire.write(reg); + Wire.endTransmission(false); + Wire.requestFrom(address, 1); + return Wire.read(); +} + +static void writeBitRegister(uint8_t address, uint8_t reg, uint8_t bit, uint8_t value) { + MESH_DEBUG_PRINTLN("ExpanderPin writeBitRegister(address=%u, reg=%u, bit=%u, value=%u)", address, reg, bit, value); + uint8_t val = readRegister(address, reg); + if (value) { + writeRegister(address, reg, val | (1 << bit)); + } else { + writeRegister(address, reg, val & ~(1 << bit)); + } +} + +static bool readBitRegister(uint8_t address, uint8_t reg, uint8_t bit) { + MESH_DEBUG_PRINTLN("ExpanderPin readBitRegister(address=%u, reg=%u, bit=%u)", address, reg, bit); + uint8_t val = readRegister(address, reg); + return ((val & (1 << bit)) > 0); +} + +void pinMode(ExpanderPin pin, uint8_t mode) { + if (!wireInitialized) { + Wire.begin(SDA, SCL); + wireInitialized = true; + // reset all registers to default state + } + if (!expanderInitialized) { + writeRegister(pin.address, 0x1, 0x1); + // set all pins as high as default state + writeRegister(pin.address, 0x9, 0xFF); + // interrupt mask to all pins + writeRegister(pin.address, 0x11, 0xFF); + // all input + writeRegister(pin.address, 0x3, 0); + expanderInitialized = true; + } + MESH_DEBUG_PRINTLN("ExpanderPin pinMode(pin=%u, mode=%u)", pin.pin, mode); + writeBitRegister(pin.address, 0x3, pin.pin, mode == OUTPUT); + if (mode == OUTPUT) { + // remove high impedance + writeBitRegister(pin.address, 0x7, pin.pin, false); + } else if (mode == INPUT_PULLUP) { + // set pull-up resistor + writeBitRegister(pin.address, 0xB, pin.pin, true); + writeBitRegister(pin.address, 0xD, pin.pin, true); + } else if (mode == INPUT_PULLDOWN) { + // disable pull-up resistor + writeBitRegister(pin.address, 0xB, pin.pin, true); + writeBitRegister(pin.address, 0xD, pin.pin, false); + } else if (mode == INPUT) { + // disable pull selector resistor + writeBitRegister(pin.address, 0xB, pin.pin, false); + } +} + +void digitalWrite(ExpanderPin pin, uint8_t val) { + if (!wireInitialized) { + Wire.begin(SDA, SCL); + wireInitialized = true; + } + MESH_DEBUG_PRINTLN("ExpanderPin digitalWrite(%u)", pin.pin); + writeBitRegister(pin.address, 0x5, pin.pin, val == HIGH); +} + +int digitalRead(ExpanderPin pin) { + if (!wireInitialized) { + Wire.begin(SDA, SCL); + wireInitialized = true; + } + MESH_DEBUG_PRINTLN("ExpanderPin digitalRead(%u)", pin.pin); + return readBitRegister(pin.address, 0xF, pin.pin); +} + +void NessoBattery::begin() { + // AW32001E - address 0x49 + // Spec: https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/products/core/LLM630%20Computer%20Kit/AW32001E.pdf + if (!wireInitialized) { + Wire.begin(SDA, SCL); + wireInitialized = true; + } + + uint8_t val = 0; + val = readRegister(AW32001_I2C_CHIP_ADDR, AW32001_REG_CHIP_ID); + // coarsely check if chip is actually the right chip + auto res = (val == AW32001_I2C_CHIP_ADDR); + if (res) { + val = readRegister(AW32001_I2C_CHIP_ADDR, AW32001_REG_CHR_TMR); +#ifdef MESH_DEBUG + // Debug output the WatchDog Timer (wdt) state + MESH_DEBUG_PRINTLN("NessoBattery.begin(): CHR_TMR full register; bits 5,6 are for WDT = %#02x", val); +#endif + // disable WatchDog Timer (wdt) + // take existing register value AND with 00011111 + val = val & 0x1f; + writeRegister(AW32001_I2C_CHIP_ADDR, AW32001_REG_CHR_TMR, val); + } +#ifdef MESH_DEBUG + else { + MESH_DEBUG_PRINTLN("NessoBattery.begin(): Register of chip ADDR = %u != I2C of chip %u", AW32001_REG_CHIP_ID, AW32001_I2C_CHIP_ADDR); + } +#endif + + // store if chip is initiated by whether it passed above checks and had watchdog disabled + _power_mgmt_init = res; +} + +void NessoBattery::enableCharge() { + // AW32001E - address 0x49 + // set CEB (charge enable) bit (3) low (0) in AW32001_REG_PWR_CFG (0x01) + MESH_DEBUG_PRINTLN("NessoBattery::enableCharge()"); + + if (_power_mgmt_init) { + MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): _power_mgmt_init = true"); + if (!wireInitialized) { + Wire.begin(SDA, SCL); + wireInitialized = true; + } + + bool charge_enable_bit = readBitRegister(AW32001_I2C_CHIP_ADDR, AW32001_REG_PWR_CFG, 3); + MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): Current charge setting (low is on): %u", charge_enable_bit); + MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): isCharging(): %u", NessoBattery::isCharging()); + MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): Current charge level %u %%", NessoBattery::getChargeLevel()); + MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): Current voltage %f V", NessoBattery::getVoltage()); + MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): Current voltage %u mV", NessoBattery::getMilliVoltage()); + + writeBitRegister(AW32001_I2C_CHIP_ADDR, AW32001_REG_PWR_CFG, 3, false); + } +#ifdef MESH_DEBUG + else { + MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): _power_mgmt_init is false, won't enable charge"); + } +#endif +} + +NessoBattery::ChargeStatus NessoBattery::getChargeStatus(void) { + uint8_t reg_value = 0; + if (_power_mgmt_init) + { + reg_value = readRegister(AW32001_I2C_CHIP_ADDR, AW32001_REG_SYS_STA); + // Extract bits 4 and 3 for charge status + reg_value = (reg_value >> 3) & 0b00000011; // Get bits 4 and 3 + MESH_DEBUG_PRINTLN("NessoBattery::getChargeStatus(): bits 4 and 3 from register %#02x = %u", AW32001_REG_SYS_STA, reg_value); + switch (reg_value) + { + case 0b00: return CS_NOT_CHARGING; // Not charging + case 0b01: return CS_PRE_CHARGE; // Pre-charge + case 0b10: return CS_CHARGE; // Charging + case 0b11: return CS_CHARGE_DONE; // Charge done + default: return CS_UNKNOWN; // Unknown state + } + } + MESH_DEBUG_PRINTLN("NessoBattery::getChargeStatus(): failed, probably chip wasn't init"); + return CS_UNKNOWN; // Return unknown if read failed +} + +bool NessoBattery::isCharging(void) +{ + ChargeStatus status = getChargeStatus(); + MESH_DEBUG_PRINTLN("NessoBattery::isCharging(): ChargeStatus = %u; is? false0/true1 = %u", status, (status == CS_PRE_CHARGE || status == CS_CHARGE)); + return (status == CS_PRE_CHARGE || status == CS_CHARGE); +} + +float NessoBattery::getVoltage() { + // BQ27220 - address 0x55 + if (!wireInitialized) { + Wire.begin(SDA, SCL); + wireInitialized = true; + } + MESH_DEBUG_PRINTLN("NessoBattery::getVoltage()"); + uint16_t voltage = (readRegister(0x55, 0x9) << 8) | readRegister(0x55, 0x8); + MESH_DEBUG_PRINTLN("NessoBattery::getVoltage(): %f", voltage / 1000.0f); + return (float)voltage / 1000.0f; +} + +uint16_t NessoBattery::getMilliVoltage() { + // BQ27220 - address 0x55 + if (!wireInitialized) { + Wire.begin(SDA, SCL); + wireInitialized = true; + } + MESH_DEBUG_PRINTLN("NessoBattery::getMilliVoltage()"); + uint16_t voltage = (readRegister(0x55, 0x9) << 8) | readRegister(0x55, 0x8); + MESH_DEBUG_PRINTLN("NessoBattery::getMilliVoltage(): %u", voltage); + return voltage; +} + +uint16_t NessoBattery::getChargeLevel() { + // BQ27220 - address 0x55 + if (!wireInitialized) { + Wire.begin(SDA, SCL); + wireInitialized = true; + } + MESH_DEBUG_PRINTLN("NessoBattery::getChargeLevel()"); + uint16_t current_capacity = readRegister(0x55, 0x11) << 8 | readRegister(0x55, 0x10); + uint16_t total_capacity = readRegister(0x55, 0x13) << 8 | readRegister(0x55, 0x12); + MESH_DEBUG_PRINTLN("NessoBattery::getChargeLevel(): curr = %u / total = %u; pct = %u %%", current_capacity, total_capacity, ((current_capacity * 100) / total_capacity)); + return (current_capacity * 100) / total_capacity; +} + +ExpanderPin LORA_LNA_ENABLE(5); +ExpanderPin LORA_ANTENNA_SWITCH(6); +ExpanderPin LORA_ENABLE(7); +ExpanderPin KEY1(0); +ExpanderPin KEY2(1); +ExpanderPin POWEROFF((1 << 8) | 0); +ExpanderPin LCD_RESET((1 << 8) | 1); +ExpanderPin GROVE_POWER_EN((1 << 8) | 2); +ExpanderPin VIN_DETECT((1 << 8) | 5); +ExpanderPin LCD_BACKLIGHT((1 << 8) | 6); +ExpanderPin LED_BUILTIN((1 << 8) | 7); \ No newline at end of file diff --git a/variants/arduino_nesso_n1/pins_arduino.h b/variants/arduino_nesso_n1/pins_arduino.h new file mode 100644 index 000000000..1f3a675f9 --- /dev/null +++ b/variants/arduino_nesso_n1/pins_arduino.h @@ -0,0 +1,106 @@ +// from https://github.com/espressif/arduino-esp32/pull/11985/files +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include +#include "soc/soc_caps.h" + +#define USB_VID 0x303A +#define USB_PID 0x1001 +#define USB_MANUFACTURER "Arduino" +#define USB_PRODUCT "Nesso N1" +#define USB_SERIAL "" + +static const uint8_t TX = -1; +static const uint8_t RX = -1; + +static const uint8_t SDA = 10; +static const uint8_t SCL = 8; + +static const uint8_t MOSI = 21; +static const uint8_t MISO = 22; +static const uint8_t SCK = 20; +static const uint8_t SS = 23; + +static const uint8_t D1 = 7; +static const uint8_t D2 = 2; +static const uint8_t D3 = 6; + +static const uint8_t IR_TX_PIN = 9; +static const uint8_t BEEP_PIN = 11; + +static const uint8_t GROVE_IO_0 = 5; +static const uint8_t GROVE_IO_1 = 4; + +static const uint8_t LORA_IRQ = 15; +static const uint8_t LORA_CS = 23; +static const uint8_t LORA_BUSY = 19; + +static const uint8_t SYS_IRQ = 3; + +static const uint8_t LCD_CS = 17; +static const uint8_t LCD_RS = 16; + + +// AW32001 registers +static const uint8_t AW32001_REG_PWR_CFG = 0x01; // Power Configuration +static const uint8_t AW32001_REG_CHR_CUR = 0x02; // Charging current +static const uint8_t AW32001_REG_CHR_VOL = 0x04; // Charge voltage +static const uint8_t AW32001_REG_CHR_TMR = 0x05; // Charge timer +static const uint8_t AW32001_REG_SYS_STA = 0x08; // System status +static const uint8_t AW32001_REG_CHIP_ID = 0x0A; // ChipID + +static const uint8_t AW32001_I2C_CHIP_ADDR = 0x49; // ChipID + + + +#if !defined(MAIN_ESP32_HAL_GPIO_H_) && defined(__cplusplus) +/* address: 0x43/0x44 */ +class ExpanderPin { +public: + ExpanderPin(uint16_t _pin) : pin(_pin & 0xFF), address(_pin & 0x100 ? 0x44 : 0x43){}; + uint8_t pin; + uint8_t address; +}; + +class NessoBattery { +private: + bool _power_mgmt_init = false; +public: + enum ChargeStatus + { + CS_UNKNOWN = -1, + CS_NOT_CHARGING = 0, + CS_PRE_CHARGE = 1, + CS_CHARGE = 2, + CS_CHARGE_DONE = 3 + }; + + NessoBattery(){}; + void begin(); // setup and check power management chip + void enableCharge(); // enable charging via power management chip + float getVoltage(); // get battery voltage in Volts + uint16_t getMilliVoltage(); // get battery voltage in millivolts + uint16_t getChargeLevel(); // get battery charge level in percents + ChargeStatus getChargeStatus(); + bool isCharging(); +}; + +extern ExpanderPin LORA_LNA_ENABLE; +extern ExpanderPin LORA_ANTENNA_SWITCH; +extern ExpanderPin LORA_ENABLE; +extern ExpanderPin POWEROFF; +extern ExpanderPin GROVE_POWER_EN; +extern ExpanderPin VIN_DETECT; +extern ExpanderPin LCD_RESET; +extern ExpanderPin LCD_BACKLIGHT; +extern ExpanderPin LED_BUILTIN; +extern ExpanderPin KEY1; +extern ExpanderPin KEY2; + +void pinMode(ExpanderPin pin, uint8_t mode); +void digitalWrite(ExpanderPin pin, uint8_t val); +int digitalRead(ExpanderPin pin); +#endif + +#endif /* Pins_Arduino_h */ \ No newline at end of file diff --git a/variants/arduino_nesso_n1/platformio.ini b/variants/arduino_nesso_n1/platformio.ini new file mode 100644 index 000000000..16bbec3da --- /dev/null +++ b/variants/arduino_nesso_n1/platformio.ini @@ -0,0 +1,89 @@ +[Arduino_Nesso_N1] +extends = esp32c6_base +board = esp32-c6-devkitm-1 +board_build.partitions = min_spiffs.csv ; get around 4mb flash limit +build_flags = + ${esp32c6_base.build_flags} + -I variants/arduino_nesso_n1 + -D MESH_DEBUG=1 + -D ARDUINO=1 + -D ARDUINO_USB_CDC_ON_BOOT=1 + -D ARDUINO_USB_MODE=1 + ; -D P_LORA_TX_LED= ; Defined in ArduinoNessoN1Board.h + -D P_LORA_SCLK=20 + -D P_LORA_MISO=22 + -D P_LORA_MOSI=21 + -D P_LORA_NSS=23 ; aka LORA_CS on the Nesso N1 schematic + -D P_LORA_DIO_1=15 ; aka LORA_IRQ on the Nesso N1 schematic + -D P_LORA_BUSY=19 + ; -D P_LORA_RESET=-1 ; Enabled in ArduinoNessoN1Board.cpp instead + -D PIN_BOARD_SDA=10 + -D PIN_BOARD_SCL=8 + ; -D SX126X_RXEN=23 ; ToDo: not sure + ; -D SX126X_DIO2_AS_RF_SWITCH=true + ; -D SX126X_DIO3_TCXO_VOLTAGE=1.8 + -D SX126X_CURRENT_LIMIT=140 + -D SX126X_RX_BOOSTED_GAIN=1 + -D RADIO_CLASS=CustomSX1262 + -D WRAPPER_CLASS=CustomSX1262Wrapper + -D LORA_TX_POWER=22 + ; -D DISPLAY_CLASS=SCIndicatorDisplay ; ToDo: Figure out display later + ; -D DISPLAY_LINES=21 ; ToDo: Figure out display later + ; -D LINE_LENGTH=53 ; ToDo: Figure out display later + ; -D UI_ZOOM=3.5 ; ToDo: Figure out display later + ; -D UI_RECENT_LIST_SIZE=9 ; ToDo: Figure out UI later + ; -D UI_SENSORS_PAGE=1 ; ToDo: Figure out UI later + ; -D PIN_USER_BTN=38 ; ToDo: Figure out UI later + ; -D HAS_TOUCH ; ToDo: Figure out UI later + ; -D PIN_TFT_SCL=38 + ; -D PIN_TFT_SDA=48 + ; -D PIN_TFT_RST=-1 ; It is defined in ArduinoNessoN1Board.h instead, so that the Expander can be targeted + ; -D PIN_TFT_VDD_CTL=7 ; Seems to be right, but seems ST7789Display or ST7789LCDDisplay are too hard coded for other devices + ; -D PIN_TFT_LEDA_CTL=-1 ; It is defined in ArduinoNessoN1Board.h instead, so that the Expander can be targeted + ; -D PIN_TFT_LEDA_CTL_ACTIVE=HIGH ; Seems to be right, but seems ST7789Display or ST7789LCDDisplay are too hard coded for other devices + ; -D PIN_TFT_CS=17 ; Seems to be right, but seems ST7789Display or ST7789LCDDisplay are too hard coded for other devices + ; -D PIN_TFT_DC=?? ; ToDo: Unsure + ; -D ST7789 ; This is the display driver type (- 1.14" IPS LCD, ST7789P3 driver @ SPI communication, Resolution: 135 × 240 pixels, 262K colors (18-bit)), but seems ST7789Display or ST7789LCDDisplay are too hard coded for other devices + ; -D DISPLAY_CLASS=ST7789Display + -D DISABLE_WIFI_OTA=1 +build_src_filter = ${esp32c6_base.build_src_filter} + + + + + +<../variants/arduino_nesso_n1> + +[env:Arduino_Nesso_N1_repeater] +extends = Arduino_Nesso_N1 +build_src_filter = ${Arduino_Nesso_N1.build_src_filter} + +<../examples/simple_repeater/*.cpp> +build_flags = + ${Arduino_Nesso_N1.build_flags} + -D ADVERT_NAME='"Arduino Nesso N1 Repeater"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D MAX_NEIGHBOURS=50 +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 +lib_deps = + ${Arduino_Nesso_N1.lib_deps} +; ${esp32_ota.lib_deps} + +[env:Arduino_Nesso_N1_companion_radio_ble] +extends = Arduino_Nesso_N1 +build_flags = ${Arduino_Nesso_N1.build_flags} + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 + -D BLE_PIN_CODE=123456 + -D BLE_DEBUG_LOGGING=1 + -D OFFLINE_QUEUE_SIZE=256 + -D ENABLE_PRIVATE_KEY_IMPORT=1 + -D ENABLE_PRIVATE_KEY_EXPORT=1 +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 +build_src_filter = ${Arduino_Nesso_N1.build_src_filter} + + + - + +<../examples/companion_radio/*.cpp> +lib_deps = + ${Arduino_Nesso_N1.lib_deps} + densaugeo/base64 @ ~1.4.0 diff --git a/variants/arduino_nesso_n1/target.cpp b/variants/arduino_nesso_n1/target.cpp new file mode 100644 index 000000000..6118453c1 --- /dev/null +++ b/variants/arduino_nesso_n1/target.cpp @@ -0,0 +1,54 @@ +#include +#include "target.h" + +ArduinoNessoN1Board board; + +#if defined(P_LORA_SCLK) + static SPIClass spi(0); + // replace P_LORA_RESET with -1 to indicate RESET is handled elsewhere (which is in ArduinoNessoN1Board.cpp) + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, -1, P_LORA_BUSY, spi); +#else + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, -1, P_LORA_BUSY); +#endif + +WRAPPER_CLASS radio_driver(radio, board); + +ESP32RTCClock fallback_clock; +AutoDiscoverRTCClock rtc_clock(fallback_clock); +SensorManager sensors; + +bool radio_init() { + MESH_DEBUG_PRINTLN("radio_init()"); + fallback_clock.begin(); + rtc_clock.begin(Wire); + + MESH_DEBUG_PRINTLN("radio.std_init() and return..."); +#if defined(P_LORA_SCLK) + spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI); + return radio.std_init(&spi); +#else + return radio.std_init(); +#endif +} + +uint32_t radio_get_rng_seed() { + return radio.random(0x7FFFFFFF); +} + +void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) { + radio.setFrequency(freq); + radio.setSpreadingFactor(sf); + radio.setBandwidth(bw); + radio.setCodingRate(cr); +} + +void radio_set_tx_power(uint8_t dbm) { + radio.setOutputPower(dbm); +} + +mesh::LocalIdentity radio_new_identity() { + RadioNoiseListener rng(radio); + return mesh::LocalIdentity(&rng); // create new random identity +} + + diff --git a/variants/arduino_nesso_n1/target.h b/variants/arduino_nesso_n1/target.h new file mode 100644 index 000000000..1aa0b392c --- /dev/null +++ b/variants/arduino_nesso_n1/target.h @@ -0,0 +1,22 @@ +#pragma once + +#define RADIOLIB_STATIC_ONLY 1 +#include +#include +#include "pins_arduino.h" +#include +#include +#include +#include +#include + +extern ArduinoNessoN1Board board; +extern WRAPPER_CLASS radio_driver; +extern AutoDiscoverRTCClock rtc_clock; +extern SensorManager sensors; + +bool radio_init(); +uint32_t radio_get_rng_seed(); +void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr); +void radio_set_tx_power(uint8_t dbm); +mesh::LocalIdentity radio_new_identity();