Initial commit

This commit is contained in:
Juergen Jung 2017-01-28 23:29:51 +01:00
commit bc45337d9d
7 changed files with 337 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
.pioenvs
.piolibdeps
.clang_complete
.gcc-flags.json

65
.travis.yml Normal file
View File

@ -0,0 +1,65 @@
# Continuous Integration (CI) is the practice, in software
# engineering, of merging all developer working copies with a shared mainline
# several times a day < http://docs.platformio.org/page/ci/index.html >
#
# Documentation:
#
# * Travis CI Embedded Builds with PlatformIO
# < https://docs.travis-ci.com/user/integration/platformio/ >
#
# * PlatformIO integration with Travis CI
# < http://docs.platformio.org/page/ci/travis.html >
#
# * User Guide for `platformio ci` command
# < http://docs.platformio.org/page/userguide/cmd_ci.html >
#
#
# Please choice one of the following templates (proposed below) and uncomment
# it (remove "# " before each line) or use own configuration according to the
# Travis CI documentation (see above).
#
#
# Template #1: General project. Test it using existing `platformio.ini`.
#
# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# install:
# - pip install -U platformio
#
# script:
# - platformio run
#
# Template #2: The project is intended to by used as a library with examples
#
# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# env:
# - PLATFORMIO_CI_SRC=path/to/test/file.c
# - PLATFORMIO_CI_SRC=examples/file.ino
# - PLATFORMIO_CI_SRC=path/to/test/directory
#
# install:
# - pip install -U platformio
#
# script:
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N

16
data/homie/config.json Normal file
View File

@ -0,0 +1,16 @@
{
"name": "Homie CTDO Schild",
"device_id": "schild2",
"wifi": {
"ssid": "Nudel",
"password": "Unser WLAN ist sicher!"
},
"mqtt": {
"host": "192.168.1.80",
"port": 1883,
"auth": false
},
"ota": {
"enabled": false
}
}

BIN
data/homie/ui_bundle.gz Normal file

Binary file not shown.

36
lib/readme.txt Normal file
View File

@ -0,0 +1,36 @@
This directory is intended for the project specific (private) libraries.
PlatformIO will compile them to static libraries and link to executable file.
The source code of each library should be placed in separate directory, like
"lib/private_lib/[here are source files]".
For example, see how can be organized `Foo` and `Bar` libraries:
|--lib
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |- readme.txt --> THIS FILE
|- platformio.ini
|--src
|- main.c
Then in `src/main.c` you should use:
#include <Foo.h>
#include <Bar.h>
// rest H/C/CPP code
PlatformIO will find your libraries automatically, configure preprocessor's
include paths and build them.
More information about PlatformIO Library Dependency Finder
- http://docs.platformio.org/page/librarymanager/ldf.html

28
platformio.ini Normal file
View File

@ -0,0 +1,28 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html
[env:d1_mini]
platform = espressif8266
board = d1_mini
framework = arduino
;upload_port = /dev/tty.wchusbserial410
;upload_speed = 921600
upload_port = schild.local
upload_flags = --auth=ctdo2342
lib_deps =
https://github.com/marvinroger/homie-esp8266.git
ArduinoJson
Bounce2
ESPAsyncTCP
AsyncMqttClient
Adafruit NeoPixel

188
src/schild.ino Normal file
View File

