Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
epiller committed Jan 10, 2020
2 parents c315aa4 + 8c3d238 commit 8b0a343
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
45 changes: 23 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,11 @@ modem.getSpreadingFactor();

The `LoRa Modem` class can be used as parameter in the Device class.

## Device
This class has only one parameter in it's constructor and that's a parameter of type Modem.
Class is used to send a payload to the modem.
You can also send the options for the specific modem
#### Sending data
For sending payload data to the backend, we can use following statement:

```
device.send(&payload);
device.send(&payload, &options);
modem.send(payload);
```

## Payload
Expand All @@ -135,15 +132,15 @@ This class is almost the same as the previous version, except you have now one f
```
CBORPayload payload;
payload.map(3);
payload.reset();
payload.set("Battery", 39);
payload.set("DoorOpen", true);
payload.set("Temp", 24.5);
```

Like mentioned before, you use the device class to send the payload
```
device.send(&payload);
modem.send(payload);
```

*CBOR payload also supports tag 103 and 120*
Expand All @@ -152,24 +149,24 @@ Tag 103 is automatically used when you add a Geolocation object (example GPSCBOR
```
GeoLocation geoLocation(51.4546534, 4.127432, 11.2);
payload.map(1);
payload.reset();
payload.set("loc", &geoLocation);
device.send(&payload);
modem.send(payload);
```

Tag 120 is used when you set the timestamp (example iotDataPoint)
```
GeoLocation geoLocation(51.4546534, 4.127432, 11.2);
payload.map(4);
payload.reset();
payload.set("bat", 98);
payload.set("title", "Hello Universe");
payload.set("loc", &geoLocation);
payload.set("doorClosed", true);
payload.setTimestamp(138914018);
device.send(&payload);
modem.send(payload);
```

### Binary Payload
Expand All @@ -181,34 +178,39 @@ payload.set(17.56);
payload.set(true);
payload.set("hello");
device.send(&payload);
modem.send(payload);
```
OR

```
BinaryPayload payload01("Hello");
BinaryPayload payload02("from ");
device.send(&payload01);
modem.send(payload01);
delay(5000);
device.send(&payload02);
modem.send(payload02);
```

# Actuation
You can also have actuation support in your sketch, the only thing you have to do is add following lines of code:
```
void callback(const unsigned char* payload, unsigned int length, uint8_t port );
void callback(BinaryPayload &payload, LoRaOptions &options);
OTAACredentials credentials(DEVEUI, APPEUI, APPKEY);
LoRaModem modem(&loraSerial, &debugSerial, &credentials, callback);
Device device(&modem);
LoRaModem modem(loraSerial, debugSerial, credentials);
void callback(const unsigned char* payload, unsigned int length, uint8_t port )
void setup() {
modem.setDownlinkCallback(callback)
}
void callback(BinaryPayload &payload, LoRaOptions &options);
{
unsigned char* bytes = payload.getBytes();
int length = payload.getSize();
for (int i = 0; i < length; i++)
{
debugSerial.print(payload[i], HEX);
debugSerial.print(bytes[i], HEX);
}
debugSerial.println();
}
Expand All @@ -218,8 +220,7 @@ In the callback method you receive the payload that is sent from the backend.

**Parameters**
payload: the binary data received from the backend
length: total amounts of bytes in payload
port: on which port you received the data
options: LoRa option that were set

# Examples

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
#define debugSerial Serial // Define the serial interface that's going to be used for Serial monitor (debugging)
#define loraSerial Serial1 // Define the serial interface that'll be used for communication with the LoRa module
#define debugSerialBaud 57600 // Define the baud rate for the debugging serial port (used for Serial monitor)
#define sendEvery 300 // Number of seconds between sensor readings

float soundValue, lightValue, temperature, humidity, pressure, airValue; // Variables used to store our sensor data
unsigned int sendEvery = 300; // Creates a delay so the data is not constantly sent.

ABPCredentials credentials(DEVADDR, APPSKEY, NWKSKEY); // Define the credential variables loaded from the keys.h file
LoRaModem modem(loraSerial, debugSerial, credentials); // Define LoRa modem properties
Expand Down

0 comments on commit 8b0a343

Please sign in to comment.