complicado con un codigo, opte por usar este para probar el telegram con el modulo, se conecta al router, ya que si ingreso al router me lo muestra conectado y su correspondiente ip, el problema es que no solo este sketch, sino los de ejemplo, no funcionan, universal telegram bot, cbot, por ese motivo sigo con el telegrambot.h , una y otra vez, los numeros de twiter y telegram, los revise varias veces, ademas de telegram cree tres bot y ninguno recibe ni envia, desde celular ni netbook.
esto devuelve el puerto serial cada 5 segundos mas o menos
Exception (3):
epc1=0x401006ed epc2=0x00000000 epc3=0x00000000 excvaddr=0x40011688 depc=0x00000000
>>>stack>>>
ctx: cont
sp: 3fff0060 end: 3fff0330 offset: 01a0
3fff0200: 3ffe895c 00000000 000a0d78 3ffeee8c
3fff0210: 3ffeeabc 00000000 00000020 40100997
3fff0220: 000005a0 800000b4 3fff2600 005b005f
3fff0230: 80ffdad0 00000019 3fff02c4 4020ced6
3fff0240: 3fff02a0 00000000 3fff02a0 4020ceec
3fff0250: 3fffdad0 40261c24 3fff0280 40201151
3fff0260: 3fffdad0 00000000 3ffeeabc 40201419
3fff0270: 3fffdad0 00000000 3ffeed4c 40201130
3fff0280: 00000000 00000000 3ffe895d 00000000
3fff0290: feefef00 feefeffe 80efeffe feefef00
3fff02a0: feefeffe 80efeffe 00000000 00007530
3fff02b0: 00000000 40211688 00000000 40211688
3fff02c0: 00000000 40211688 00000000 40211688
3fff02d0: 00000000 40211688 00000000 40211688
3fff02e0: 00000000 00000000 ffffffff fe000001
3fff02f0: 3ffe88c1 00000000 fe01ef35 40201048
3fff0300: 40201020 0000000a 3fff0a34 3ffeee8c
3fff0310: 3fffdad0 00000000 3ffeee4c 4020e1b4
3fff0320: feefeffe feefeffe 3ffe8534 40100c59
<<<stack<<<
ets Jan 8 2013,rst cause:4, boot mode:(3,6)
wdt reset
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
vbc204a9b
~ld
*WM:
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Using last saved values, should be faster
*WM: Waiting for connection result with time out
*WM: Connection result:
*WM: 3
*WM: IP Address:
*WM: 192.168.0.103
*WM:
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Using last saved values, should be faster
*WM: Waiting for connection result with time out
*WM: Connection result:
*WM: 3
*WM: IP Address:
*WM: 192.168.0.103
Conectado de forma a la red WiFi
*WM: freeing allocated params!
el codigo que descarge es este
#include <ESP8266WiFi.h>
#include <Twitter.h>
#include <DNSServer.h> //Servidor DNS local para redireccionar peticiones al portal de configuración
#include <ESP8266WebServer.h> //Webserver local para el portal de configuración
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager WiFi Configuration Magic
#include <SPI.h>
#include <TelegramBot.h>
byte sensorPin = 2; // Pin para el sensor de movimiento
byte movimiento = 0; // Variable para activar alarma
byte sinmovimiento = 0; // Resetea el contador a 0 cuando no hay movimiento durante un tiempo
long Numerorandom; // Número ramdom para enviar por Twitter
char msg[140]; // Mensaje para Twitter
Twitter twitter("MI BOTTOKENse;
const char* BotToken = "EL TOKEN DE TELEGRAM"; // Token de Telegram se obtiene configurando el Bot
WiFiClientSecure client;
TelegramBot bot(BotToken,client);
void configModeCallback (WiFiManager *myWiFiManager) {
Serial.println("Accediendo al Modo de Configuración");
Serial.println(WiFi.softAPIP());
//if you used auto generated SSID, print it
Serial.println(myWiFiManager->getConfigPortalSSID());
}
//flag para guardar datos
bool shouldSaveConfig = false;
//callback para guardar datos
void saveConfigCallback () {
Serial.println("Should save config");
shouldSaveConfig = true;
}
void setup()
{
Serial.begin(115200);
delay(10);
pinMode(sensorPin,INPUT);
WiFiManager wifiManager;
wifiManager.setAPCallback(configModeCallback); //Cuando la conexión al WiFi falla, se entra en el modo AP
wifiManager.setConnectTimeout(30); // Se da un tiempo de 30 segundos para iniciar la conexion a la red WiFi
wifiManager.autoConnect("Alarma-esp8266-01"); // Nombre de la red WiFi creada por la ESP8266-01
// Se intenta una autoconexión y si falla se espera por una configuración
if(!wifiManager.autoConnect()) {
Serial.println("failed to connect and hit timeout");
//reset and try again, or maybe put it to deep sleep
ESP.reset();
delay(1000);
}
// Conexión a la red wifi exitosa
Serial.println("Conectado de forma a la red WiFi");
//set config save notify callback
wifiManager.setSaveConfigCallback(saveConfigCallback);
}
void loop()
{
message m = bot.getUpdates(); // A la espera de nuevos mensajes de Telegram
// Si el mensaje es Alarma on se activa la alarma, es sensible a mayúsculas
if (m.text.equals("Alarmaon"))
{
Serial.println("Mensaje recibido se activa la alarma");
bot.sendMessage(m.chat_id, "La Alarma está preparada y lista.");
movimiento = 0;
repiteloop = false;
while (!repiteloop)
{
byte state = digitalRead(sensorPin);
if(state == 1) {
Serial.println("Se ha detectado movimiento!");
delay(50);
movimiento++;
Serial.println(movimiento);
}
else if (state == 0) {
delay(10);
sinmovimiento++;
Serial.println("Sin movimiento!");
}
// Se resetea el contador de movimientos si no hay movimiento continuo
if (sinmovimiento == 10) {
sinmovimiento = 0;
movimiento = 0;
}
// Se activa la alarma y se envía el mensaje a Telegram
if (movimiento == 3)
{
bot.sendMessage(m.chat_id, "Alarma activada por movimiento!!"); //Mensaje de alerta Telegram
// Envía el Tweet junto a un número random para que los tweets sean diferentes
// Si son siempre iguales Twitter los bloquea
Numerorandom = random(101,1565);
Serial.println(Numerorandom);
sprintf(msg, "Alarma activada!: %d.", Numerorandom);
Serial.println(msg);
Serial.println("Conectando a Twitter…");
if (twitter.post(msg)) {
int status = twitter.wait(&Serial);
if (status == 200) {
Serial.println("200 OK");
delay(60001); // Si el mensaje se envía se espera 1 minuto para evitar spam en arduino-tweet.appspot.com
}
else {
Serial.print("Error : code ");
Serial.println(status);
}
} else {
Serial.println("Fallo en la conexión.");
}
movimiento = 0; // Variable de movimientos vuelve a cero
}
message m = bot.getUpdates(); // Leer nuevos mensajes de Telegram
if (m.text.equals("Alarmaoff"))
{
repiteloop = true;
Serial.println("Mensaje recibido, se apaga la alarma.");
bot.sendMessage(m.chat_id, "La Alarma está desactivada.");
}
}
}
else if (m.text.equals("Alarmaoff"))
{
Serial.println("Mensaje recibido, se apaga la alarma.");
bot.sendMessage(m.chat_id, "La Alarma está desactivada.");
repiteloop = false;
}
} // fin loop