initial, copied from rgbled
This commit is contained in:
36
build.sh
Executable file
36
build.sh
Executable file
@ -0,0 +1,36 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ "$1" == "" ]; then
|
||||||
|
echo "Give one of the targets: build, clean, upload"
|
||||||
|
echo "If you want to use a project directory different"
|
||||||
|
echo "than the current directory, give it as a second"
|
||||||
|
echo "argument."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$2" != "" ]; then
|
||||||
|
PROJECT_DIR=$2
|
||||||
|
else
|
||||||
|
PROJECT_DIR=$PWD
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
if [ "$1" == "build" ]; then
|
||||||
|
pushd $PROJECT_DIR/libraries/esp8266boilerplate/ConfigGenerator && ./configGen.sh && popd
|
||||||
|
env ARDUINO_SKETCHBOOK_DIR=$PROJECT_DIR arduino-cli compile --fqbn=esp8266:esp8266:nodemcu $PROJECT_DIR/sketch
|
||||||
|
cp sketch/sketch.esp8266.esp8266.nodemcu.* .
|
||||||
|
elif [ "$1" == "clean" ]; then
|
||||||
|
for D in libraries/includes/configuration.h libraries/includes/configuration.cpp sketch/sketch.esp8266.esp8266.nodemcu.bin sketch/sketch.esp8266.esp8266.nodemcu.elf sketch.esp8266.esp8266.nodemcu.bin sketch.esp8266.esp8266.nodemcu.elf; do
|
||||||
|
echo -n "About to delete $D ... "
|
||||||
|
rm $PROJECT_DIR/$D && echo "done"
|
||||||
|
done
|
||||||
|
elif [ "$1" == "upload" ]; then
|
||||||
|
echo "About to upload to device"
|
||||||
|
esptool.py --port /dev/ttyUSB1 write_flash 0 sketch.esp8266.esp8266.nodemcu.bin
|
||||||
|
else
|
||||||
|
echo "Unknown subcommand '$1'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
47
libraries/includes/defines.h
Normal file
47
libraries/includes/defines.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* defines.h
|
||||||
|
*
|
||||||
|
* Created on: Aug 20, 2017
|
||||||
|
* Author: wn
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DEFINES_H_
|
||||||
|
#define DEFINES_H_
|
||||||
|
|
||||||
|
// #define DEBUG
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// #define WS2811
|
||||||
|
#define PL9823
|
||||||
|
|
||||||
|
#define NODEMCU
|
||||||
|
// #define ESP01
|
||||||
|
|
||||||
|
|
||||||
|
#define EEPROM_ADDR 0
|
||||||
|
|
||||||
|
#ifdef ESP01
|
||||||
|
#define CONFIG_SWITCH 0 // Arduino numbering
|
||||||
|
#endif
|
||||||
|
#ifdef NODEMCU
|
||||||
|
#define CONFIG_SWITCH D2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WS2811
|
||||||
|
#define PIXEL_PIN 1 // NODEMCU numbering
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef PL9823
|
||||||
|
#ifdef ESP01
|
||||||
|
#define PIXEL_PIN 2
|
||||||
|
#endif
|
||||||
|
#ifdef NODEMCU
|
||||||
|
#define PIXEL_PIN D1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define NUM_OF_LEDs 300
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* DEFINES_H_ */
|
8
releaseInfo.json
Normal file
8
releaseInfo.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"releaseTag": "v1.0.6",
|
||||||
|
"createReleaseTag": "true",
|
||||||
|
"releaseName": "colorPattern and watchdog",
|
||||||
|
"description": "introduce the colorPattern config option (swap R and G) and use the mqtt boilerplate code with watchdog support"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
20
sketch/ConfigDataStructure.py
Normal file
20
sketch/ConfigDataStructure.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
configItems = [
|
||||||
|
{"label":"_", "key":"magic", "type":"I", "default": ""},
|
||||||
|
{"label":"Config Username", "key":"confUser", "type":"C", "length":16, "default":"admin"},
|
||||||
|
{"label":"Config Password", "key":"confPasswd", "type":"C", "length":16, "default":"geheim123"},
|
||||||
|
{"label":"Wifi SSID", "key":"wifiSsid", "type":"C", "length":32, "default":"test"},
|
||||||
|
{"label":"Wifi Key", "key":"wifiKey", "type":"C", "length":64, "default":"geheim"},
|
||||||
|
{"label":"MQTT Broker", "key":"mqttBroker", "type":"C", "length":32, "default":"broker.hottis.de"},
|
||||||
|
{"label":"MQTT ClientId", "key":"mqttClientId", "type":"C", "length":32, "default":"RgbLed1"},
|
||||||
|
{"label":"MQTT Port", "key":"mqttPort", "type":"I", "default":1883},
|
||||||
|
{"label":"MQTT Topic Color Command", "key":"mqttTopicColorCommand", "type":"C", "length":64, "default":"IoT/RgbLed1/ColorCommand"},
|
||||||
|
{"label":"MQTT Topic Command", "key":"mqttTopicCommand", "type":"C", "length":64, "default":"IoT/RgbLed1/Command"},
|
||||||
|
{"label":"MQTT DebugTopic", "key":"mqttDebugTopic", "type":"C", "length":64, "default":"IoT/RgbLed1/Debug"},
|
||||||
|
{"label":"MQTT WatchdogTopic", "key":"mqttWatchdogTopic", "type":"C", "length":64, "default":"IoT/Watchdog"},
|
||||||
|
{"label":"Color pattern (rgb=0, grb=1", "key":"colorPattern", "type":"I", "default":0},
|
||||||
|
{"label":"DebugMode", "key":"debugMode", "type":"I", "default":0}
|
||||||
|
]
|
||||||
|
|
||||||
|
magic = 3235774471
|
||||||
|
appName = "ESP8266 based RGB-LED-Light"
|
238
sketch/application.cpp
Normal file
238
sketch/application.cpp
Normal file
@ -0,0 +1,238 @@
|
|||||||
|
/*
|
||||||
|
* productionMode.cpp
|
||||||
|
*
|
||||||
|
* Created on: Apr 05, 2019
|
||||||
|
* Author: wn
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <mqttHandling.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef WS2811
|
||||||
|
#define FASTLED_ESP8266_NODEMCU_PIN_ORDER
|
||||||
|
#include <FastLED.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef PL9823
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include "configuration.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef WS2811
|
||||||
|
CRGB leds[NUM_OF_LEDs];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef PL9823
|
||||||
|
typedef struct {
|
||||||
|
uint8_t r;
|
||||||
|
uint8_t g;
|
||||||
|
uint8_t b;
|
||||||
|
} CRGB;
|
||||||
|
|
||||||
|
|
||||||
|
// Adafruit_NeoPixel pixels(NUM_OF_LEDs, PIXEL_PIN, NEO_RGB + NEO_KHZ400);
|
||||||
|
Adafruit_NeoPixel pixels(NUM_OF_LEDs, PIXEL_PIN, NEO_RGB + NEO_KHZ800);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool show = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static CRGB evaluationColorWord(char* cmd) {
|
||||||
|
uint8_t red = 0, green = 0, blue = 0;
|
||||||
|
if ((! strcmp(cmd, "on")) || (! strcmp(cmd, "white"))) {
|
||||||
|
red = 255;
|
||||||
|
green = 255;
|
||||||
|
blue = 255;
|
||||||
|
} else if (! strcmp(cmd, "off")) {
|
||||||
|
red = 0;
|
||||||
|
green = 0;
|
||||||
|
blue = 0;
|
||||||
|
} else if (! strcmp(cmd, "warmwhite")) {
|
||||||
|
red = 0;
|
||||||
|
green = 0;
|
||||||
|
blue = 0;
|
||||||
|
} else if (! strcmp(cmd, "red")) {
|
||||||
|
red = 255;
|
||||||
|
green = 0;
|
||||||
|
blue = 0;
|
||||||
|
} else if (! strcmp(cmd, "green")) {
|
||||||
|
red = 0;
|
||||||
|
green = 255;
|
||||||
|
blue = 0;
|
||||||
|
} else if (! strcmp(cmd, "blue")) {
|
||||||
|
red = 0;
|
||||||
|
green = 0;
|
||||||
|
blue = 255;
|
||||||
|
} else if (! strcmp(cmd, "purple")) {
|
||||||
|
red = 255;
|
||||||
|
green = 0;
|
||||||
|
blue = 255;
|
||||||
|
} else if (! strcmp(cmd, "yellow")) {
|
||||||
|
red = 255;
|
||||||
|
green = 255;
|
||||||
|
blue = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
CRGB res;
|
||||||
|
res.r = red;
|
||||||
|
res.g = green;
|
||||||
|
res.b = blue;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void subscribeApplication() {
|
||||||
|
mqttClient.subscribe(configBlock.mqttTopicColorCommand);
|
||||||
|
mqttClient.subscribe(configBlock.mqttTopicCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void setColor(int16_t ledNumber, uint8_t x, uint8_t y, uint8_t z) {
|
||||||
|
uint8_t red, green, blue;
|
||||||
|
|
||||||
|
switch (configBlock.colorPattern) {
|
||||||
|
case 1:
|
||||||
|
red = y;
|
||||||
|
green = x;
|
||||||
|
blue = z;
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
default:
|
||||||
|
red = x;
|
||||||
|
green = y;
|
||||||
|
blue = z;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ledNumber == -1) {
|
||||||
|
for (uint16_t i = 0; i < NUM_OF_LEDs; i++) {
|
||||||
|
#ifdef WS2811
|
||||||
|
leds[i].r = red;
|
||||||
|
leds[i].g = green;
|
||||||
|
leds[i].b = blue;
|
||||||
|
#endif
|
||||||
|
#ifdef PL9823
|
||||||
|
pixels.setPixelColor(i, pixels.Color(red, green, blue));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
show = true;
|
||||||
|
} else {
|
||||||
|
if (ledNumber >= 0 && ledNumber < NUM_OF_LEDs) {
|
||||||
|
|
||||||
|
#ifdef WS2811
|
||||||
|
leds[ledNumber].r = red;
|
||||||
|
leds[ledNumber].g = green;
|
||||||
|
leds[ledNumber].b = blue;
|
||||||
|
#endif
|
||||||
|
#ifdef PL9823
|
||||||
|
pixels.setPixelColor(ledNumber, pixels.Color(red, green, blue));
|
||||||
|
#endif
|
||||||
|
show = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void callbackApplication(char *topic, uint8_t tokenCnt, char **tokens) {
|
||||||
|
if (! strcmp(topic, configBlock.mqttTopicCommand)) {
|
||||||
|
int32_t n, b;
|
||||||
|
CRGB pseudoColors;
|
||||||
|
switch (tokenCnt) {
|
||||||
|
case 1:
|
||||||
|
// set brightness
|
||||||
|
b = strtol(tokens[0], NULL, 10);
|
||||||
|
setColor(-1, b, b, b);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
// set brightness for one LED
|
||||||
|
n = strtol(tokens[0], NULL, 10);
|
||||||
|
b = strtol(tokens[1], NULL, 10);
|
||||||
|
setColor(n, b, b, b);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (! strcmp(topic, configBlock.mqttTopicColorCommand)) {
|
||||||
|
int32_t n, red, green, blue;
|
||||||
|
CRGB colors;
|
||||||
|
switch (tokenCnt) {
|
||||||
|
case 1:
|
||||||
|
// on, off, color word for all LEDs
|
||||||
|
colors = evaluationColorWord(tokens[0]);
|
||||||
|
setColor(-1, colors.r, colors.g, colors.b);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
// token0 = LED number, token1 = color
|
||||||
|
n = strtol(tokens[0], NULL, 10);
|
||||||
|
colors = evaluationColorWord(tokens[1]);
|
||||||
|
setColor(n, colors.r, colors.g, colors.b);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
// token0 = red, token1 = green, token2 = blue
|
||||||
|
red = strtol(tokens[0], NULL, 10);
|
||||||
|
green = strtol(tokens[1], NULL, 10);
|
||||||
|
blue = strtol(tokens[2], NULL, 10);
|
||||||
|
setColor(-1, red, green, blue);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
// token0 = LED number, token1 = red, token2 = green, token3 = blue
|
||||||
|
n = strtol(tokens[0], NULL, 10);
|
||||||
|
red = strtol(tokens[1], NULL, 10);
|
||||||
|
green = strtol(tokens[2], NULL, 10);
|
||||||
|
blue = strtol(tokens[3], NULL, 10);
|
||||||
|
setColor(n, red, green, blue);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void setupApplication() {
|
||||||
|
mqttSetup();
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef WS2811
|
||||||
|
FastLED.addLeds<NEOPIXEL, PIXEL_PIN>(leds, NUM_OF_LEDs);
|
||||||
|
#endif
|
||||||
|
#ifdef PL9823
|
||||||
|
pixels.begin();
|
||||||
|
|
||||||
|
for (uint16_t i = 0; i < NUM_OF_LEDs; i++) {
|
||||||
|
pixels.setPixelColor(i, pixels.Color(0,0,0));
|
||||||
|
}
|
||||||
|
pixels.show();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loopApplication() {
|
||||||
|
mqttLoop();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (show) {
|
||||||
|
show = false;
|
||||||
|
#ifdef WS2811
|
||||||
|
FastLED.show();
|
||||||
|
#endif
|
||||||
|
#ifdef PL9823
|
||||||
|
pixels.show();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
19
sketch/application.h
Normal file
19
sketch/application.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* productionMode.h
|
||||||
|
*
|
||||||
|
* Created on: Apr 5 2019
|
||||||
|
* Author: wn
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PRODUCTIONMODE_H_
|
||||||
|
#define PRODUCTIONMODE_H_
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void setupApplication();
|
||||||
|
void loopApplication();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* PRODUCTIONMODE_H_ */
|
22
sketch/rainsensor2.h
Normal file
22
sketch/rainsensor2.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Only modify this file to include
|
||||||
|
// - function definitions (prototypes)
|
||||||
|
// - include files
|
||||||
|
// - extern variable definitions
|
||||||
|
// In the appropriate section
|
||||||
|
|
||||||
|
#ifndef _rgbled_H_
|
||||||
|
#define _rgbled_H_
|
||||||
|
#include "Arduino.h"
|
||||||
|
//add your includes for the project rgbled here
|
||||||
|
|
||||||
|
|
||||||
|
//end of add your includes here
|
||||||
|
|
||||||
|
|
||||||
|
//add your function definitions for the project rgbled here
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Do not add code below this line
|
||||||
|
#endif /* _rgbled_H_ */
|
18
sketch/sketch.ino
Normal file
18
sketch/sketch.ino
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Do not remove the include below
|
||||||
|
#include "rainsensor2.h"
|
||||||
|
|
||||||
|
#include <main.h>
|
||||||
|
|
||||||
|
//The setup function is called once at startup of the sketch
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
// Add your initialization code here
|
||||||
|
mainSetup();
|
||||||
|
}
|
||||||
|
|
||||||
|
// The loop function is called in an endless loop
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
//Add your repeated code here
|
||||||
|
mainLoop();
|
||||||
|
}
|
Reference in New Issue
Block a user