Skip to content

Commit

Permalink
Merge pull request YourproductSmarter#4 from TheThingsIndustries/master
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
GeproHenri authored Jun 6, 2017
2 parents 9e3eb29 + abab3d4 commit c747111
Show file tree
Hide file tree
Showing 13 changed files with 1,330 additions and 135 deletions.
29 changes: 29 additions & 0 deletions COMMISSION_AT_HOME.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Commissioning

During the E&A fair we had a couple of commissioning stations standing around where one could personalise, or commission, your KISS gadget. It is however also possible to commission the device without the commissioning stations. These stations did automate many steps, so at home the process is more complex.

## Prerequisites

* Follow the steps in the main README to install the latest version of the Arduino IDE.
* Also install the USB drivers, SparkFun AVR boards and TheThingsNetwork library.
* [A TTN account](https://account.thethingsnetwork.org/)

## Device info

In the Arduino IDE, go to **File->Examples->TheThingsNetwork->DeviceInfo**. This will open the Device Info example code. On line 7 replace `REPLACE_ME` by `TTN_FP_EU868`. Following the steps in the main readme, **upload** this firmware to the KISS gadget. After uploading the code, got to **Tools->Serial Monitor**. At the bottom of the newly opened serial monitor, change the baudrate to *9600 baud*.

Copy the 16 HEX characters following `EUI:` and use this to register a new device on The Things Network Console.

## Register a new device
[See the TTN documentation](https://www.thethingsnetwork.org/docs/devices/registration.html).

## SendOTAA example

Open the SendOTAA example from **File->Examples->TheThingsNetwork->SendOTAA**. Replace the keys at the top with the keys you got from the TTN Console. After uploading this example, check the console to see if you receive any data. If you don't, you do not have TTN coverage.

## Original Firmware

The previous example proved that we have a working KISS gadget, a working radio module, TTN coverage, and programmed valid keys into the KISS gadget. Now we can upload the original firmware back onto the KISS gadget. Follow the steps in the readme inside the *KISSLoRa-demo_app* directory.


> This readme describes the steps necessary to commission a KISS gadget. Many details still need to be added, but the important steps are already included.
59 changes: 1 addition & 58 deletions Examples/CayenneLPP/CayenneLPP.ino
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ void setup()
debugSerial.println("-- JOIN");
ttn.join(appEui, appKey);

// Seed the random function
seedRandomFunction();

//start temperature and humidity sensor
sensor.begin();
}
Expand All @@ -86,7 +83,7 @@ void sendData(uint8_t port)
getAcceleration(&x, &y, &z);
lpp.addAccelerometer(6, x, y, z);

ttn.sendBytes(lpp.getBuffer(), lpp.getSize(), 2, false, getSF());
ttn.sendBytes(lpp.getBuffer(), lpp.getSize(), port);
}

uint8_t getButtonPressed()
Expand Down Expand Up @@ -141,60 +138,6 @@ uint16_t get_lux_value()
return (uint16_t)lux; //Return Lux value as value without decimal
}

void seedRandomFunction()
{
char hwEui_char_array[16+1];//16 chars + \0
uint16_t hwEui_16_bits = 0;

ttn.getHardwareEui(hwEui_char_array, 17); //read HWEUI from module
hwEui_16_bits = ascii_hex_to_nibble(hwEui_char_array[12]);
hwEui_16_bits |= ascii_hex_to_nibble(hwEui_char_array[13]) << 4;
hwEui_16_bits |= ascii_hex_to_nibble(hwEui_char_array[14]) << 8;
hwEui_16_bits |= ascii_hex_to_nibble(hwEui_char_array[15]) << 12;
uint16_t seed = hwEui_16_bits;
randomSeed(seed);
}

uint8_t getSF()
{
uint8_t txsf = 7;
uint8_t rnd = (uint8_t)random(1, 64);

if (rnd == 1 ) {
txsf = 12; // SF12
}
else if (rnd > 1 && rnd < 4 ) {
txsf = 11; // SF11
}
else if (rnd > 3 && rnd < 8 ) {
txsf = 10; // SF10
}
else if (rnd > 7 && rnd < 16 ) {
txsf = 9; // SF9
}
else if (rnd > 15 && rnd < 32 ) {
txsf = 8; // SF8
}
else {
txsf = 7; // SF7
}
}

//This function is used to convert ascii-hex string to integer
static uint8_t ascii_hex_to_nibble(char ascii_hex)
{
uint8_t return_value=0;

if((ascii_hex >= 'A') && (ascii_hex <= 'F'))
{
return_value |= (ascii_hex - ('A' - 10));
}
else if((ascii_hex >= '0') && (ascii_hex <= '9'))
{
return_value |= (ascii_hex - '0');
}
return return_value;
}
//Write one register to the acceleromter
void writeAccelerometer(unsigned char REG_ADDRESS, unsigned char DATA)
{
Expand Down
Loading

0 comments on commit c747111

Please sign in to comment.