Quantcast
Channel: The Things Network - Latest posts
Viewing all articles
Browse latest Browse all 116642

Proper setup?

$
0
0

Hi w4e,

Of course! This code we used on the workshop where I was yesterday. I deleted the in the code because code below is used to push data to the ThingsPark-platform of KPN.

We changed the line:
switch (LoRaBee.send(1, (uint8_t*)reading.c_str(), reading.length())) // TTN

This because there is no acknoweldgement-feature right now on the TTN (?)

/*
* Copyright (c) 2015 SODAQ. All rights reserved.
*
* This file is part of Sodaq_RN2483.
*
* Sodaq_RN2483 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or(at your option) any later version.
*
* Sodaq_RN2483 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sodaq_RN2483.  If not, see
* <http://www.gnu.org/licenses/>.
*/

#include <Sodaq_RN2483.h>
#include "DHT.h"

// MBili / Tatu
//#define debugSerial Serial
// Autonomo
#define debugSerial SerialUSB
#define loraSerial Serial1

#define DHTPIN 10 // what pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

DHT dht(DHTPIN, DHTTYPE);

// USE YOUR OWN KEYS!
const uint8_t devAddr[4] =
{
   <keyvalue>
};

// USE YOUR OWN KEYS!
const uint8_t appSKey[16] =
{
 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x80
};

// USE YOUR OWN KEYS!
const uint8_t nwkSKey[16] =
{
 0x0A, 0x1B, 0x2C, 0x3D, 0x4E, 0x5F, 0x0A, 0x1B, 0x2C, 0x3D, 0x4E, 0x5F, 0x0A, 0x1B, 0x2C, 0x80
};

void setup()
{
 // REMOVE WHEN YOU DONT USE PC
 // This line make the program only run when its connected to the serial monitor
 while ((!debugSerial) && (millis() < 10000));

	debugSerial.begin(57600);
	loraSerial.begin(LoRaBee.getDefaultBaudRate());

 digitalWrite(BEE_VCC, HIGH);

 pinMode(LED_BUILTIN, OUTPUT); 

	LoRaBee.setDiag(debugSerial); // optional
	if (LoRaBee.initABP(loraSerial, devAddr, appSKey, nwkSKey, true))
	{
		debugSerial.println("Connection to the network was successful.");
	}
	else
	{
		debugSerial.println("Connection to the network failed!");
	}

 dht.begin();
}

void loop()
{
 debugSerial.println();
 digitalWrite(BEE_VCC, HIGH);

 debugSerial.println("Sending payload: Humidity, Temperature");
 String reading = takeTPHReading();

		//switch (LoRaBee.sendReqAck(1, (uint8_t*)reading.c_str(), reading.length(), 8))// KPN
            switch (LoRaBee.send(1, (uint8_t*)reading.c_str(), reading.length()))// TTN
		{
		case NoError:
			debugSerial.println("Successful transmission.");
			break;
		case NoResponse:
			debugSerial.println("There was no response from the device.");
			break;
		case Timeout:
			debugSerial.println("Connection timed-out. Check your serial connection to the device! Sleeping for 20sec.");
			delay(20000);
			break;
		case PayloadSizeError:
			debugSerial.println("The size of the payload is greater than allowed. Transmission failed!");
			break;
		case InternalError:
			debugSerial.println("Oh No! This shouldn't happen. Something is really wrong! Try restarting the device!\r\nThe program will now halt.");
			while (1) {};
			break;
		case Busy:
			debugSerial.println("The device is busy. Sleeping for 10 extra seconds.");
			delay(10000);
			break;
		case NetworkFatalError:
			debugSerial.println("There is a non-recoverable error with the network connection. You should re-connect.\r\nThe program will now halt.");
			while (1) {};
			break;
		case NotConnected:
			debugSerial.println("The device is not connected to the network. Please connect to the network before attempting to send data.\r\nThe program will now halt.");
			while (1) {};
			break;
		case NoAcknowledgment:
			debugSerial.println("There was no acknowledgment sent back!");
			break;
		default:
			break;
		}
   // Delay between readings
   // 60 000 = 1 minute

   digitalWrite(LED_BUILTIN, HIGH);  //Set LED pin High
   debugSerial.println("LED_ON"); 

		delay(1000);

   digitalWrite(LED_BUILTIN, LOW);
   debugSerial.println("LED_OF");

}

String takeTPHReading()
{
 // Reading temperature or humidity takes about 250 milliseconds!
 // Sensor readings may also be up to A0 seconds 'old' (its a very slow sensor)
 float h = dht.readHumidity();
 float t = dht.readTemperature();

 String data = String(h)  + ", ";
 data += String(t);

 debugSerial.println(data);

 return data;
}

Viewing all articles
Browse latest Browse all 116642

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>