zykes

Untitled

Apr 23rd, 2017
612
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. /*
  2.   LoRa_Simple_Client_DHT11 for Arduino:
  3.   Support Devices:
  4.   1/ LoRa Shield + Arduino + DHT11 Temperature Sensor
  5.   2/ LoRa mini / LoRa mini dev + DHT11 Temperature Sensor
  6.  
  7.   Hardware Connection:
  8.   1/ Connect DHT11 vcc to 3.3v
  9.   2/ Connect DHT11 GND to LoRa mini dev GND
  10.   3/ Connect DHT11 Data pin to LoRa mini dev A0 pin
  11.  
  12.   Software Requirement:
  13.   1/ Install the Radiohead Library(http://www.airspayce.com/mikem/arduino/RadioHead/) to Arduino.
  14.  
  15.   Example sketch showing how to get temperature and humidity value and send to
  16.   LoRa Gateway: Detail refer
  17.   http://wiki.dragino.com/index.php?title=LoRa_Mini#Example_2:_Multi_LoRa_nodes_simple_connection_--_RadioHead_Lib
  18.  
  19.   It is designed to work with the other example LoRa_Simple_Gateway_DHT11
  20.  
  21.   modified 25 MAr 2017
  22.   by Dragino Tech <[email protected]>
  23.   Dragino Technology Co., Limited
  24. */
  25.  
  26. #include <SPI.h>
  27. #include <RH_RF95.h>
  28. #include <string.h>
  29.  
  30. #include <OneWire.h>
  31. #include <DallasTemperature.h>
  32.  
  33. #define ONE_WIRE_BUS PD4
  34. OneWire oneWire(ONE_WIRE_BUS);
  35. DallasTemperature sensors(&oneWire);
  36.  
  37. RH_RF95 rf95;
  38. float frequency = 868.0; // Change the frequency here.
  39.  
  40. byte bGlobalErr;
  41.  
  42. void setup()
  43. {
  44.    Serial.begin(9600);
  45.    while (!Serial) ; // Wait for serial port to be available
  46.  
  47.    if (!rf95.init()) {
  48.      Serial.println("init failed");
  49.    }
  50.    Serial.println("Humidity and temperature\n\n");
  51.   // Setup ISM frequency
  52.    rf95.setFrequency(frequency);
  53.    // Setup Power,dBm
  54.    rf95.setTxPower(13);
  55.  
  56.    sensors.begin();
  57. }
  58.  
  59. void loop()
  60. {
  61.     uint8_t data[50] = {0} ;
  62.     data[0] = 1 ;
  63.     data[1] = 1 ;
  64.     data[2] = 1 ;// Use Data [0].Data[1], Data[2] to combine a Device ID.
  65.  
  66.     Serial.print(" Requesting temperatures...");
  67.     sensors.requestTemperatures();
  68.     Serial.println("DONE");
  69.  
  70.     float temp = sensors.getTempCByIndex(0);
  71.     Serial.println(temp);
  72.     data[3] = temp;
  73.  
  74.     rf95.send(data, sizeof(data)); // Send out ID + Sensor data to LoRa gateway
  75.     delay(5000);
  76. }
Advertisement
Add Comment
Please, Sign In to add comment