Here is my project for the day. Problem is, that is crashes. Bigger problem is that Exception Decoder disappeared into the ether when I upgraded to IDE 1.8.8. If anyone knows how to get THAT back, I'd sure appreciate hearing from.
This code simply listens for UDP packets and more or less presents them to serial monitor. It performs a web request here and there, it flashes the built-in LED, but it's not like it's being hit with 200kbits/sec of packets. I'm talking about 4 bytes/sec... that's it. They are four digit codes that correspond to a certain event.
But, after a few minutes the thing crashes,Does anything stand out as a problem?
I can paste in the stack dump if it helps. Can't in the same message though.
/*
Node9
Will control BI!
Arming on magnet break
Disarming on keyin
*/
int x;
int biProfile, biLock;
int parseNow, state, state2;
long unsigned keyinMS;
#include <Arduino.h>
#include <ESP8266WiFi.h>
//#include <ESP8266WiFiMulti.h>
#include <WiFiUdp.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
const char* ssid = "JMR";
const char* password = "";
IPAddress ip(192, 168, 1, 139);
IPAddress ipTarget(192, 168, 1, 137);
//unsigned int localPort = 8888; // local port to listen on
// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char ReplyBuffer[] = "acknowledged"; // a string to send back
// An EthernetUDP instance to let us send and receive packets over UDP
WiFiUDP Udp;
WiFiClient client;
HTTPClient http;
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(2, OUTPUT);
Serial.println("Node9 Starting...");
// start the Ethernet and UDP:
WiFi.mode(WIFI_STA);
IPAddress ip(192, 168, 1, 139);
IPAddress gw(192, 168, 1, 254);
IPAddress dns(192, 168, 1, 254);
IPAddress sn(255, 255, 255, 0);
WiFi.config(ip, gw, sn, dns);
WiFi.begin(ssid, password);
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Node9: Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
x = Udp.begin(8888);
if (x == 0) {
Serial.println("Udp.begin: Errror - No sockets availible");
}
}
void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize) {
IPAddress remote = Udp.remoteIP();
// read the packet into packetBufffer
Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
//Serial.println("Contents:");
if ((packetSize == 5) || (packetSize == 4)) {
if ((atoi(packetBuffer) != 7102) && (atoi(packetBuffer) != 7105)) {
if (state % 2 == 0) {
digitalWrite(LED_BUILTIN, HIGH);
}
else {
digitalWrite(LED_BUILTIN, LOW);
}
state++;
}
if ((atoi(packetBuffer) == 7102) || (atoi(packetBuffer) == 7105)) {
if (state2 % 2 == 0) {
digitalWrite(2, HIGH);
}
else {
digitalWrite(2, LOW);
}
state2++;
}
parsePacket2(packetBuffer);
}
if (packetSize < 4) {
sendUDP("9999"); //PAcket fragment gets 9999'd to retransmit
}
}
delay(10);
}
void getProfile() {
String biLockS, biProfileS;
char payloadC[45] = { 0 };
http.begin(client, "http://@192.168.1.71:15080/admin?signal=1");
int httpCode = http.GET();
String payload = http.getString();
payload.toCharArray(payloadC, 40);
biProfile = payloadC[21];
biLock = payloadC[28];
if (biProfile == 0) {
//blueIris not responding
sendUDP("9106");
}
biProfile = biProfile - 48;
biLock = biLock - 48;
}
void sendUDP(char* udpDataOut) {
x = Udp.beginPacket(ipTarget, 8888);
if (x == 1) {
}
else {
Serial.print("beginPacket status: FAILURE ");
}
x = Udp.write(udpDataOut);
x = Udp.endPacket();
if (x == 1) {
}
else {
Serial.print("Packet Send status: FAILURE ");
}
}
void parsePacket2(char* packet) {
int echo = 0;
char packet3[4]; //Replace first digit with 7
strncpy(packet3, packet + 0, 3);
packet = strcat("7", packet3);
int packetI = atoi(packet);
char* msg;
getProfile();
switch (packetI) {
case 7101: {
msg = "Node 7B Reset"
echo = 0;
break;
}
case 7102: {
msg = "Ping from Node7A";
echo = 0;
break;
}
case 7105: {
msg = "Ping from Node7B";
echo = 0;
break;
}
case 7001: { //South Door Open
msg = "South Door Open";
echo = 1;
if (millis() - keyinMS > 10123) { //If door opens without key-in in last ten seconds, arm
//Profile 6
http.begin(client, "http://@192.168.1.71:15080/admin?profile=6");
http.GET();
http.end();
//Trigger c158 > Alarm
http.begin(client, "http://@192.168.1.71:15080/admin?camera=c158&trigger");
http.GET();
http.end();
}
//Trigger c158 > Alarm
http.begin(client, "http://@192.168.1.71:15080/admin?camera=c158&trigger");
http.GET();
http.end();
//Trigger c155
http.begin(client, "http://@192.168.1.71:15080/admin?camera=c155&trigger");
int httpCode = http.GET();
http.end();
break;
}
case 7004: { //Magnet Break - Immediate ARM/Trigger BI system.
msg = "Magnet Break!";
echo = 1;
http.begin(client, "http://@192.168.1.71:15080/admin?profile=6");
http.GET();
http.end();
//Trigger c158 > Alarm
http.begin(client, "http://@192.168.1.71:15080/admin?camera=c158&trigger");
int httpCode = http.GET();
http.end();
break;
}
case 7003: //Door Ajar
keyinMS = millis(); //Reset key-in so doesn't alarm
msg = "Door Ajar";
echo = 1;
break;
case 7017: // Pex pressed, flow into Key-in
case 7018: { //Key-in will disarm BI system.
keyinMS = millis();
msg = "Key-in";
if (biProfile == 6) { //dis-arm if armed, otherwise don't do anything.
http.begin(client, "http://@192.168.1.71:15080/admin?profile=7");
int httpCode = http.GET();
}
break;
}
case 7021: { //PIR Motion
msg = "Kitchen Motion";
echo = 1;
http.begin(client, "http://@192.168.1.71:15080/admin?camera=c155&trigger");
http.GET();
http.end();
break;
}
case 7095: //Camera c158 Motion Reed Out
msg = "c158 Motion";
echo = 1;
if (biProfile == 6) {
sendUDP("9107");
}
break;
}
if (echo == 1) { Serial.println(msg); }
}