-
Notifications
You must be signed in to change notification settings - Fork 0
/
PT_FOTA_PO_V2.ino
103 lines (89 loc) · 2.49 KB
/
PT_FOTA_PO_V2.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
#include <WiFi.h>
#include <HTTPClient.h>
#include <HTTPUpdate.h>
#include <WiFiClientSecure.h>
#include "cert.h"
//const char * ssid = "home_wifi";
//const char * password = "helloworld";
const char * ssid = "PC";
const char * password = "idhh1925";
//Fota Deatals for GIT--------------
String FirmwareVer = {
"2.6"
};
#define URL_fw_Version "https://raw.githubusercontent.com/khirds/powertalkz/main/bin_version.txt"
#define URL_fw_Bin "https://raw.githubusercontent.com/khirds/powertalkz/main/fw.bin"
//Fota details end---------------------------------------
void connect_wifi();
void firmwareUpdate();
int FirmwareVersionCheck();
unsigned long previousMillis = 0; // will store last time LED was updated
unsigned long previousMillis_2 = 0;
const long interval = 60000;
const long mini_interval = 1000;
void repeatedCall() {
static int num=0;
unsigned long currentMillis = millis();
if ((currentMillis - previousMillis) >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
if (FirmwareVersionCheck()) {
firmwareUpdate();
}
}
if ((currentMillis - previousMillis_2) >= mini_interval) {
previousMillis_2 = currentMillis;
Serial.print("idle loop...");
Serial.print(num++);
Serial.print(" Active fw version:");
Serial.println(FirmwareVer);
if(WiFi.status() == WL_CONNECTED)
{
Serial.println("wifi connected");
}
else
{
connect_wifi();
}
}
}
struct Button {
const uint8_t PIN;
uint32_t numberKeyPresses;
bool pressed;
};
Button button_boot = {
0,
0,
false
};
/*void IRAM_ATTR isr(void* arg) {
Button* s = static_cast<Button*>(arg);
s->numberKeyPresses += 1;
s->pressed = true;
}*/
void IRAM_ATTR isr() {
button_boot.numberKeyPresses += 1;
button_boot.pressed = true;
}
void setup() {
pinMode(button_boot.PIN, INPUT);
attachInterrupt(button_boot.PIN, isr, RISING);
Serial.begin(115200);
Serial.print("Active firmware version:");
Serial.println(FirmwareVer);
pinMode(LED_BUILTIN, OUTPUT);
connect_wifi();
Serial.println(URL_fw_Version);
Serial.println(URL_fw_Bin);
// #define URL_fw_Version "https://raw.githubusercontent.com/khirds/powertalkz/main/bin_version.txt"
//#define URL_fw_Bin "https://raw.githubusercontent.com/khirds/powertalkz/main/fw.bin"
}
void loop() {
if (button_boot.pressed) { //to connect wifi via Android esp touch app
Serial.println("Firmware update Starting..");
firmwareUpdate();
button_boot.pressed = false;
}
repeatedCall();
}