Skip to content

Latest commit

 

History

History
273 lines (214 loc) · 7.95 KB

README_TTN.md

File metadata and controls

273 lines (214 loc) · 7.95 KB

The Things Gateway Configuration

Official tutorial is available here

Procedure

  1. Remove the white cover
  2. Power on the TTN Gateway
  3. Press the red button for 5 seconds to reset WiFi settings and Activation Settings
  4. Connect to the WiFi signal emitted from the Gateway (ex. TheThings-Gateway-xxxxx)
  5. Go to http://192.168.84.1/ and configure
GatewayID:
martel-ttn-01

Account Server:
https://eu1.cloud.thethings.network/

Gateway Key:
"Stored safely in local"

After configuration wait until 4 out of 5 blue leds turn on.

The TTN Gateway is now ready to use.

NOTE: The led meaning documentation is available here

Seeeduino LoRaWAN Configuration

Device Info (seed-martel-001)

AppEUI: 8CF957200005727C
DevEUI: 70B3D57ED00561EC
AppKey: 51F58CAC3F5735E3D1F88DD3EADBE9C6

Application: oc-diorama-001

Device Info (seed-martel-002)

AppEUI: 8CF95720000569A6
DevEUI: 70B3D57ED00579DB
AppKey: F80714239C6BC515D1772ED0C38A55F0

Application: oc-diorama-002

Connection between Seeeduino LoRaWAN and TTN

At the moment there are 2 Seeeduino LoRaWAN connected to our account on The Things Network.

  • To add another Seeeduino you need to add a new End Device under an application in our TTN account, like oc-diorama-001 or oc-diorama-002.

  • If there is no application, it must be created.

  • Click on Add End Devide, choose the manual insertion method.

  • The Frequency Plan must be Europe 863-870MHz (SF9)

  • LoRaWAN version 1.0.3

  • The JoinEUI value can be found on the chip present on the Seeeduino LoRaWAN.

  • DevEui and AppKey must be generated and finally an ID must be chosen.

After this configuration the TTN will be ready to receive messages from our boards.

Send data to TTN

To send data to TTN we use has base the OTAA script provided by SeedStudio, you can find the code snipped at this link.

That code need to be a little corrected:

lora.setKey("2B7E151628AED2A6ABF7158809CF4F3C", "2B7E151628AED2A6ABF7158809CF4F3C"
"2B7E151628AED2A6ABF7158809CF4F3C");

The line above has to be removed and substitute with this one:

//void setId(char *DevAddr, char *DevEUI, char *AppEUI);
lora.setId(NULL, "12409E2345695432", "70B3D57EF0006593");
// setKey(char *NwkSKey, char *AppSKey, char *AppKey);
lora.setKey(NULL, NULL, "47BDA77B6D7B4DDA7DC182E54295FE4E");

NOTE: Data in the functions are just examples.

It is needed to configure those value with the one of the Seeeduino the user is intended to send messages with.

Details are available here

Compiling the OTAA sketch should make the Seeeduino connect to the Gateway and send messages to the TTN.

Receive data from TTN into IoT-LoRaWan Agent

In order to receive data from TTN the IoT-Lorawan Agent should subscribe to the applications on the TTN platform.

The code below is the comand, already configured, that we use in order to connect.

Two keys, one for each application are generated in order to connect and used as password.

curl --location --request POST 'localhost:4042/iot/services' \
--header 'fiware-service: openiot' \
--header 'fiware-servicePath: /' \
--header 'Content-Type: application/json' \
--data-raw '{
  "services": [
    {
      "device_id": "urn:ngsi-ld:WasteContainer:martel-ttn-001",
      "entity_name": "urn:ngsi-ld:WasteContainer:martel-ttn-001",
      "entity_type": "WasteContainer",
      "apikey": "",
      "resource": "8CF957200005727C",
      "expressionLanguage": "jexl",
      "attributes": [
        {
          "object_id": "temperature_1",
          "name": "temperature",
          "type": "Number"
        },
        {
          "object_id": "relative_humidity_1",
          "name": "relativeHumidity",
          "type": "Number"
        },
        {
          "object_id": "digital_in_1",
          "name": "fillingLevel",
          "type": "Number"
        },
        {
          "object_id": "digital_in_2",
          "name": "status",
          "type": "Text",
          "expression" : "digital_in_2 == 0 ? \"Ok\" : digital_in_2 == 1 ? \"Lid Open\" : digital_in_2 == 2 ? \"Dropped\" :\"Burning\" "
        }
      ],
      "internal_attributes": {
        "lorawan": {
          "application_server": {
            "host": "eu1.cloud.thethings.network",
            "username": "oc-diorama-001@ttn",
            "password": "pass",
            "provider": "TTN"
          },
          "app_eui": "8CF957200005727C",
          "application_id": "oc-diorama-001@ttn",
          "application_key": "51F58CAC3F5735E3D1F88DD3EADBE9C6",
          "data_model": "application_server"
        }
      }
    }
  ]}'

curl --location --request POST 'localhost:4042/iot/services' \
--header 'fiware-service: openiot' \
--header 'fiware-servicePath: /' \
--header 'Content-Type: application/json' \
--data-raw '{
  "services": [
    {
      "device_id": "urn:ngsi-ld:AirQualityObserved:martel-ttn-002",
      "entity_name": "urn:ngsi-ld:AirQualityObserved:martel-ttn-002",
      "entity_type": "environment",
      "apikey": "",
      "resource": "8CF95720000569A6",
      "expressionLanguage": "jexl",
      "attributes": [
        {
          "object_id": "digital_in_1",
          "name": "NO2",
          "type": "Number"
        },
        {
          "object_id": "digital_in_2",
          "name": "C2H50H",
          "type": "Number"
        },
        {
          "object_id": "digital_in_3",
          "name": "VOC",
          "type": "Number"
        },
        {
          "object_id": "digital_in_4",
          "name": "CO",
          "type": "Number"
        },
        {
          "object_id": "digital_in_5",
          "name": "airQuality",
          "type": "Text",
          "expression" : "digital_in_5 == 0 ? \"Good\" : digital_in_5 == 1 ? \"Low\" : digital_in_5 == 2 ? \"Med\" : \"High\" "
        },
        {
          "object_id": "digital_in_6",
          "name": "sound",
          "type": "Number"
        },
        {
          "object_id": "digital_in_7",
          "name": "UVvalue",
          "type": "Number"
        }
      ],
      "internal_attributes": {
        "lorawan": {
          "application_server": {
            "host": "eu1.cloud.thethings.network",
            "username": "oc-diorama-002@ttn",
            "password": "",
            "provider": "TTN"
            },
            "app_eui": "8CF95720000569A6",
            "application_id": "oc-diorama-002@ttn",
            "application_key": "F80714239C6BC515D1772ED0C38A55F0",
            "data_model": "application_server"
          }
        }
      }
    ]}'

Required libraries for seed-martel-001

Sensors Specifications

Required libraries for seed-martel-002

Sensors Specifications