This repository has been archived by the owner on Feb 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SAMD_WiFiNINA_WM.ino
127 lines (107 loc) · 2.96 KB
/
SAMD_WiFiNINA_WM.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/****************************************************************************************************************************
SAMD_WiFiNINA_WM.ino
For SAMD using WiFiNINA Shield/Module
Blynk_WiFiNINA_WM is a library for the Mega, Teensy, SAM DUE, nRF52, STM32, SAMD and RP2040 boards
(https://github.com/khoih-prog/Blynk_WiFiNINA_WM) to enable easy configuration/reconfiguration and
autoconnect/autoreconnect of WiFiNINA/Blynk
Modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases
Built by Khoi Hoang https://github.com/khoih-prog/Blynk_WiFiNINA_WM
Licensed under MIT license
*****************************************************************************************************************************/
#include "defines.h"
#include "Credentials.h"
#include "dynamicParams.h"
void heartBeatPrint()
{
static int num = 1;
if (Blynk.connected())
{
Serial.print("B");
Blynk.virtualWrite(V0, "OK");
}
else
{
Serial.print("F");
}
if (num == 80)
{
Serial.println();
num = 1;
}
else if (num++ % 10 == 0)
{
Serial.print(" ");
}
}
void check_status()
{
static unsigned long checkstatus_timeout = 0;
#define STATUS_CHECK_INTERVAL 10000L
// Send status report every STATUS_REPORT_INTERVAL (10) seconds: we don't need to send updates frequently if there is no status change.
if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
{
// report status to Blynk
heartBeatPrint();
checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL;
}
}
void setup()
{
// Debug console
Serial.begin(115200);
while (!Serial);
//delay(1000);
Serial.print("\nStart SAMD_WiFiNINA_WM using WiFiNINA_Shield on ");
Serial.println(BOARD_NAME);
#if USE_BLYNK_WM
Serial.println(BLYNK_WIFININA_WM_VERSION);
Serial.println(DOUBLERESETDETECTOR_GENERIC_VERSION);
Serial.println(F("Start Blynk_WM"));
Blynk.setConfigPortalIP(IPAddress(192, 168, 120, 1));
//Blynk.setConfigPortal("SAMD", "MySAMD");
//Blynk.begin("SAMD-WiFiNINA");
Blynk.begin(HOST_NAME);
#else
Serial.println(F("Start Blynk"));
Blynk.begin(auth, ssid, pass, BlynkServer.c_str(), BLYNK_SERVER_HARDWARE_PORT);
#endif
}
#if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS)
void displayCredentials()
{
Serial.println("\nYour stored Credentials :");
for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++)
{
Serial.print(myMenuItems[i].displayName);
Serial.print(F(" = "));
Serial.println(myMenuItems[i].pdata);
}
}
void displayCredentialsInLoop()
{
static bool displayedCredentials = false;
if (!displayedCredentials)
{
for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++)
{
if (!strlen(myMenuItems[i].pdata))
{
break;
}
if ( i == (NUM_MENU_ITEMS - 1) )
{
displayedCredentials = true;
displayCredentials();
}
}
}
}
#endif
void loop()
{
Blynk.run();
check_status();
#if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS)
displayCredentialsInLoop();
#endif
}