Skip to content

Commit afd030b

Browse files
committed
update the lora shield
1 parent b94a436 commit afd030b

File tree

2 files changed

+53
-13
lines changed

2 files changed

+53
-13
lines changed

libraries/Dragino/examples/IoTServer/Cayenne and TTN/cayenne and ttn example/lora_shield DHT11 and Relay on the cayenne and ttn_examples/lora_shield_cayenne_and_ttn-abpClient/lora_shield_cayenne_and_ttn-abpClient.ino

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636

3737
dht DHT;
3838
#define DHT11_PIN A0
39-
const int ctl_pin=4; //define the input pin of realy
39+
const int ctl_pin=4; //define the output pin of realy
40+
const int flame_pin=3; //define the input pin of flame sensor
4041

4142
// LoRaWAN NwkSKey, network session key
4243
// This is the default Semtech key, which is used by the early prototype TTN
@@ -59,7 +60,7 @@ void os_getDevEui (u1_t* buf) { }
5960
void os_getDevKey (u1_t* buf) { }
6061

6162
static float temperature,humidity,tem,hum;
62-
static uint8_t LPP_data[10] = {0x01,0x67,0x00,0x00,0x02,0x68,0x00,0x03,0x01,0x00}; //0xO1,0x02,0x03 is Data Channel,0x67,0x68,0x01 is Data Type
63+
static uint8_t LPP_data[13] = {0x01,0x67,0x00,0x00,0x02,0x68,0x00,0x03,0x01,0x00,0x04,0x00,0x00}; //0xO1,0x02,0x03,0x04 is Data Channel,0x67,0x68,0x01,0x00 is Data Type
6364
static uint8_t opencml[4]={0x03,0x00,0x64,0xFF},closecml[4]={0x03,0x00,0x00,0xFF}; //the payload of the cayenne or ttn downlink //0xO1,0x02 is Data Channel,0x67,0x68 is Data Type
6465
static unsigned int count = 1;
6566

@@ -186,10 +187,11 @@ void dhtTem()
186187
LPP_data[6] = hum * 2;
187188
}
188189

189-
void ctl_pinread()
190+
void pinread()
190191
{
191-
int val;
192+
int val,val1;
192193
val=digitalRead(ctl_pin);
194+
val1=digitalRead(flame_pin);
193195
if(val==1)
194196
{
195197
LPP_data[9]=0x01;
@@ -198,6 +200,14 @@ void ctl_pinread()
198200
{
199201
LPP_data[9]=0x00;
200202
}
203+
if(val1==1)
204+
{
205+
LPP_data[12]=0x01;
206+
}
207+
else
208+
{
209+
LPP_data[12]=0x00;
210+
}
201211
}
202212

203213
void do_send(osjob_t* j){
@@ -206,7 +216,7 @@ void do_send(osjob_t* j){
206216
Serial.println(F("OP_TXRXPEND, not sending"));
207217
} else {
208218
dhtTem();
209-
ctl_pinread();
219+
pinread();
210220
// Prepare upstream data transmission at the next possible time.
211221
LMIC_setTxData2(1,LPP_data, sizeof(LPP_data), 0);
212222
Serial.println(F("Packet queued"));
@@ -220,6 +230,8 @@ void setup() {
220230
Serial.println("Connect to TTN and Send data to mydevice cayenne(Use DHT11 Sensor):");
221231

222232
pinMode(ctl_pin,OUTPUT);
233+
pinMode(flame_pin,INPUT);
234+
attachInterrupt(1,fire,LOW);
223235

224236
#ifdef VCC_ENABLE
225237
// For Pinoccio Scout boards
@@ -293,6 +305,14 @@ void setup() {
293305
do_send(&sendjob);
294306
}
295307

308+
void fire()
309+
{
310+
LPP_data[12]=0x00;
311+
dhtTem();
312+
LMIC_setTxData2(1,LPP_data, sizeof(LPP_data), 0);
313+
Serial.println("Have fire,the temperature is send");
314+
}
315+
296316
void loop() {
297317
os_runloop_once();
298318
}

libraries/Dragino/examples/IoTServer/Cayenne and TTN/cayenne and ttn example/lora_shield DHT11 and Relay on the cayenne and ttn_examples/lora_shield_cayenne_and_ttn-otaaClient/lora_shield_cayenne_and_ttn-otaaClient.ino

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,29 @@
3636

3737
dht DHT;
3838
#define DHT11_PIN A0
39-
const int ctl_pin=4; //define the input pin of realy
39+
const int ctl_pin=4; //define the output pin of realy
40+
const int flame_pin=3; //define the input pin of flame sensor
4041

4142
// This EUI must be in little-endian format, so least-significant-byte
4243
// first. When copying an EUI from ttnctl output, this means to reverse
4344
// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3,
4445
// 0x70.
45-
static const u1_t PROGMEM APPEUI[8]={ 0xBB, 0x66, 0x01, 0xD0, 0x7E, 0xD5, 0xB3, 0x70 };
46+
static const u1_t PROGMEM APPEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4647
void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);}
4748

4849
// This should also be in little endian format, see above.
49-
static const u1_t PROGMEM DEVEUI[8]={ 0x3F, 0x63, 0xB9, 0x66, 0xC0, 0xF5, 0x96, 0x00 };
50+
static const u1_t PROGMEM DEVEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
5051
void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);}
5152

