-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lora: Initial work at LoRaWAN support. Empty announcements. #70
Conversation
unsigned long lastAnnounce; | ||
uint8_t dataPacket[9]; | ||
|
||
// LoRa module pin mapping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might be able to get these from HAL.. but not sure HAL is aware of them if we don't pull in the Heltec libraries. Needs more investigation. For now we can just define these per board.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this have to be anything specific? There is a hardware ID that can be obtained from the (ESP) HAL (the WiFi MAC)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, that comment was aimed at the LoRa module pin mapping. The Heltec ESP32 V1 vs V2 has different pin mappings per device. I've seen some references to the pin mappings being available from HAL, but there are no docs around using them.
https://github.com/mcci-catena/arduino-lmic/blob/master/src/hal/getpinmap_heltec_lora32.cpp
void os_getDevKey (u1_t* buf) { } | ||
|
||
|
||
void onEvent(ev_t ev) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now we just blast our status to the network every 30 seconds. We could add some confirmation code to "ensure the network accepted the update", but for now i'm keeping it simple.
#define ANNOUNCE_INTERVAL 30 * 1000 // (In Milliseconds) | ||
|
||
|
||
// TODO: Store these via WebUI? We're doing (simple) ABP activation for now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ABP activation is where "every device is configured" OpenEVSE could move to a "OTAA" activation where devices "automatically register and activate themselves under an application" but this is overkill unless OpenEVSE wants to become a 'managed' product (plug it in, and it works under the OpenEVSE account)
Testing has been limited thus far, without a spare OpenEVSE module testing is tough since the ESP32 enters a "Unable to communicate to OpenEVSE" loop. The code was taken from another (working) project I have. All code remains inactive however unless you build for the heltec LoRa board. |
Oh.. beyond The Things Network, this code could be used to connect to any other LoRaWAN network (915 Mhz in the US). one option is Helium. https://developer.helium.com/console/cli Not sure of the options there, however there are a ton of Helium devices out there today. https://network.helium.com/coverage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the work on this, looks like an interesting project
unsigned long lastAnnounce; | ||
uint8_t dataPacket[9]; | ||
|
||
// LoRa module pin mapping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this have to be anything specific? There is a hardware ID that can be obtained from the (ESP) HAL (the WiFi MAC)
|
||
// TODO: Pack important OpenEVSE stats into dataPacket. | ||
|
||
LMIC_setTxData2(1, dataPacket, sizeof(dataPacket), true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When is the dataPacket filled in with the state?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this have to be anything specific? There is a hardware ID that can be obtained from the (ESP) HAL (the WiFi MAC)
The three values identify + authenticate the OpenEVSE unit on the LoRaWAN network. Pretty much the three values are generated at your LoRaWAN gateway provider and filled in. The values will be unique per OpenEVSE unit. (prime candidates for a webui setting)
Other things to adjust in the web ui in the future are the LoRa Spread factor. (7 = narrow bandwidth, but less prone to interference. 12 = wide bandwidth, but more prone to interference)
https://www.thethingsnetwork.org/article/how-spreading-factor-affects-lorawan-device-battery-life explains SF a bit.
When is the dataPacket filled in with the state?
That's what the todo is for :-) We need to decide what's "important enough" to broadcast over LoRaWAN to a gateway potentially a few miles away. Charger state, vehicle state of charge, etc. Likely some subset of what you can send to MQTT today. we should pack these as small as possible to improve reliability. (two bits for charger state, etc)
Pretty much, data payloads that are sent over LoRa need to be as small as possible. But essentially we're free to pack whatever OpenEVSE stats we want to.
Then, you add some "decoding logic" at the destination to unpack the lora data into whatever structure you want before passing it onto other integrations.
There is a review of the process here:
https://hackmd.io/@pmanzoni/Hy6qUmbA4
I'm using The Things Network here since it's free and has a low bar to entry. There are several however. Essentially a LoRaWAN gateway such as The Things Network is an online API to:
- Receive data from physical LoRaWAN gateway devices attached to the internet.
- Translate the data from LoRaWAN, and send to configured integrations.
Think of LoRaWAN gateways as "cell phone towers". Anyone can use the LoRaWAN gateway you provide, but each LoRaWAN gateway is configured for "a single gateway service" like The Things Network (free), helium.com (cryptocurrency based cost to use LoRaWAN), loriot.io (haven't looked at them yet)
src/lora.cpp
Outdated
|
||
LMIC_setTxData2(1, dataPacket, sizeof(dataPacket), true); | ||
|
||
lastAnnounce = millis(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IHMO it is better to work out what time the next packet should be, ie:
lastAnnounce = millis(); | |
nextAnnounce = millis() + ANNOUNCE_INTERVAL; |
You only need to do the addition once rather than every check, but a minor point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. Good point :-)
7b1e0c7
to
1ea51f7
Compare
Ok. The latest patch has a bunch of fixes and actually pushes useful data over LoRaWAN :-) The only change which is active when building non-lora enabled firmware is the addition of the "create_rapi_packed" function to input.cpp. This takes important values and packs them into a bunch of uint8's to be broadcast over LoRa. If a value could be reasonably > 255, I added a conversion factor (voltage, elapsed, temp) Keep in mind this is all still untested. I need to short circut the OpenEVSE communication tests to try and fake the ESP32 to send some data over LoRaWAN. |
Replaced by #537 |
This has been greatly simplified using a common LoRa library, and removing the Heltec code.
(these can be pulled via the OpenEVSE storage, but just not there yet)
(the status is empty at the moment, need to pull from OpenEVSE still. The status information needs packed into as small a datastructure as possible)