No es del código pero aquí esta:
String inputString = ""; // a String to hold incoming data
bool stringComplete = false; // whether the string is complete
int caso = 0;
void setup() {
pinMode(2, INPUT);
// initialize serial:
Serial.begin(9600);
// reserve 200 bytes for the inputString:
inputString.reserve(200);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
delay(10000);
Serial.println ("AT");
}
void loop() {
if (digitalRead(2) == 1 and caso == 0) {
digitalWrite(LED_BUILTIN, HIGH);
caso = 2;
Post();
}
// print the string when a newline arrives:
if (stringComplete) {
if ((inputString.indexOf("OK") != -1 or inputString.indexOf("NO CARRIER") != -1 or inputString.indexOf("DOWNLOAD") != -1) and (caso != 14) and (caso != 0)) {
delay(1000);
caso++;
Post();
}
if (inputString.indexOf("+HTTPACTION:") != -1 and caso == 14) {
digitalWrite(LED_BUILTIN, LOW);
caso++;
Post();
}
if (inputString.indexOf("ERROR") != -1 ) {
delay(1000);
caso=7;
Post();
}
inputString = "";
stringComplete = false;
}
}
void Post() {
switch (caso) {
case 1:
Serial.println ("AT");
break;
case 2:
Serial.println ("AT+CREG?");
break;
case 3:
Serial.println ("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
break;
case 4:
Serial.println ("AT+SAPBR=3,1,\"APN\",\"tel.hitsmobile.es\"");
break;
case 5:
Serial.println ("AT+SAPBR=2,1");
break;
case 6:
Serial.println ("AT+SAPBR=1,1");
break;
case 7:
Serial.println ("AT+HTTPINIT");
delay(3000);
break;
case 8:
Serial.println ("AT+HTTPPARA=\"CID\",1");
break;
case 9:
Serial.println ("AT+HTTPPARA=\"URL\",\"...\"");
break;
case 10:
Serial.println ("AT+HTTPPARA=\"CONTENT\",\"application/x-www-form-urlencoded\"");
break;
case 11:
Serial.println ("AT+HTTPDATA=10,20000");
break;
case 12:
Serial.println ("datos=Hits");
break;
case 13:
Serial.println ("AT+HTTPSSL=1");
break;
case 14:
Serial.println ("AT+HTTPACTION=1");
break;
case 15:
Serial.println ("AT+HTTPREAD");
break;
case 16:
Serial.println ("AT+HTTPTERM");
break;
case 17:
Serial.println ("AT+SAPBR=0,1");
delay(300000);
caso=0;
}
}
/*
SerialEvent occurs whenever a new data comes in the hardware serial RX. This
routine is run between each time loop() runs, so using delay inside loop can
delay response. Multiple bytes of data may be available.
*/
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag so the main loop can
// do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}
También lo he probado con otro Arduino y este código:
// Date and time functions using a DS3231 RTC connected via I2C and Wire lib
#include "RTClib.h"
#include <Wire.h>
#include <EEPROM.h>
long A = 0;
int eeAddress = 0;
bool Inte = false;
RTC_DS3231 rtc;
void setup () {
Wire.begin();
Serial.begin(9600);
delay(30000);
pinMode(2,INPUT);
}
void loop () {
if (digitalRead(2) == HIGH and Inte == false) {
DateTime now = rtc.now();
delay(500);
A=now.unixtime();
EEPROM.put(eeAddress, A);
//EEPROM.get(eeAddress,A);
eeAddress += sizeof(long);
Serial.println(A);
Inte = true;
}
if (digitalRead(2) == LOW and Inte == true) Inte = false;
}
946728166 sáb ene 1 12:02:46 UTC 2000
946728174 sáb ene 1 12:02:54 UTC 2000
946728184 sáb ene 1 12:03:04 UTC 2000
946692566 sáb ene 1 02:09:26 UTC 2000
946692574 sáb ene 1 02:09:34 UTC 2000
946692581 sáb ene 1 02:09:41 UTC 2000
946709409 sáb ene 1 06:50:09 UTC 2000
946716563 sáb ene 1 08:49:23 UTC 2000
946716573 sáb ene 1 08:49:33 UTC 2000
946728028 sáb ene 1 12:00:28 UTC 2000
No estaba en hora el reloj, pero ocurre lo de las 2 horas, ahora lo tengo puesto en hora y activo en una habitación que no entra nadie, este modulo no es valido para alarma.
Por cierto los potenciómetros los tengo sensibilidad min y tiempo mínimo acorde a la foto adjunta, desbordara algún contador interno o algo a las 2 horas, en esa habitación tengo un router espero que no interfiera, ya probare en otro sitio
Edito: Esta noche no me lo ha hecho, ¿Alguien más ha experimentado en profundidad este modulo?