
I was really happy that I made a sketch with “wires” and that this is working with two (or more) mode’s. I have a little bit of programing experience.
I will see if I can figure out what is: 4 V_LIGHT
Moderator: leecollings
Code: Select all
/json.htm?type=command¶m=switchlight&idx=50&switchcmd=Off
I am using AWI and Gimoz example on 1.5.1 and it is working fine.Ritmeester wrote:I’m trying to get the sketch from gizmocuz to work with MySensors 2.0. I have made the necessary conversion from MySensors 1.5 to 2.0. It compiles without errors.
If I run the sketch the “SendColor2AllLEDs” works. And then it stops because I don’t get any information from Domoticz to this Node. So, Domoticz is not sending commands, or it is not receiving commands.
Maybe (pretty possible) that I have overlooked something but I don’t know what.
Sketch:
Code: Select all
// PROJECT: MySensors / RGB test for Light & Sensor // PROGRAMMER: AWI/GizMoCuz // DATE: september 27, 2015/ last update: October 10, 2015 // LAST UPDATE: August 16, 2016 by Ritmeester // FILE: AWI_RGB.ino // LICENSE: Public domain // Hardware: Nano and MySensors 2.0 // Special: // uses Fastled library with NeoPixel (great & fast RBG/HSV universal library) https://github.com/FastLED/FastLED // Remarks: // Fixed node-id // Added option to request/apply last light state from gateway // Domoticz typicals - 2015 10 10: // - Domoticz is using HUE values internally, there might be a slight difference then using direct RGB colors. // Enable debug prints to serial monitor // #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 // Enable repeater functionality for this node #define MY_REPEATER_FEATURE #include <MySensors.h> #include <SPI.h> #include <FastLED.h> #define LED_PIN 4 // Pin to connect WS2812B (strip) #define NUM_LEDS 10 #define COLOR_ORDER GRB // It's GRB for WS2812B #define LED_TYPE WS2812B // What kind of strip are you using (APA102, WS2801 or WS@2812B #define NODE_ID 254 // fixed MySensors node id #define CHILD_ID 0 // Child Id's CRGB leds[NUM_LEDS]; char actRGBvalue[] = "000000"; // Current RGB value uint16_t actRGBbrightness = 0xFF ; // Controller Brightness int actRGBonoff = 0; // OnOff flag MyMessage lastColorStatusMsg(CHILD_ID, V_VAR1); void presentation() { sendSketchInfo("AWI RGB Light", "1.1"); present(CHILD_ID, S_RGB_LIGHT); // present to controller } void setup() { LEDS.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS); // Use this for WS2812B - initialize led strip // Flash the "hello" color sequence: R, G, B, black. colorBars(); //Request the last stored colors settings request(CHILD_ID, V_VAR1); } void receive(const MyMessage &message) { } void loop() { } void colorBars() { SendColor2AllLEDs( CRGB::Red ); FastLED.show(); delay(500); SendColor2AllLEDs( CRGB::Green ); FastLED.show(); delay(500); SendColor2AllLEDs( CRGB::Blue ); FastLED.show(); delay(500); SendColor2AllLEDs( CRGB::Black ); FastLED.show(); delay(500); } void SendColor2AllLEDs(const CRGB lcolor) { for (int i = 0 ; i < NUM_LEDS ; i++) { leds[i] = lcolor; } } void SendLastColorStatus() { String cStatus = actRGBvalue + String("&") + String(actRGBbrightness) + String("&") + String(actRGBonoff); send(lastColorStatusMsg.set(cStatus.c_str())); } String getValue(String data, char separator, int index) { int found = 0; int strIndex[] = {0, -1}; int maxIndex = data.length() - 1; for (int i = 0; i <= maxIndex && found <= index; i++) { if (data.charAt(i) == separator || i == maxIndex) { found++; strIndex[0] = strIndex[1] + 1; strIndex[1] = (i == maxIndex) ? i + 1 : i; } } return found > index ? data.substring(strIndex[0], strIndex[1]) : ""; } void incomingMessage(const MyMessage &message) { if (message.type == V_RGB) { // check for RGB type actRGBonoff = 1; strcpy(actRGBvalue, message.getString()); // get the payload SendColor2AllLEDs(strtol(actRGBvalue, NULL, 16)); SendLastColorStatus(); } else if (message.type == V_DIMMER) { // if DIMMER type, adjust brightness actRGBonoff = 1; actRGBbrightness = map(message.getLong(), 0, 100, 0, 255); FastLED.setBrightness( actRGBbrightness ); SendLastColorStatus(); } else if (message.type == V_STATUS) { // if on/off type, toggle brightness actRGBonoff = message.getInt(); FastLED.setBrightness((actRGBonoff == 1) ? actRGBbrightness : 0); SendLastColorStatus(); } else if (message.type == V_VAR1) { // color status String szMessage = message.getString(); strcpy(actRGBvalue, getValue(szMessage, '&', 0).c_str()); actRGBbrightness = atoi(getValue(szMessage, '&', 1).c_str()); actRGBonoff = atoi(getValue(szMessage, '&', 2).c_str()); SendColor2AllLEDs(strtol(actRGBvalue, NULL, 16)); FastLED.setBrightness((actRGBonoff == 1) ? actRGBbrightness : 0); } FastLED.show(); }
Nope. It will process automatically.I don't know how 2.x is working but don't you need gw.process( or equal) in LOOP?
Code: Select all
/*
PROJECT: MySensors / RGB test for Light & Sensor
PROGRAMMER: AWI/GizMoCuz
DATE: september 27, 2015/ last update: May 3, 2017
FILE: AWI_RGB.ino
LICENSE: Public domain
Hardware: Nano and MySensors 2.x
Special:
uses Fastled library with NeoPixel (great & fast RBG/HSV universal library) https://github.com/FastLED/FastLED
Remarks:
Fixed node-id
Added option to request/apply last light state from gateway
Converted to work on 2.x
Domoticz typicals - 2015 10 10:
- Domoticz is using HUE values internally, there might be a slight difference then using direct RGB colors.
*/
#define MY_RADIO_NRF24
#define MY_REPEATER_FEATURE
#define MY_DEBUG
#include <MySensors.h>
#include <SPI.h>
#include <FastLED.h>
const int stripPin = 4 ; // pin where 2812 LED strip is connected
const int numPixel = 25 ; // set to number of pixels
#define CHILD_ID 0 // Child id
CRGB leds[numPixel];
char actRGBvalue[] = "000000"; // Current RGB value
uint16_t actRGBbrightness = 0xFF ; // Controller Brightness
int actRGBonoff=0; // OnOff flag
MyMessage lastColorStatusMsg(CHILD_ID,V_VAR1);
void presentation()
{
sendSketchInfo("AWI RGB Light", "1.2");
present(CHILD_ID, S_RGB_LIGHT); // present to controller
}
void before() {
FastLED.addLeds<NEOPIXEL, stripPin >(leds, numPixel); // initialize led strip
// Flash the "hello" color sequence: R, G, B, black.
colorBars();
}
void setup() {
//Request the last stored colors settings
request(CHILD_ID, V_VAR1);
}
void loop() {
}
void colorBars()
{
SendColor2AllLEDs( CRGB::Red ); FastLED.show(); delay(500);
SendColor2AllLEDs( CRGB::Green ); FastLED.show(); delay(500);
SendColor2AllLEDs( CRGB::Blue ); FastLED.show(); delay(500);
SendColor2AllLEDs( CRGB::Black ); FastLED.show(); delay(500);
}
void SendColor2AllLEDs(const CRGB lcolor)
{
for(int i = 0 ; i < numPixel ; i++) {
leds[i] = lcolor;
}
}
void SendLastColorStatus()
{
String cStatus=actRGBvalue+String("&")+String(actRGBbrightness)+String("&")+String(actRGBonoff);
send(lastColorStatusMsg.set(cStatus.c_str()));
}
String getValue(String data, char separator, int index)
{
int found = 0;
int strIndex[] = {0, -1};
int maxIndex = data.length()-1;
for(int i=0; i<=maxIndex && found<=index; i++){
if(data.charAt(i)==separator || i==maxIndex){
found++;
strIndex[0] = strIndex[1]+1;
strIndex[1] = (i == maxIndex) ? i+1 : i;
}
}
return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
}
void receive(const MyMessage &message) {
if (message.type == V_RGB) { // check for RGB type
actRGBonoff=1;
strcpy(actRGBvalue, message.getString()); // get the payload
SendColor2AllLEDs(strtol(actRGBvalue, NULL, 16));
SendLastColorStatus();
}
else if (message.type == V_DIMMER) { // if DIMMER type, adjust brightness
actRGBonoff=1;
actRGBbrightness = map(message.getLong(), 0, 100, 0, 255);
FastLED.setBrightness( actRGBbrightness );
SendLastColorStatus();
}
else if (message.type == V_STATUS) { // if on/off type, toggle brightness
actRGBonoff = message.getInt();
FastLED.setBrightness((actRGBonoff == 1)?actRGBbrightness:0);
SendLastColorStatus();
}
else if (message.type==V_VAR1) { // color status
String szMessage=message.getString();
strcpy(actRGBvalue, getValue(szMessage,'&',0).c_str());
actRGBbrightness=atoi(getValue(szMessage,'&',1).c_str());
actRGBonoff=atoi(getValue(szMessage,'&',2).c_str());
SendColor2AllLEDs(strtol(actRGBvalue, NULL, 16));
FastLED.setBrightness((actRGBonoff == 1)?actRGBbrightness:0);
}
FastLED.show();
}
Code: Select all
// Modified strandtest sketch to support also RGBW strips like SK6812 based:
// http://www.szledcolor.com/download/SK6812RGBW.pdf
// Should be used with Adafruit NeoPixel version 1.0.3
// Hacked by G. Knauf 2015-12-06
Code: Select all
if (received_message.startsWith("#"))
{
color = WHITE_LED;
}
else
{
color = strtol(message.getString(), NULL, 16);
}
Users browsing this forum: No registered users and 0 guests