Posts: 51
Threads: 18
Joined: Jan 2016
Reputation:
0
01-23-2019, 01:57 PM
(This post was last modified: 01-24-2019, 12:16 PM by Technomaker.)
Questo è lo sketch a cui ho aggiunto due righe per vedere se gira.
Code:
String Msg;
void setup() {
Serial.begin(57600);
delay(5000);
Serial.print("GO!");
}
void loop() {
int c;
while ((c = Serial.read()) > '\n') Msg += (char) c; // Read incoming chars, if any, until new line
if (c == '\n') // is the message complete?
{
Serial.println(Msg);
if (Msg.substring(0, 13).equals("$CLOUD-JOINED")) Serial.println("$CLOUD GET:DATE");
Msg = "";
}
Serial.print(".");
delay(500);
}
Ma sia con GET:DATE che con GET:TIME, sulla seriale non vedo altro se non i punti che riempiono lo schermo, segno che il programma gira.
La versione del firmware installata è l'ultima, presa dallo SHOP nel mese dicembre 2018.
L'IDE Arduino che compila lo sketch è installato su un Mac.
Lo strano è che se installo su iPhone 6 o su LG Android, lo sketch di esempio " Allarme con notifica push" funziona regolarmente e anche l'acquisizione della data.
Ho letto il listato ma non ancora capito come faccia quella funzione li. :D
Saluti
Posts: 51
Threads: 18
Joined: Jan 2016
Reputation:
0
C'e qualche comando particolare per connettersi al Cloud e ricevere la famosa scritta "CLOD-JOINED" ?
Io vedo che il led diventa giallo, segno che si è connesso al Cloud.
Saluti
Posts: 51
Threads: 18
Joined: Jan 2016
Reputation:
0
01-25-2019, 10:55 AM
(This post was last modified: 01-25-2019, 01:48 PM by EzioGi.
Edit Reason: visualizza emoticon al posto dei :
)
Questo è lo sketch che uso:
Code:
#include <Time.h>
#include <TimeLib.h>
#define ESP_PROGRAM_PIN 12
#define ESP_ENABLE_PIN 13
#define LAMP_PIN 21
#define BUZZER_PIN 20
#define PUSH_PERIOD_MS 30000
unsigned char lamp_set = 0;
unsigned char alarm_set = 0;
unsigned char push_set = 0;
unsigned char buzzer_set = 0;
unsigned char clock_sync = 0;
unsigned char flag_alarm = 0;
unsigned int lamp_timer_ms = 10; // timer in seconds
unsigned int counter_test_push = 1;
unsigned long LastPush_Time = 0x0FFFFFFF;
unsigned long TriggerAlarm_Time = 0;
unsigned long CurrentTime =0;
unsigned char hours;
unsigned char minutes;
unsigned char seconds;
unsigned char days;
unsigned char months;
unsigned int years;
String Msg;
void setup() {
Serial.begin(57600);
delay(5000);
Serial.println("");
SendPanel();
delay(10000);
Serial.println("$CLOUD GET:DATE");
//Serial.println("#C3:s~1:!9E6");
}
void loop() {
int c;
while ((c = Serial.read()) > '\n') Msg += (char) c;
if (c == '\n')
{
if (Msg.substring(0,7).equals("#:DATE:"))
{
// the entire message received has the form:
// #:DATE:1453635745818:2016:01:24:12:42:25:818
// where the fields are: Java Time, year, month, day, hour, minute, second, millisecond
years = Msg.substring(21,25).toInt();
months = Msg.substring(26,28).toInt();
days = Msg.substring(29,31).toInt();
hours = Msg.substring(32,34).toInt();
minutes = Msg.substring(35,37).toInt();
seconds = Msg.substring(38,40).toInt();
setTime(hours, minutes, seconds, days, months, years); // Method of library "Time"
old_rtc_time = now(); // Reads the current time, as a time_t number.
clock_sync = 1;
DisplayClock();
}
}
}
//----------------------------------------------------------------
void SendPanel(void)
{
Serial.println("\n$P:Dw!FFF;-0{%100,y6!062Tf*15d2:µPanel Alarm;}{~1^%100,y25!9E6#333{%50,y60M1*40fb:--:--;_M2*15:--/--/----;}|{%35,y60T*12fb:Last Alarm:;_M3*15:-;_M4*15:-;}}{%100,y2!FFF}{%100,y0.1!FFF}{^t%100,y66!DDD#333{%90,y5}");
DisplayClock();
}
void DisplayClock(void)
{
if (clock_sync == 1)
{
Serial.print("#M1");
if (hours < 10) Serial.print('0');
Serial.print(String(hours) + ":");
if (minutes < 10) Serial.print('0');
Serial.println(String(minutes));
Serial.print("#M2");
if (days < 10) Serial.print('0');
Serial.print(String(days) + "/");
if (months < 10) Serial.print('0');
Serial.print(String(months) + "/");
Serial.println(String(years));
}
else
{
Serial.println("#M1--:--");
Serial.println("#M2--/--/--");
}
}
e non visualizzo ne l'orario ne la data.
Se attivo il monitor vedo questi comandi:
$OK-PANEL
$OK-TCP2-CONNECTING
$OK-CLOUD
$TCP2: CONNECTED
$TCP2:SENT:1
$TCP2: DELETED
Mentre sulla seriale vedo:
$CLOUD GET: DATE
Se qualcuno mi da una mano a capire dove sbaglio gliene sarei grato.
Saluti
Posts: 100
Threads: 10
Joined: Apr 2016
Reputation:
3
02-01-2019, 03:04 PM
(This post was last modified: 02-01-2019, 03:21 PM by Dok.)
Se magari pubblichi uno sketch completo e almeno corretto di sintassi forse ti si può anche aiutare
Comunque parti con questo:
Quote:String Msg;
int counter = 0;
void setup() {
Serial.begin(57600);
delay(5000);
Serial.println("");
Serial.println("$PING 200");
}
void loop() {
int c;
while ((c = Serial.read()) > '\n') Msg += (char) c; // Read incoming chars, if any, until new line
if (c == '\n') // is the message complete?
{
Serial.println(Msg);
if (counter == 0) {
Serial.println("$CLOUD GET:TIME+1");
counter = 1;
}
Msg = "";
}
}
Posts: 51
Threads: 18
Joined: Jan 2016
Reputation:
0
Grazie per aver risposto con l'esempio del GET:TIME, che ma al momento non posso lo testare perché ho rotto il ADP-01 e il relativo SCF-01 come spiegato nel tread presente nel forum.
Appena mi arriva quello nuovo che ho ordinato, lo provo.
Il mio sketch precedente è stato preso da questo originale, adattandolo e modificandolo per le mie esigenze.:
Code:
/******************** **********************
* 24 gennaio 2019
* Used Time Library to calculate data and time:
* http://playground.arduino.cc/Code/Time
*
* --- IMPORTANTE ---:
* Modificato e adattato ad Arduino Nano
*
********************************************************/
#include <Time.h>
#include <TimeLib.h>
#define LAMP_PIN 21
#define BUZZER_PIN 20
#define PUSH_PERIOD_MS 30000 // intervallo[ms] minimo tra due push
unsigned char lamp_set = 0;
unsigned char alarm_set = 0;
unsigned char push_set = 0;
unsigned char buzzer_set = 0;
unsigned char clock_sync = 0;
unsigned char flag_alarm = 0;
unsigned int lamp_timer_ms = 10; // timer in seconds
unsigned int counter_test_push = 1;
unsigned long LastPush_Time = 0x0FFFFFFF;
unsigned long TriggerAlarm_Time = 0;
unsigned long CurrentTime =0;
unsigned char hours;
unsigned char minutes;
unsigned char seconds;
unsigned char days;
unsigned char months;
unsigned int years;
String Msg;
time_t rtc_time = 0;
time_t old_rtc_time = 0;
void setup() {
Serial.begin(57600);
pinMode(LAMP_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
delay(5000);
Serial.println("");
SendPanel();
// Interrupt on PIN 5 (D2) (will be called the function "IsrAlarm()" )
attachInterrupt(digitalPinToInterrupt(2), IsrAlarm, RISING);
}
void loop() {
int c;
while ((c = Serial.read()) > '\n') Msg += (char) c;
if (c == '\n')
{
// has the slider been moved?
if (Msg.substring(0,4).equals("#R1:") || Msg.substring(0,4).equals("#r1:")){
lamp_timer_ms = (int) Msg.substring(4).toInt(); // Read
Serial.print("#M5"); Serial.println(lamp_timer_ms, DEC); // Update message
}
else if (Msg.substring(0,4).equals("#W01")){ // Enable LAMP
lamp_set = 1;
}
else if (Msg.substring(0,4).equals("#W00")){ // Disable LAMP
lamp_set = 0;
}
else if (Msg.substring(0,4).equals("#W11")){ // Enable ALARM
alarm_set = 1;
Serial.println("#C4:s~2:z1d0");
Serial.println("#C5:s~3:z1d0");
}
else if (Msg.substring(0,4).equals("#W10")){ // Disable ALARM
alarm_set = 0;
Serial.println("#C4:s~2:z-1d0");
Serial.println("#C5:s~3:z-1d0");
digitalWrite(BUZZER_PIN, LOW); // Secure quite buzzer
}
else if (Msg.substring(0,4).equals("#W21")){ // Enable PUSH
push_set = 1;
}
else if (Msg.substring(0,4).equals("#W20")){ // Disable PUSH
push_set = 0;
}
else if (Msg.substring(0,4).equals("#W31")){ // Enable BUZZER
buzzer_set = 1;
}
else if (Msg.substring(0,4).equals("#W30")){ // Disable BUZZER
buzzer_set = 0;
digitalWrite(BUZZER_PIN, LOW); // Secure quite buzzer
}
else if (Msg.substring(0,4).equals("#B1P")) // TEST PUSH
{
Serial.print("$CLOUD SEND:PUSH: Test Push n.");
Serial.println(counter_test_push, DEC);
counter_test_push ++;
}
else if (Msg.substring(0,4).equals("#B2P")) // SYNC TIME
{
// "ask date and time to smartphone" (using the virtual object "panel command")
Serial.println("#C9:S:_da(1);;");
}
else if (Msg.substring(0,4).equals("#B3P")) // TEST BUZZER
{
digitalWrite(BUZZER_PIN, HIGH);
delay (2000);
digitalWrite(BUZZER_PIN, LOW);
}
else if (Msg.substring(0,7).equals("#:DATE:"))
{
// the entire message received has the form:
// #:DATE:1453635745818:2016:01:24:12:42:25:818
// where the fields are: Java Time, year, month, day, hour, minute, second, millisecond
years = Msg.substring(21,25).toInt();
months = Msg.substring(26,28).toInt();
days = Msg.substring(29,31).toInt();
hours = Msg.substring(32,34).toInt();
minutes = Msg.substring(35,37).toInt();
seconds = Msg.substring(38,40).toInt();
setTime(hours, minutes, seconds, days, months, years); // Method of library "Time"
old_rtc_time = now(); // Reads the current time, as a time_t number.
clock_sync = 1;
DisplayClock();
}
else if (Msg.equals("$RES")){ // WiFi Module unwanted RESET >>>>>>> send panel again
SendPanel();
}
Msg = ""; // Clean message string
}
// ********* check alarm in polling ********
if (flag_alarm == 1) // During a detected alarm
{
// Switch off alarm
if (millis() - TriggerAlarm_Time >= (unsigned long)(lamp_timer_ms *1000)) {
flag_alarm = 0;
Serial.println("#C3:s~1:!9E6"); // colore verde
digitalWrite(LAMP_PIN, LOW);
digitalWrite(BUZZER_PIN, LOW);
}
}
CheckClock();
}
// --------------------- Funzioni ---------------------------
// Interrupt Service Routine
void IsrAlarm (void){
if (flag_alarm == 0){ // NOT Retriggering Mode
TriggerAlarm_Time = millis();
flag_alarm = 1;
if (alarm_set == 1){
Serial.println("#C3:s~1:!F55"); // colore rosso
DisplayAlarm();
if (buzzer_set == 1)
digitalWrite(BUZZER_PIN, HIGH);
if (push_set == 1)
{
CurrentTime = millis();
if (CurrentTime - LastPush_Time >= (unsigned long)PUSH_PERIOD_MS ){
Serial.println("$CLOUD SEND:PUSH: ALARM Detected!");
LastPush_Time = CurrentTime; // save sending instant
}
}
}
if (lamp_set == 1)
digitalWrite(LAMP_PIN, HIGH);
}
}
void CheckClock(void){
rtc_time = now(); // Store the current time in time
if ( rtc_time - old_rtc_time >= 60) // Sync each 60 seconds
{
old_rtc_time = rtc_time;
years = year(rtc_time);
months = month (rtc_time);
days = day(rtc_time);
hours = hour(rtc_time);
minutes = minute(rtc_time);
seconds = second(rtc_time);
DisplayClock();
}
}
void DisplayClock(void)
{
if (clock_sync == 1)
{
Serial.print("#M1");
if (hours < 10) Serial.print('0');
Serial.print(String(hours) + ":");
if (minutes < 10) Serial.print('0');
Serial.println(String(minutes));
Serial.print("#M2");
if (days < 10) Serial.print('0');
Serial.print(String(days) + "/");
if (months < 10) Serial.print('0');
Serial.print(String(months) + "/");
Serial.println(String(years));
}
else
{
Serial.println("#M1--:--");
Serial.println("#M2--/--/--");
}
}
void DisplayAlarm(void)
{
if (clock_sync == 1)
{
Serial.print("#M3");
if (hours < 10) Serial.print('0');
Serial.print(String(hours) + ":");
if (minutes < 10) Serial.print('0');
Serial.println(String(minutes));
Serial.print("#M4");
if (days < 10) Serial.print('0');
Serial.print(String(days) + "/");
if (months < 10) Serial.print('0');
Serial.print(String(months) + "/");
Serial.println(String(years));
}
else
{
Serial.println("#M3Alarm detected!");
Serial.println("#M4Time not available");
}
}
void SendPanel(void)
{
Serial.println("\n$P:Dw!FFF;-0{%100,y6!062Tf*15d2:µPanel Alarm;}{~1^%100,y25!9E6#333{%50,y60M1*40fb:--:--;_M2*15:--/--/----;}|{%35,y60T*12fb:Last Alarm:;_M3*15:-;_M4*15:-;}}{%100,y2!FFF}{%100,y0.1!FFF}{^t%100,y66!DDD#333{%90,y5}{m<%90T*15:LAMP;|>W0F:0;}{%90,y5}{m<%90T*15:ALARM;|>W1F:0;}{%90,y5}{m<%90T*15:Notification;|z-1d0~2>W2F:0;}{%90,y5}{m<%90T*15:Buzzer;|z-1d0~3>W3F:0;}{%90,y5}=S1!AAA%32,10^fb;{m%95,y20B1s1:TEST PUSH;|B2s1:SYNC TIME;|B3s1:TEST BUZZER;}{m<%90T*15:Lamp: ;M5*15:10;T*15:s;|%60R1:0:60:1:10:100;}}");
// Check the status of all the panel objects (useful in case of unwanted RESET of the wifi module only)
if (lamp_set == 1) Serial.println("#W01");
if (push_set == 1) Serial.println("#W21");
if (buzzer_set == 1) Serial.println("#W31");
if (alarm_set == 1){
Serial.println("#W11");
Serial.println("#C4:s~2:z1d0");
Serial.println("#C5:s~3:z1d0");
}
Serial.print("#M5"); Serial.println(lamp_timer_ms, DEC); // Update message
DisplayClock(); // Display time
}
Saluti
Posts: 51
Threads: 18
Joined: Jan 2016
Reputation:
0
Sto tentando, senza successo di intercettare la risposta che contiene la data e ora, per poi elaborarla, ma senza successo.
Lo sketch che uso è il seguente:
Code:
String Msg;
int counter = 0;
void setup() {
Serial.begin(57600);
delay(5000);
Serial.println("");
Serial.println("$PING 200");
}
void loop() {
int c;
while ((c = Serial.read()) > '\n') Msg += (char) c; // Read incoming chars, if any, until new line
if (c == '\n') // is the message complete?
{
Serial.println(Msg);
if (Msg.substring(0,5).equals("$CLOUD")) Serial.println("... preso1 ... ");
if (counter == 0) {
Serial.println("$CLOUD GET:TIME+1");
counter = 1;
}
Msg = "";
if (Msg.substring(0,5).equals("$CLOUD")) Serial.println("... preso2... ");
}
}
Ho fatto un po di prove ma non riesco a capire dove mettere il comando per catturare la stringa.
Saluti
Posts: 100
Threads: 10
Joined: Apr 2016
Reputation:
3
a me così funziona
Code:
String Msg;
int counter = 0;
void setup() {
Serial.begin(57600);
delay(5000);
Serial.println("");
Serial.println("$PING 200");
}
void loop() {
int c;
while ((c = Serial.read()) > '\n') Msg += (char) c; // Read incoming chars, if any, until new line
if (c == '\n') // is the message complete?
{
Serial.println(Msg);
if (Msg.substring(0,6).equals("$CLOUD")) Serial.println("... preso1 ... ");
if (counter == 0) {
Serial.println("$CLOUD GET:TIME+1");
counter = 1;
}
if (Msg.substring(0,6).equals("$CLOUD")) Serial.println("... preso2... ");
Msg = "";
}
}
|