I'm very tired.... this code finally compiled and the serial window is empty except for when I press reset. I went to a blank slate with just Serial.begin and it worked, same for clearing out most of the functions.... no crash messages either.
Well, EDIT - I did notice my refs to pins were GPIO not D0 style, that can't be the cause though...
#define NODE_NUMBER 5 //This is Node ID
#define UDP_TX_PACKET_MAX_SIZE 32
#define UDP_TIMEOUT 800
#define WiFI_Conn_Timeout 4000
#define AP_PASSWORD NOT FOR YOUR EYES
#define SSIDn "JMR"
#define VIBRATION_THRESHOLD 5
#ifdef ESP32
#define BOARD_TYPE "ESP32"
#define NO_OF_LEDS 1
#define LED1 5
#define LED2 5
#define BOARD_NO 1
#endif
#ifdef ESP8266
#define BOARD_NO 2
#define BOARD_TYPE "ESP8266"
#define NO_OF_LEDS 2
#define LED1 2
#define LED2 LED_BUILTIN
#endif
#ifdef ARDUINO_AVR_UNO
#define BOARD_NO 3
#define BOARD_TYPE "UNO"
#define NO_OF_LEDS 1
#define LED1 LED_BUILTIN
#define LED2 LED_BUILTIN
#endif
// ** Node 5 ***
//*****PIN-MAP for Node5 ESP12E ************************************************************************************************************************************************************
int dr5 = 0, bo5 = 1, pr5 = 2, vb5 = 3, vbp = 4;
int installed[21] = { -1, -1, 1, 1, 2 };
char *ssNames[21] = { "dr5", "bo5", "pr5", "vb5", "vbp" };
// *****************************************************************************************************************************************************************
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
int node = NODE_NUMBER;
char *ssid;
int debugOn;
int code, i, x;
long delayMS = 100;
int iNow[30], iWas[30];
String msgPtr;
long unsigned last[30];
char packetBuffer[32], packetCode[5], packet[32];
int deBounceMS = 25;
int pinNumbers[21] = { D0, D1, D2, D3, D4, D5, 6, 7, 8, 9, 10 }; //D port numbers, NOT GPIO
const byte numChars = 8;
char *nodeName = "North Door (Davidson)";
char codeChar[numChars];
int arrMax = 20;
//OBJ NSTANTIOANTIONS
WiFiUDP Udp;
//Function Declarations
void setup();
void loop();
int udpRead();
int UDPsend(int, int);
int UDPsend(char*, int);
int sendUDP(int, int);
int sendUDP(char*, int);
int udpInit();
int wifiInit(int);
void setup() {
//start standardizing functions for nodes
Serial.begin(115200);
wifiInit(node);
//httpDInit(); //Start the HTTPD for OTA updates - not sure if WebServer works on ESP8266
udpInit();
pinMode(dr5, INPUT_PULLUP);
pinMode(bo5, INPUT_PULLUP);
pinMode(vb5, INPUT);
pinMode(vbp, OUTPUT);
pinMode(pr5, INPUT);
String strMsg = String("Node ") + String(NODE_NUMBER) + String(" Started");
Serial.println(strMsg);
Serial.println(5099); //This init code will change
}
void loop() {
for (i = 0; i < arrMax + 0; i++) {
int x = pinChange(i); //pinChange handes iNow vs iWas comparison, debounce
if (abs(x) == 1) {
//state change!
inParse(ssNames[i], x);
}
//no change
}
next:
int x = udpRead(); //udpRead() returns length of read string
if (x > 2) {
}
long unsigned endMS = millis() + delayMS;
while (millis() < endMS) {
}
}
int inParse(String target, int dirc) {
static int vibrationCount;
if (target == "dr5") {
if (dirc == 1) {
Serial.println(5001);
} //Door opens HIGH
if (dirc == -1) {
Serial.println(5002);
} //door closes LOW
}
if (target == "bo5") {
//bolt locks (Reed sensor is on the UNLOCK side, thus unlock == LOW)
if (dirc == 1) {
Serial.println(5009); //bolt locks
}
if (dirc == -1) {
Serial.println(5010); // bolt unlocks
}
}
if (target == "pr5") {
if (dirc == 1) {
Serial.println(5021); //PIR goes active (high)
}
if (target == "vb5") {
//Vibration sensor is shaking
if (dirc == 1) Serial.println("Vibration Sensor open"); //debug
if (dirc == -1) Serial.println("Vibration Sensor CLOSED");
//send code, reset count, set timer
if (vibrationCount > VIBRATION_THRESHOLD) {
Serial.println(5062);
}
} //vb5 (a little more complex) when this goes low only for a breif moment send a packet, but don't send a bunch in a row!
}
}
int pinChange(int i) {
int iDelta, iW;
if (abs(installed[i]) == 1) { //If input (-1 or 1)
iNow[i] = digitalRead(pinNumbers[i]);
if (iNow[i] == iWas[i]) { //No state change
return 0;
}
if ((millis() - last[i]) < deBounceMS) { //DeBounce: Exit if changed but not long enough
return 0;
}
last[i] = millis(); //If past this point, state has CHANGED
} //end if input
if (iWas[i] == 0) iDelta = 1;
if (iWas[i] == 1) iDelta = -1;
return iDelta;
}
int wifiInit(int node) {
//Change, must call with ipD argument
int ipD;
char filler1[16], filler2[16];
char *password = &filler1[0];
char * ssid = &filler2[0];
ssid = SSIDn;
password = AP_PASSWORD;
ssid = "JMR";
ipD = 130 + node;
if ((node < 0) || (node > 10)) {
return 54502; //bad node # argument }
if (strlen(password) < 2) {
return 54503;
}
WiFi.mode(WIFI_STA);
IPAddress ip(192, 168, 1, ipD);
IPAddress gw(192, 168, 1, 254);
IPAddress dns(192, 168, 1, 254);
IPAddress sn(255, 255, 255, 0);
WiFi.config(ip, gw, sn, dns);
int x = WiFi.begin(ssid, password); //x is status only, no value to return!
// Wait for connection
long dMS = millis();
while (WiFi.status() != WL_CONNECTED) {
if (WiFi.status() == WL_NO_SHIELD) return 54504;
if (WiFi.status() == WL_NO_SSID_AVAIL) return 54505;
if (WiFi.status() == WL_CONNECT_FAILED) return 54506;
if (WiFi.status() == WL_CONNECTION_LOST) return 54507;
if (WiFi.status() == WL_DISCONNECTED) return 54508;
delay(500);
Serial.print(".");
if (millis() - dMS > WiFI_Conn_Timeout) {
return 54509;
}
String spr = String("Node") + String(node) + String(" (") + String(nodeName) + String(") connected to ");
Serial.print("Node ");
Serial.print(node);
Serial.print(" (");
Serial.print(nodeName);
Serial.print("connected to: ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
} //end if connected
return 24510;
}
}
int udpInit() {
int x = Udp.begin(8888);
if (x < 1) {
return 54410;
}
}
int udpBegin() {
return udpInit();
}
TRUNCATED...
}