1 Code base, many Xenons

@picsil Good questions - Thanks a bunch for helping. The first thing that jumped out was about use of strings… I create devname as char, based on @ScruffR here learning to get the device name. Was trying to set up webhooks to check batt voltage and as step 1 in logging motion locations. I change devname to string only because in my limited experience and habit, that’s what I had learned to do (I forget what example).

Devname and devLocID - retrieve and use the device name from the cloud to set devLocID. devLocID is in code so I know the event (Motion) and which sensor (devLocID) spread across a couple acres. I was hoping that I could use one codebase that could work on all sensors, and just determine which one the code is running on. Right now, it’s just testing 5 sensors in Zone 1, so numbered devLocID 11 - 15. Zone 2 will be 21 - 25, etc.

I’m using thingspeak.com to learn webhooks and see results for now. Eventually, I want to send a text with this info and more, as well as log the monitor voltage, when motion occurs and by which of 15-20 xenons are tripped.

Below is the full code. It has a lot of other garbage in it as it’s my first attempt at many things, had stuff added/moved as it grew. So it’s ugly, but it’s current state. Sleep/battery management, etc. are future needs. For now, I want to see how long a battery might last, and track the sensor tripped.

// Zone1 01 Motion

int led1 = D0;
int led2 = D7;
int motion = D1;
int n = 0;
int old_time = 0;
String MyID = System.deviceID();
String MotionName = "Starter";
char devname[32] = "";
bool publishName = false;

// DeviceName Handler
void devnameHandler(const char *devn, const char *data) {
    strncpy(devname,data,sizeof(devname)-1);
    publishName = true;
}

void setup() {
    pinMode(D0, OUTPUT);
    pinMode(D1, INPUT);
    // function from other project:
    Particle.function("led",ledToggle);
    digitalWrite(led2, LOW);
    Particle.function("chkVolt",checkvolt);
    // Get DeviceName for standardized code
    Particle.subscribe("particle/device/name", devnameHandler);
    Particle.publish("particle/device/name");
}

void loop() {
    if (millis() - old_time > 900000) {
        float voltage = analogRead(BATT) * 0.0011224;
        Particle.publish("voltage", String(voltage), PRIVATE);
        old_time = millis();
    }
    if (digitalRead(D1) == HIGH) {
        if (String(devname) == "Zone01-01") {
            String devLocID = "11";
        }
        else if (String(devname) == "Zone01-02") {
            String devLocID = "12";
        }
        else if (String(devname) == "Zone01-03") {
            String devLocID = "13";
        }
        else if (String(devname) == "Zone01-04") {
            String devLocID = "14";
        }
        else if (String(devname) == "Zone01-05") {
            String devLocID = "15";
        }
        Particle.publish("Motion", "11", PRIVATE);
        digitalWrite(led1,HIGH);
        while (digitalRead(D1) == HIGH); // hang tight here until motion stops
        digitalWrite(led1,LOW);
    }
    else {
        MotionName = 'Unknown';
    }
}

int checkvolt(String voltreport) {
    if (voltreport == "report") {
        float voltage = analogRead(BATT) * 0.0011224;
        Particle.publish("voltage", String(voltage), PRIVATE);
        
    }
}

Hope I actually answered the main questions.