-
Notifications
You must be signed in to change notification settings - Fork 0
/
RMakerMQBridge_SimpleDemo.ino
91 lines (76 loc) · 1.77 KB
/
RMakerMQBridge_SimpleDemo.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
#include "RMaker.h"
#include "WiFi.h"
#include "WiFiProv.h"
#include <WiFi.h>
extern "C" {
#include "freertos/FreeRTOS.h"
#include "freertos/timers.h"
}
#include <Wire.h>
#include <ESPmDNS.h>
#include <WiFiUdp.h>
static int gpio_0 = 0;
void node_configure();
#define DEFAULT_POWER_MODE false
float Bcharge = 0;
//Rainmaker Device Names - Types//
static Device front_lights("FrontLight", ESP_RMAKER_DEVICE_LIGHTBULB , NULL);
static Device Solar("Solar", "esp.device.temperature-sensor", NULL);
/*
Provisioning Service Name
*/
const char *service_name = "PROV_1234";
const char *pop = "abcd1234";
#include <AsyncMqttClient.h>
#define MQTT_HOST IPAddress(192, 168, 199, 8)
#define MQTT_PORT 1883
AsyncMqttClient mqttClient;
TimerHandle_t mqttReconnectTimer;
TimerHandle_t wifiReconnectTimer;
int strToInt(char* str)
{
int res = 0;
if (strcmp( "ON", str) == 0) {
res = 100;
}
return res;
}
float strToFloat(char* str)
{
return atof(str);
}
bool strToBool(char* str)
{
bool res = false;
if (strcmp( "ON", str) == 0) {
res = true;
}
return res;
}
void setup()
{
Serial.begin(115200);
node_configure();
MQ_Setup();
RMaker.start();
}
void loop()
{
if (digitalRead(gpio_0) == LOW) { //Push button pressed
// Key debounce handling
vTaskDelay(100);
Serial.printf("Pressed");
int startTime = millis();
while (digitalRead(gpio_0) == LOW) delay(50);
int endTime = millis();
if ((endTime - startTime) > 10000) {
// If key pressed for more than 10secs, reset all
Serial.printf("Reset to factory.\n");
RMakerFactoryReset(2);
} else if ((endTime - startTime) > 3000) {
Serial.printf("Reset Wi - Fi.\n");
// If key pressed for more than 3secs, but less than 10, reset Wi-Fi
RMakerWiFiReset(2);
}
}
}