Carlo Stramaglia
ITALY • + Follow
Edit Project
Components
|
ARDUINO_NANO |
x 1 | |
|
RP2040RASPBERRY-PI
|
x 1 | |
|
microSD_Card |
x 1 | |
|
RFM95 |
x 1 | |
|
868 Mhz Antenna |
x 1 | |
|
OLED 128x64 1.3 I2C |
x 1 | |
|
DHT22HAIGU
|
x 1 |
Description
End2End LoRa gateway and device tutorial
I would like to show you how I solved my problem of measuring the temperature and the humidity of my Wine Cellar in the basement of my house.
In the wine cellar, there is no wifi access and the connectivity is very bad! But I've noticed that the lora 868Mhz frequency was well received, so I decided to use lora protocol for getting real time temperature and humidity from my wine cellar.
This tutorial explains how to build an end to end lora network using very cheap components.
Code
IOT Lora
Arduino
#include <lmic.h>
#include <hal/hal.h>
#include "U8glib.h"
#include <DHT.h>
// OLED Display configuration
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0); // I2C / TWI
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define DHTPIN 8
DHT dht(DHTPIN, DHTTYPE);
// LoRaWAN NwkSKey, network session **** DO NOT USE AS IS. NEEDS TO BE CHANGED AS PER TUTORIAL ******
static const PROGMEM u1_t NWKSKEY[16] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
// LoRaWAN AppSKey, application session key **** DO NOT USE AS IS. NEEDS TO BE CHANGED AS PER TUTORIAL ******
static const u1_t PROGMEM APPSKEY[16] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
// LoRaWAN end-device address (DevAddr) **** DO NOT USE AS IS. NEEDS TO BE CHANGED AS PER TUTORIAL ******
static const u4_t DEVADDR = { 0xFFFFFFFF };
// These callbacks are only used in over-the-air activation, so they are
// left empty here (we cannot leave them out completely unless
// DISABLE_JOIN is set in config.h, otherwise the linker will complain).
void os_getArtEui (u1_t* buf) { }
void os_getDevEui (u1_t* buf) { }
void os_getDevKey (u1_t* buf) { }
//static uint8_t mydata[] = "LoRa Device Test";
static osjob_t sendjob;
// Schedule data trasmission in every this many seconds (might become longer due to duty
// cycle limitations).
// we set 10 seconds interval
const unsigned TX_INTERVAL = 10;
// Pin mapping according to Cytron LoRa Shield RFM
const lmic_pinmap lmic_pins = {
.nss = 10,
.rxtx = LMIC_UNUSED_PIN,
.rst = 7,
.dio = {2, 5, 6},
};
void onEvent (ev_t ev) {
switch(ev) {
case EV_TXCOMPLETE:
Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));
// Schedule next transmission
os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
break;
default:
Serial.println(F("Unknown event"));
break;
}
}
void do_send(osjob_t* j){
char ValueT[5];
char ValueH[5];
int Temperature;
int Humidity;
// Check if there is not a current TX/RX job running
if (LMIC.opmode & OP_TXRXPEND) {
Serial.println(F("OP_TXRXPEND, not sending"));
} else {
// Get Temperature
Temperature=int(dht.readTemperature()*10);
// Get humidity
Humidity=int(dht.readHumidity()*10);
// Format the values to be printed on OLED Screen
sprintf(ValueT, "%d.%d", int(dht.readTemperature()),int(dht.readTemperature()*10)-(int(dht.readTemperature())*10));
sprintf(ValueH, "%d.%d", int(dht.readHumidity()),int(dht.readHumidity()*10)-(int(dht.readHumidity())*10));
u8g.firstPage();
do {
draw("LoRa", 50, 10);
draw("Temperature:", 0, 30);
draw(ValueT, 85, 30);
draw("C", 115, 30);
draw("Humidity:", 0, 50);
draw(ValueH, 85, 50);
draw("%", 115, 50);
} while( u8g.nextPage() );
// prepare and schedule data for transmission
LMIC.frame[0] = Temperature >> 8;
LMIC.frame[1] = Temperature;
LMIC.frame[2] = Humidity >> 8;
LMIC.frame[3] = Humidity;
LMIC_setTxData2(1, LMIC.frame, 4, 0); // (port 1, 4 bytes, unconfirmed)
Serial.println(F("Packet queued"));
}
// Next TX is scheduled after TX_COMPLETE event.
}
void setup() {
Serial.begin(9600);
Serial.println(F("Starting"));
u8g.setColorIndex(1); // pixel on for Display
// Initialize Temp sensor device.
dht.begin();
// LMIC init
os_init();
// Reset the MAC state. Session and pending data transfers will be discarded.
LMIC_reset();
// Set static session parameters. Instead of dynamically establishing a session
// by joining the network, precomputed session parameters are be provided.
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);
// Disable link check validation
LMIC_setLinkCheckMode(0);
// Disable ADR
LMIC_setAdrMode(false);
// TTN uses SF9 for its RX2 window.
LMIC.dn2Dr = DR_SF9;
// Set data rate and transmit power for uplink (note: txpow seems to be ignored by the library)
LMIC_setDrTxpow(DR_SF7,14);
// Start job
do_send(&sendjob);
}
void loop() {
os_runloop_once();
}
void draw(char* parola, int posx, int posy) {
// graphic commands to redraw the complete screen should be placed here
u8g.setFont(u8g_font_tpssb);
u8g.drawStr( posx, posy, parola);
}
Schematic and Layout
Jul 09,2023
864 views
End2End LoRa gateway and device tutorial
I would like to show you how I solved my problem of measuring the temperature and the humidity of my Wine Cellar in the basement of my house
864
0
0
Published: Jul 09,2023
Purchase
Donation Received ($)
PCBWay Donate 10% cost To Author
Copy this HTML into your page to embed a link to order this shared project
Copy
Under the
Attribution-ShareAlike (CC BY-SA)
License.
Topic
- Comments(0)
- Likes(0)
You can only upload 1 files in total. Each file cannot exceed 2MB. Supports JPG, JPEG, GIF, PNG, BMP
0 / 10000
Remove
It looks like you have not written anything. Please add a comment and try again.
View More
View More
VOTING
0 votes
- 0 USER VOTES
0.00
- YOUR VOTE 0.00 0.00
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Design
1/4
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Usability
2/4
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Creativity
3/4
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Content
4/4
More by Carlo Stramaglia
- End2End LoRa gateway and device tutorial I would like to show you how I solved my problem of measuring the temperature and the humidity of my...
- Mobile LoRa short message transmitter/receiver Introduction I’ve always been fascinated by the fact that we can transmit data for a long distance b...
- W425010AS1D2_ESP 32 LoRa Do you want to have two LoRa devices communicate to each other? Then look at the video! It's very ea...
- Smart Arduino Digital Meter with HC-SR04 and TM1637 There are quite a few distant meters made with Arduino, but this is a special one.Two reasons why th...
- Drive an Old PC Fan with Arduino A few weeks ago, I found this old computer fan that was about to be thrown away.I took a look on the...
- Simple and easy weather station for indoor and outdoor The idea was to combine the 433Mhz transmission with exchange of data between two devices so a simpl...
- Arduino Audiometric Device I had a medical test and the doctor measured my hearing. When I left the medical center I said to my...
- Spin The Wheel! Today I built with Arduino a simple game for 2 players. Each player have to spin the wheel and the w...
- Sensor Station I wanted to have a simple station that monitors: Temperature, Humidity, Heat index, Carbon Monoxide,...
- Cool Way to Count the Euro Coins! This is a cool way to count coins. It's a scale that, with the help of Arduino, a display and a push...
- Cool Timer with Voice synthesizer I was looking for a timer that could be setup without looking at the display. Mainly the purpose was...
- Arduino Cloud TV Audience Measurement All TV's in Europe have a slot called Common Interface.In this slot you can place a Common Interface...
- APAN - Arduino Privacy Automatic Navigator Do you know that while you are browsing the internet, all your internet traffica may be recorded?Des...
- Arduino Tea Bag Timer Today I want to show you how Arduino can help you to make a perfect Tea!I always wanted to have the ...
- Arduino TTN LoRa node device using PCB Way This is a video that describes how you can build a #LoRa #TTN node using an #Arduino mini Pro with #...
- Biorhythm Clock Using Arduino Nano, RTC, 1602A and 74HC595 It's a biorhythm clock using Arduino Nano.A biorhythm is a theoretical process by which the human bo...
- Yet another Arduino clock.... But this is a nice one :-) I bought a very nice transparent display from DF Robot, and I will use it to build my new project.Th...
You may also like
-
-
-
3D printed Enclosure Backplate for Riden RD60xx power supplies
55 0 0 -
-
-
-
Sega Master System RGB Encoder Switcher Z80 QSB v1.2
57 0 0 -
18650 2S2P Battery Charger, Protection and 5V Output Board
78 0 0 -
High Precision Thermal Imager + Infrared Thermometer | OpenTemp
420 0 6 -
Sony PlayStation Multi Output Frequency Oscillator (MOFO) v1
129 0 2