1 # AllWize to LoRaWAN - Proof of Concept
3 These two example codes are a PoC to send messages from a Wize node to The Things Network (or any other LoRaWAN server).
7 The PoC is based on two protocol implementations.
9 * LoRaWAN frame support for nodes
10 * Semtech legacy packet forwarder running on an ESP8266 acting as gateway
12 First the Wize payload in the node (sender) is encoded as a LoRaWAN compatible frame. This means that the total payload size is bigger than with just LoRaWAN, since its wrapped with Wize headers and checksum. The encription is done in the sender, just like with a regular LoRaWan node, using both the network and the application session keys. Only Activation-by-Personalisation (ABP) is supported.
14 The Wize message is received by a Wize single-channel gateway. The gateway does not decrypt the message and acts as a dumb bridge building an UDP frame compatible with the Semtech legacy packet forwarder protocol. It presents itself as an FSK gateway, providing useful information in the channel, datarate and RSSI fields.
16 Current limitations due to implementation details are:
20 * Payload size is big (i.e. more time on air)
26 To encode the message as a LoRaWAN compatible frame you just have to use the AllWize_LoRaWAN class instead of the AllWize class and provide proper activation keys. The AllWize_LoRaWAN class wraps up the AllWize class providing LoRaWAN frame encoding and AES encryption. The it relies on the underneath AllWize class to send the LoRaWAN message inside a Wize frame.
28 Here you have a fragment of the sample code:
31 #include "AllWize_LoRaWAN.h"
32 AllWize_LoRaWAN allwize(RX_PIN, TX_PIN, RESET_PIN);
36 // Init communication to the module
38 if (!allwize.waitForReady()) {
39 Serial.println("[WIZE] Error connecting to the module, check your wiring!");
45 allwize.setChannel(WIZE_CHANNEL, true);
46 allwize.setPower(WIZE_POWER);
47 allwize.setDataRate(WIZE_DATARATE);
50 allwize.joinABP(DEVADDR, APPSKEY, NWKSKEY);
58 The gateway code is meant to be run on an ESP8266 board with Wize module. This is the standard setup for our AllWize G1 gateways (a Wemos D1 with an AllWize K1 shield).
60 The gateway code is split into different "modules" (components) so it's easier to manage and understand. These modules are responsible for different actions:
62 * **main**: main entry point, initializes the different components and manages the polling
63 * **debug**: serial debug definitions
64 * **wifi**: handles WiFi connectivity
65 * **ntp**: keeps local RTC in time using NTP
66 * **wize**: handles incomming Wize messages
67 * **lorawan**: keeps gateway "alive" by pinging the server every 30s, encodes and sends messages inside UDP frames to the server
69 To configure the different modules, first copy the `configuration.sample.h` file to `configuration.h` and edit it providing proper information. At least you should provide the WiFi connection credentials and the Gateway configuration (location, type, description and admin email).
71 You will need two thrid party libraries (both available in the Arduino Library Manager):
73 * **EspSoftwareSerial** by @plerup (https://github.com/plerup/espsoftwareserial)
74 * **NtpClientLib** by @gmag11 (https://github.com/gmag11/NtpClient)
78 Copyright (C) 2018-2020 by AllWize ([http://allwize.io](http://allwize.io))
80 AllWize library is free software: you can redistribute it and/or modify
81 it under the terms of the GNU Lesser General Public License as published by
82 the Free Software Foundation, either version 3 of the License, or
83 (at your option) any later version.
85 AllWize library is distributed in the hope that it will be useful,
86 but WITHOUT ANY WARRANTY; without even the implied warranty of
87 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
88 GNU Lesser General Public License for more details.
90 You should have received a copy of the GNU Lesser General Public License
91 along with AllWize library. If not, see <http://www.gnu.org/licenses/>.