Guest User

Untitled

a guest
May 9th, 2018
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. // Include some libraries
  2. #include <dht.h> // Include the Digital Temperature Humidity Sensor Library
  3. #include <CayenneLPP.h> // Include the Cayenne Library
  4. #include <LoRaWan.h> // Include the LoRaWan Library
  5. #include <HP20x_dev.h>
  6. #include "Arduino.h"
  7. #include "Wire.h"
  8. #include <KalmanFilter.h>
  9.  
  10. // Initialize Libraries
  11. dht DHT;
  12. CayenneLPP lpp(51); // Max Message - 51 Bytes
  13. char buffer[256]; // Buffer for reading lora's parameters
  14.  
  15. // Define some variables
  16. #define DHT22_PIN 4 // Define the variable that the sensor is connected
  17.  
  18. void setup() {
  19. // put your setup code here, to run once:
  20. Serial.begin(9600);
  21. SerialUSB.begin(115200);
  22. delay(150);
  23. HP20x.begin();
  24. delay(100);
  25.  
  26. lora.init(); // Initialize
  27.  
  28. memset(buffer, 0, 256);
  29. lora.getVersion(buffer, 256, 1); //get board version
  30.  
  31. memset(buffer, 0, 256);
  32. lora.getId(buffer, 256, 1); //get DevEUI
  33.  
  34. // void setId(char *DevAddr, char *DevEUI, char *AppEUI);
  35. lora.setId("26011F41", "001C864F75182C45", "70B3D57ED000C00E");
  36.  
  37. // setKey(char *NwkSKey, char *AppSKey, char *AppKey);
  38. lora.setKey("9B1FDB959EA1430CF6D5AEC58A30018E", "9AE4543378E0C2B88E79015C984BAE71", NULL);
  39.  
  40. lora.setDeciveMode(LWABP); //Set Mode (OTAA or ABP)
  41. lora.setDataRate(DR0, EU868); //Set Data Rate
  42.  
  43. //Set the channels
  44. lora.setChannel(0, 868.1);
  45. lora.setChannel(1, 868.3);
  46. lora.setChannel(2, 868.5);
  47.  
  48. //Set receive parameters
  49. lora.setReceiceWindowFirst(0);
  50. lora.setReceiceWindowSecond(869.5, DR3);
  51.  
  52. //Set power
  53. lora.setPower(20);
  54. }
  55.  
  56. void loop() {
  57. // put your main code here, to run repeatedly:
  58. bool result = false;
  59. int chk = DHT.read22(DHT22_PIN);
  60.  
  61. float temp = DHT.temperature;
  62. float hum = DHT.humidity;
  63. float uv = analogRead(A0);
  64. float bPressure = HP20x.ReadPressure() /100.0;
  65. float bTemp = HP20x.ReadTemperature() /100.0;
  66. float bAltitude = HP20x.ReadAltitude() /100.0;
  67.  
  68. // Send temperature and humidity sensor data
  69. lpp.reset();
  70. lpp.addTemperature(0, temp);
  71. lpp.addRelativeHumidity(1, hum);
  72. lpp.addLuminosity(2, uv);
  73. lpp.addBarometricPressure(3, bPressure);
  74. lpp.addTemperature(4, bTemp);
  75. lpp.addAnalogInput(5, bAltitude);
  76.  
  77. result = lora.transferPacket(lpp.getBuffer(), lpp.getSize());
  78. }
Advertisement
Add Comment
Please, Sign In to add comment