@ -0,0 +1,188 @@
#include <Arduino.h>
#include <Homie.h>
#include <ArduinoOTA.h>
#include <Adafruit_NeoPixel.h>
#define PIN D1
#define NUMPIXELS 30
uint16_t i=0,j=0,wait = 50;
unsigned long lastCall = 0;
byte wPos = 0;
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
HomieNode stripNode("strip", "strip");
String effect = "none";
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t wheel(byte wheelPos) {
wheelPos = 255 - wheelPos;
if(wheelPos < 85) {
return pixels.Color(255 - wheelPos * 3, 0, wheelPos * 3);
}
if(wheelPos < 170) {
wheelPos -= 85;
return pixels.Color(0, wheelPos * 3, 255 - wheelPos * 3);
}
wheelPos -= 170;
return pixels.Color(wheelPos * 3, 255 - wheelPos * 3, 0);
}
bool onSetPixel(const HomieRange& range, const String& value){
if(!range.isRange){
for(int i=0;i<pixels.numPixels();i++){
pixels.setPixelColor(i, value.toInt());
}
pixels.show();
stripNode.setProperty("pixel").send(value);
return true;
}
if (range.index < 0 || range.index > NUMPIXELS-1) {
return false;
}
effect == "none";
pixels.setPixelColor(range.index, value.toInt());
pixels.show();
stripNode.setProperty("pixel_" + String(range.index)).send(value);
}
bool onSetBrightness(const HomieRange& range, const String& value){
long brightness= value.toInt();
if (brightness < 0 || brightness > 255) {
return false;
}
pixels.setBrightness(brightness);
pixels.show();
stripNode.setProperty("brightness").send(value);
}
bool onSetEffect(const HomieRange& range, const String& value){
effect = value;
i=0,j=0,wait=50;
stripNode.setProperty("effect").send(value);
}
bool onSetClear(const HomieRange& range, const String& value){
effect = "none";
pixels.clear();
pixels.show();
stripNode.setProperty("clear").send(value);
}
void loopHandler() {
if (effect == "none"){
return;
}
else if (effect == "larson") {
int SpeedDelay = 20;
int ReturnDelay = 50;
int EyeSize = 5;
for(int i = 0; i < pixels.numPixels()-EyeSize-2; i++) {
pixels.clear();
pixels.show();
pixels.setPixelColor(i, 255/10, 0, 0);
for(int j = 1; j <= EyeSize; j++) {
//pixels.setPixelColor(i+j, 255, 0, 0);
pixels.setPixelColor(i+j, wheel(wPos++));
}
pixels.setPixelColor(i+EyeSize+1, 255/10, 0, 0);
pixels.show();
delay(SpeedDelay);
}
delay(wait);
for(int i = pixels.numPixels()-EyeSize-2; i > 0; i--) {
pixels.clear();
pixels.show();
pixels.setPixelColor(i, 255/10, 0, 0);
for(int j = 1; j <= EyeSize; j++) {
//pixels.setPixelColor(i+j, 255, 0, 0);
pixels.setPixelColor(i+j, wheel(wPos++));
}
pixels.setPixelColor(i+EyeSize+1, 255/10, 0, 0);
pixels.show();
delay(SpeedDelay);
}
delay(wait);
}
else if (effect == "randomfade") {
if(lastCall + wait > millis()){
return;
}
lastCall = millis();
for(int i=0;i<pixels.numPixels();i++){
pixels.setPixelColor(i,wheel(wPos));
}
pixels.show();
wPos++;
}
else if (effect == "rainbow") {
if(wait + lastCall >= millis()){
return;
}
if(j<256) {
if(i<pixels.numPixels()) {
pixels.setPixelColor(i, wheel((i+j) & 255));
i++;
}
else {
i=0;
j++;
}
pixels.show();
lastCall = millis();
}
else {
j=0;
}
}
else if (effect == "rainbowCycle") {
if(j<256*5) {
if(i<pixels.numPixels()) {
pixels.setPixelColor(i, wheel(((i * 256 / pixels.numPixels()) + j) & 255));
i++;
}
else {
i=0;
j++;
}
pixels.show();
lastCall = millis();
}
else {
j=0;
}
}
}
void setup() {
Serial.begin(115200);
Homie_setFirmware("schild", "1.0.0");
Homie.setLoopFunction(loopHandler);
stripNode.advertiseRange("pixel", 0, NUMPIXELS-1).settable(onSetPixel);
stripNode.advertise("brightness").settable(onSetBrightness);
stripNode.advertise("effect").settable(onSetEffect);
stripNode.advertise("clear").settable(onSetClear);
pixels.begin();
pixels.clear();
pixels.setBrightness(64);
pixels.show();
Homie.setup();
ArduinoOTA.setHostname(Homie.getConfiguration().deviceId);
ArduinoOTA.setPassword((const char *)"ctdo2342");
ArduinoOTA.begin();
}
void loop() {
Homie.loop();
ArduinoOTA.handle();
}