forked from gravitech-engineer/AIS_IoT_4G
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetControlPlaintext_LED.ino
69 lines (65 loc) · 2.07 KB
/
getControlPlaintext_LED.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
#include <Arduino.h>
#include <MAGELLAN_SIM7600E_MQTT.h>
#define LED_E15 15 //LED Builtin Board 4G
MAGELLAN_SIM7600E_MQTT magel;
void setup()
{
Serial.begin(115200);
magel.begin();
pinMode(LED_E15, OUTPUT);
digitalWrite(LED_E15, LOW);
//{1} control get any key and value
magel.getControl([](String key, String value){
Serial.print("# Control incoming\n# [Key]: ");
Serial.println(key);
Serial.print("# [Value]: ");
Serial.println(value);
if(key == "Lamp1")
{
if(value == "1")
{
digitalWrite(LED_E15, HIGH);
Serial.println("LED ON");
magel.control.ACK("Lamp1", String(digitalRead(LED_E15))); //ACKNOWLEDGE control to magellan
}
else if (value == "0")
{
digitalWrite(LED_E15, LOW);
Serial.println("LED OFF");
magel.control.ACK("Lamp1", String(digitalRead(LED_E15))); //ACKNOWLEDGE control to magellan
}
}
else // ACKNOWLEDGE control to magellan form another control focus
{
magel.control.ACK(key, value); //ACKNOWLEDGE control to magellan
}
});
//or {2} get control by focus on 1 key optional
// magel.getControl("Lamp1", [](String value){ // focus only value form key "Lamp1"
// Serial.print("# Control incoming focus on [Key] Lamp1: ");
// Serial.println(value);
// if(value == "1")
// {
// digitalWrite(LED_E15, HIGH);
// Serial.println("LED ON");
// magel.control.ACK("Lamp1", String(digitalRead(LED_E15))); //ACKNOWLEDGE control to magellan
// }
// else if (value == "0")
// {
// digitalWrite(LED_E15, LOW);
// Serial.println("LED OFF");
// magel.control.ACK("Lamp1", String(digitalRead(LED_E15))); //ACKNOWLEDGE control to magellan
// }
// });
// prepare sensor to magellan by report control key with inial value
magel.report.send("Lamp1","0");
}
void loop()
{
magel.loop();
magel.subscribes([](){
magel.subscribe.control(PLAINTEXT); // subscribe server config content type JSON
});
magel.interval(10,[](){ //time interval function inside every 10000 millis
});
}