Cytron LoRa-RFM Shield, this is the LoRa shield
915MHz LoRa Gateway Raspberry Pi Hat for the gateway.
This is the Arduino Code
#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>
#define Offset 0.00 // calibration for pH at standard value
static const PROGMEM u1_t NWKSKEY[16] = { FILLMEIN }; //Network session key with ttn
static const u1_t PROGMEM APPSKEY[16] = { FILLMEIN }; //Application key with ttn
static const u4_t DEVADDR = { 0x26041D70} ; //device address in ttn
void os_getArtEui (u1_t* buf) { }
void os_getDevEui (u1_t* buf) { }
void os_getDevKey (u1_t* buf) { }
static osjob_t sendjob;
const unsigned TX_INTERVAL =10;//transmission interval at time=1min
const lmic_pinmap lmic_pins = {
.nss = 10,
.rxtx = LMIC_UNUSED_PIN,
.rst = 7,
.dio = {2, 5, 6},
}; //LoRa pin mapping
void onEvent (ev_t ev) // controls the events occuring during the transmission
{
Serial.print(os_getTime());
Serial.print(": ");
switch (ev) {
case EV_SCAN_TIMEOUT:
Serial.println(F(“EV_SCAN_TIMEOUT”));
break;
case EV_BEACON_FOUND:
break;
case EV_BEACON_MISSED:
break;
case EV_BEACON_TRACKED:
break;
case EV_JOINING:
break;
case EV_JOINED:
break;
case EV_RFU1:
break;
case EV_JOIN_FAILED:
break;
case EV_REJOIN_FAILED:
break;
case EV_TXCOMPLETE:
if (LMIC.txrxFlags & TXRX_ACK)
Serial.println(F(“Received ack”));
if (LMIC.dataLen) {
Serial.println(F(“Received “));
Serial.println(LMIC.dataLen);
Serial.println(F(” bytes of payload”));
}
os_setTimedCallback(&sendjob, os_getTime() + sec2osticks(TX_INTERVAL), do_send);
break;
case EV_LOST_TSYNC:
break;
case EV_RESET:
break;
case EV_RXCOMPLETE:
break;
case EV_LINK_DEAD:
break;
case EV_LINK_ALIVE:
break;
default:
break;
} }
float t, turbidity, volt;
float p; // testing
int tempPin = 3; // testing
uint16_t temp;
float read_pH(int ph) //converts pH sensor reading to a pH value from 0-14
{
float voltage2= ph * (5.0 / 1023.0);
float pHValue = 3.5*voltage2+Offset;
return pHValue;
}
void do_send(osjob_t* j)
{
// Check if there is not a current TX/RX job running
if (LMIC.opmode & OP_TXRXPEND)
{
Serial.println(F(“OP_TXRXPEND, not sending”));
} else
{
p = analogRead(A1); // reads the analog data from A1
for(int i=0; i<800; i++) //The voltage from the sensor is quite noisy
{
int sensorvalue = analogRead(A0);
volt += sensorvalue * (5.0 / 1023.0);
//so I take 800 samples of data from turbidity sensor and then average
//Convert the analog reading (0~1023) to a voltage (0 ~ 5V)
}
float pHlevel= read_pH(p);
float ntu;
ntu = -1120.4*square(volt)+5742.3*volt-4352.9; // Calculate the current NTU
// converting voltage from turbidity sensor to NTU
uint16_t n = ntu ;
uint16_t pHV = (pHlevel* 100) ;
temp=analogRead(tempPin);
float mv = ( temp/1023.0)*5000;
float tempc = mv/10 ;
uint16_t tempy=tempc;
/* temp=DHT.read11(dht_apin); // getting temperature value from pin
uint16_t tempy=temp; //showing and storing the value
// val = analogRead(tempPin); // testing
//temp=analogRead(tempPin); */
byte payload[6]; // testing
payload[0] = highByte(n);
payload[1] = lowByte(n);
payload[2] = highByte(tempy);
payload[3] = lowByte(tempy);
payload[4] = highByte(pHV);
payload[5] = lowByte(pHV);
LMIC_setTxData2(1, payload, sizeof(payload), 0);
Serial.println(F("Packet queued"));
}
}
void setup() {
Serial.begin(115200);
Serial.println(F(“Starting”));
os_init();
LMIC_reset();
#ifdef PROGMEM
uint8_t appskey[sizeof(APPSKEY)];
uint8_t nwkskey[sizeof(NWKSKEY)];
memcpy_P(appskey, APPSKEY, sizeof(APPSKEY));
memcpy_P(nwkskey, NWKSKEY, sizeof(NWKSKEY));
LMIC_setSession (0x1, DEVADDR, nwkskey, appskey);
#else
LMIC_setSession (0x1, DEVADDR, NWKSKEY, APPSKEY);
#endif
#if defined(CFG_us915)
LMIC_selectSubBand(1);
#elif defined(CFG_au915)
LMIC_selectSubBand(3);
#endif
LMIC_setLinkCheckMode(0);
LMIC_setAdrMode(false);
LMIC.dn2Dr = DR_SF9;
LMIC_setDrTxpow(DR_SF7, 14);
do_send(&sendjob);
}
void loop()
{
os_runloop_once();
} // where the loop runs once
Yes I did. But nothing seemed to work