-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbotany-temperature-02.ino
105 lines (78 loc) · 2.8 KB
/
botany-temperature-02.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <math.h>;
const int B = 4275; // B value of the thermistor
const int R0 = 100000; // R0 = 100k
const int pinTempSensor = A0; // Grove - Temperature Sensor connect to A0
//#if defined(ARDUINO_ARCH_AVR)
//#define debug Serial
//#elif defianed(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
//#define debug SerialUSB
//#else
//#define debug Serial
//#endif
#include <LoRaWan.h>
//unsigned char buffer[128] = {0xef, 0xff, 0x55, 3, 4, 5, 6, 7, 8, 9,};
unsigned char data[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0xA,};
char buffer[256];
void setup(void)
{
// SerialUSB.begin(115200);
// while(!SerialUSB);
// digitalWrite(OUTPUT_PIN, HIGH);
// digitalWrite(OUTPUT_PIN, HIGH);
lora.setDeviceLowPower();
lora.init();
memset(buffer, 0, 256);
lora.getVersion(buffer, 256, 1);
// SerialUSB.print(buffer);
memset(buffer, 0, 256);
lora.getId(buffer, 256, 1);
// SerialUSB.print(buffer);
//REPLACE THESE VALUES:
// lora.setId(char *DevAddr, char *DevEUI, char *AppEUI);
// lora.setKey(char *NwkSKey, char *AppSKey, char *AppKey);00DBBF7C763121C5
lora.setId("2701141E", "70B3D57ED8000D13", "00DBBF7C763121C5");
lora.setKey("EC9F5B199255BEE55D03D8A9CA607C2B", "EC9F5B199255BEE55D03D8A9CA607C2B", "EC9F5B199255BEE55D03D8A9CA607C2B");
lora.setDeciveMode(LWABP);
// lora.setDeciveMode(LWOTAA);
lora.setDataRate(DR0, EU868);
lora.setChannel(0, 868.1);
lora.setChannel(1, 868.3);
lora.setChannel(2, 868.5);
lora.setChannel(3, 867.1);
lora.setChannel(4, 867.3);
lora.setChannel(5, 867.5);
lora.setChannel(6, 867.7);
lora.setReceiceWindowFirst(0, 868.1);
lora.setReceiceWindowSecond(869.5, DR3);
lora.setDutyCycle(false);
lora.setJoinDutyCycle(false);
lora.setPower(30);
// while(!lora.setOTAAJoin(JOIN)){
// SerialUSB.println("Trying to Join network");
// }
}
//void(* resetFunc) (void) = 0; //declare reset function @ address 0
void loop(void)
{
bool result = false;
int a = analogRead(pinTempSensor);
float R = 1023.0/a-1.0;
R = R0*R;
float temperature = 1.0/(log(R/R0)/B+1/298.15)-273.15; // convert to temperature via datasheet
char myTemp[8]; // empty string
uint16_t batteryVoltage = lora.getBatteryVoltage();
dtostrf(temperature, 6, 2, myTemp);
Serial.print("temperature = ");
Serial.println(temperature);
Serial.print("batteryVoltage = ");
Serial.println(batteryVoltage);
// SerialUSB.println("Send string packet to Pervasive Nation NOC.");
//This sketch will broadcast a string to Pervasive Nation Network
result = lora.transferPacket(myTemp, 8);
if (result == 0){
lora.setDeviceReset();
}
// SerialUSB.print("Sleep for 60000 ms (1minutes) ");
//delay(60000);
delay (10000);
}