I did make a sensor to measure the temperature in my garden.
I get a box with 5 volt solar panel on , a lipo and a Lora32U4II board.
You can find the code and the data here.
****************************************************'
#include <lmic.h>
#include <hal/hal.h>
#include "LowPower.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 5
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
static const PROGMEM u1_t NWKSKEY[16] ={ 0x18, 0x35, 0xF9, 0x9E, 0x66, 0x06, 0x75, 0xF2, 0xE2, 0x31, 0xB5, 0x62, 0x9D, 0x53, 0x00, 0x00 };
static const u1_t PROGMEM APPSKEY[16] = { 0xF8, 0x72, 0x0D, 0x33, 0x59, 0x14, 0xCD, 0x73, 0xA1, 0x1A, 0xC2, 0xCB, 0x9C, 0x20, 0x00, 0x00 };
static const u4_t DEVADDR = 0x26011B00 ;
void os_getArtEui (u1_t* buf) { }
void os_getDevEui (u1_t* buf) { }
void os_getDevKey (u1_t* buf) { }
float Celcius=0;
static uint8_t mydata[] = {0x00,0x00,0x00};
static osjob_t sendjob;
const lmic_pinmap lmic_pins = {
.nss = 8, // Digital pin connected to SS
.rxtx = LMIC_UNUSED_PIN, // we do not use these
.rst = 4, // Digital pin connected to RST
.dio = {7, 1, 2}, // Digital pin connected to 00,01,02
};
void onEvent (ev_t ev) {
switch(ev) {
case EV_TXCOMPLETE:
for (int i=0; i<=2; i++) {
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
}
do_send(&sendjob);
break;
}
}
void do_send(osjob_t* j){
if (LMIC.opmode & OP_TXRXPEND) {
} else {
LMIC_setTxData2(1, mydata, sizeof(mydata), 0);
}
}
void setup() {
sensors.begin();
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
LMIC_setupChannel(0, 868100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(1, 868300000, DR_RANGE_MAP(DR_SF12, DR_SF7B), BAND_CENTI); // g-band
LMIC_setupChannel(2, 868500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(3, 867100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(4, 867300000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(5, 867500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(6, 867700000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(7, 867900000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(8, 868800000, DR_RANGE_MAP(DR_FSK, DR_FSK), BAND_MILLI); // g2-band
LMIC_setLinkCheckMode(0);
LMIC_setDrTxpow(DR_SF7, 14);
LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100);
LMIC.dn2Dr = DR_SF9;
do_send(&sendjob);
}
void loop() {
os_runloop_once();
delay(1000);
sensors.requestTemperatures();
Celcius=sensors.getTempCByIndex(0)*100;
int hex1 = (int)Celcius >> 8;
int hex2 = (int)Celcius & 0xFF;
mydata[0]= hex1;
mydata[1]= hex2;
mydata[2]= (analogRead(A2)/15);
}