Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- LoRa_Simple_Client_DHT11 for Arduino:
- Support Devices:
- 1/ LoRa Shield + Arduino + DHT11 Temperature Sensor
- 2/ LoRa mini / LoRa mini dev + DHT11 Temperature Sensor
- Hardware Connection:
- 1/ Connect DHT11 vcc to 3.3v
- 2/ Connect DHT11 GND to LoRa mini dev GND
- 3/ Connect DHT11 Data pin to LoRa mini dev A0 pin
- Software Requirement:
- 1/ Install the Radiohead Library(http://www.airspayce.com/mikem/arduino/RadioHead/) to Arduino.
- Example sketch showing how to get temperature and humidity value and send to
- LoRa Gateway: Detail refer
- http://wiki.dragino.com/index.php?title=LoRa_Mini#Example_2:_Multi_LoRa_nodes_simple_connection_--_RadioHead_Lib
- It is designed to work with the other example LoRa_Simple_Gateway_DHT11
- modified 25 MAr 2017
- by Dragino Tech <[email protected]>
- Dragino Technology Co., Limited
- */
- #include <SPI.h>
- #include <RH_RF95.h>
- #include <string.h>
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #define ONE_WIRE_BUS PD4
- OneWire oneWire(ONE_WIRE_BUS);
- DallasTemperature sensors(&oneWire);
- RH_RF95 rf95;
- float frequency = 868.0; // Change the frequency here.
- byte bGlobalErr;
- void setup()
- {
- Serial.begin(9600);
- while (!Serial) ; // Wait for serial port to be available
- if (!rf95.init()) {
- Serial.println("init failed");
- }
- Serial.println("Humidity and temperature\n\n");
- // Setup ISM frequency
- rf95.setFrequency(frequency);
- // Setup Power,dBm
- rf95.setTxPower(13);
- sensors.begin();
- }
- void loop()
- {
- uint8_t data[50] = {0} ;
- data[0] = 1 ;
- data[1] = 1 ;
- data[2] = 1 ;// Use Data [0].Data[1], Data[2] to combine a Device ID.
- Serial.print(" Requesting temperatures...");
- sensors.requestTemperatures();
- Serial.println("DONE");
- float temp = sensors.getTempCByIndex(0);
- Serial.println(temp);
- data[3] = temp;
- rf95.send(data, sizeof(data)); // Send out ID + Sensor data to LoRa gateway
- delay(5000);
- }
Advertisement
Add Comment
Please, Sign In to add comment