Hi all,
I’ve been working on this project for the past few weeks (https://learn.adafruit.com/smart-bathroom-app/hardware) and the original developer set it up to post the status of a bathroom door to a web app. I’ve copied everything directly to the T but I’m unable to get the web app working properly. I’ve added in my own device’s ID and access code but I’m still running into issues.
Anyone familiar with publishing one of the known variables to a web app? In all honesty, I just need a page to be red or green depending on one of the variables.
Here is my code:
// This #include statement was automatically added by the Particle IDE.
#include "neopixel/neopixel.h"
#define PIN 9
#define PIXEL_PIN D2
#define PIXEL_COUNT 12
#define PIXEL_TYPE WS2812B
int analogPin = A0;
int val;
int bathStatus;
int reedSense;
bool isClosed;
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
Particle.variable("bathStatus", &bathStatus, INT);
Particle.variable("reedSense", &reedSense, INT);
}
void loop() {
val = digitalRead(analogPin);
reedSense = val;
if (bathStatus = 1) {
if (!isClosed) {
Particle.publish("door-closed");
isClosed = true;
}
} else {
if (isClosed) {
Particle.publish("door-open");
isClosed = false;
}
}
if (val >= 1) {
bathStatus = 1;
cantpoop();
} else {
bathStatus = 0;
canpoop();
}
}
void canpoop() {
colorWipe(strip.Color(0, 255, 0), 50); // Green
strip.show();
}
void cantpoop() {
colorWipe(strip.Color(255, 0, 0), 50); // Red
strip.show();
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
Thanks all!
Josh