5253
// This key should be in big endian format (or, since it is not really a
5354
// number but a block of memory, endianness does not really apply). In
5455
// practice, a key taken from ttnctl can be copied as-is.
5556
// The key shown here is the semtech default key.
56-
static const u1_t PROGMEM APPKEY[16] ={ 0x41, 0x2B, 0x22, 0x8A, 0xFD, 0x92, 0x57, 0xC1, 0x64, 0x4D, 0x3B, 0xC2, 0x1E, 0x3D, 0xAE, 0x65 };
57+
static const u1_t PROGMEM APPKEY[16] ={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
5758
void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16);}
5859

5960
static float temperature,humidity,tem,hum;
60-
static uint8_t LPP_data[10] = {0x01,0x67,0x00,0x00,0x02,0x68,0x00,0x03,0x01,0x00}; //0xO1,0x02,0x03 is Data Channel,0x67,0x68,0x01 is Data Type
61+
static uint8_t LPP_data[13] = {0x01,0x67,0x00,0x00,0x02,0x68,0x00,0x03,0x01,0x00,0x04,0x00,0x00}; //0xO1,0x02,0x03,0x04 is Data Channel,0x67,0x68,0x01,0x00 is Data Type
6162
static uint8_t opencml[4]={0x03,0x00,0x64,0xFF},closecml[4]={0x03,0x00,0x00,0xFF}; //the payload of the cayenne or ttn downlink
6263
static unsigned int count = 1;
6364

@@ -189,10 +190,11 @@ void dhtTem()
189190
LPP_data[6] = hum * 2;
190191
}
191192

192-
void ctl_pinread()
193+
void pinread()
193194
{
194-
int val;
195+
int val,val1;
195196
val=digitalRead(ctl_pin);
197+
val1=digitalRead(flame_pin);
196198
if(val==1)
197199
{
198200
LPP_data[9]=0x01;
@@ -201,6 +203,14 @@ void ctl_pinread()
201203
{
202204
LPP_data[9]=0x00;
203205
}
206+
if(val1==1)
207+
{
208+
LPP_data[12]=0x01;
209+
}
210+
else
211+
{
212+
LPP_data[12]=0x00;
213+
}
204214
}
205215

206216
void do_send(osjob_t* j){
@@ -209,7 +219,7 @@ void do_send(osjob_t* j){
209219
Serial.println(F("OP_TXRXPEND, not sending"));
210220
} else {
211221
dhtTem();
212-
ctl_pinread();
222+
pinread();
213223
// Prepare upstream data transmission at the next possible time.
214224
LMIC_setTxData2(1,LPP_data, sizeof(LPP_data), 0);
215225
Serial.println(F("Packet queued"));
@@ -223,6 +233,8 @@ void setup() {
223233
Serial.println("Connect to TTN and Send data to mydevice cayenne(Use DHT11 Sensor):");
224234

225235
pinMode(ctl_pin,OUTPUT);
236+
pinMode(flame_pin,INPUT);
237+
attachInterrupt(1,fire,LOW);
226238

227239
#ifdef VCC_ENABLE
228240
// For Pinoccio Scout boards
@@ -240,6 +252,14 @@ void setup() {
240252
do_send(&sendjob);
241253
}
242254

255+
void fire()
256+
{
257+
LPP_data[12]=0x00;
258+
dhtTem();
259+
LMIC_setTxData2(1,LPP_data, sizeof(LPP_data), 0);
260+
Serial.println("Have fire,the temperature is send");
261+
}
262+
243263
void loop() {
244264
os_runloop_once();
245265
}

0 commit comments

Comments
 (0)