@mfalkvidd No. I'm controling a ledstrip with ws2812b led's. The radio is powered from one of those small adapterboards with integrated regulator and capacitor. All driven from a 15W 5V switchmode powersupply.
It seems that Domoticz is expecting a reply from the node with the same status as the command. Every time it works there is a reply from the node. And when I get the error Idont get that reply. I have not programmed in any replyprocedures in the sketch, so when it works it must be the library that send that reply from the node. But if thats the case, why not every time.
I tried to modify the sketch to count any failed transmission and send that value back to the gateway to see if I have problems with the transmission. But the value is still Zero. Maybe my sketch is coded wrong but I dont think so.
And even when domoticz says it failed the node still executes what was ordered.
So the problem I think lies in the fact that domoticz seems to be waiting for an answer back with the new status from the node. The node send that status sometimes but more often not.
This is the sketch:
#define MY_RADIO_NRF24
#define MY_NODE_ID 200
#define MY_REPEATER_FEATURE
//#define MY_DEBUG
#include <MySensors.h>
#include <SPI.h>
#include "FastLED.h"
#include <OneWire.h>
#include <avr/pgmspace.h>
#define DATA_PIN 2
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define NUM_LEDS 232
#define BRIGHTNESS 96
CRGB leds[NUM_LEDS];
char actRGBvalue[] = "FFFFFF"; // Current RGB value
uint16_t actRGBbrightness = 0xFF ; // Controller Brightness
int actRGBonoff = 0; // OnOff flag
MyMessage msg(1, V_RGB);
MyMessage msgtemp(2, V_TEMP);
MyMessage msgcputemp(3, V_TEMP);
MyMessage msgcpuvolt(4, V_VOLTAGE);
MyMessage msgfailcount(5, V_VAR1);
void SendColor2AllLEDs(const CRGB lcolor)
{
for (int i = 0 ; i < NUM_LEDS ; i++) {
leds[i] = lcolor;
}
}
OneWire ds(8);
void setup() {
wait(3000); // 3 second delay for recovery
pinMode(7, OUTPUT);
digitalWrite(7, HIGH);
// tell FastLED about the LED strip configuration
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
//FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
// set master brightness control
FastLED.setBrightness(BRIGHTNESS);
SendColor2AllLEDs(strtol(actRGBvalue, NULL, 16));
}
void presentation()
{
present(1, S_RGB_LIGHT, "200 RGB Led");
wait(1000);
present(2, S_TEMP, "200 Temperatur altan");
wait(1000);
present(3, S_TEMP, "200 Temperatur CPU");
wait(1000);
present(4, S_MULTIMETER, "200 Spänning CPU");
wait(1000);
present(5, S_CUSTOM, "200 Failcount");
wait(1000);
sendSketchInfo("Nod 200 - Altan", "V1.6");
wait(1000);
}
unsigned int fail;
void loop()
{
if(!send(msgtemp.set(getTemp(), 2)))
{
fail++;
}
wait(1000);
if(!send(msgcputemp.set(GetTempCpu(),2)))
{
fail++;
}
wait(1000);
if(!send(msgcpuvolt.set(readVcc(),3)))
{
fail++;
}
wait(30000);
send(msgfailcount.set(fail));
wait(1000);
}
void receive(const MyMessage &message)
{
if (message.type == V_RGB) {
strcpy(actRGBvalue, message.getString()); // get the payload
SendColor2AllLEDs(strtol(actRGBvalue, NULL, 16));
Serial.println(F("RGB"));
Serial.println(actRGBvalue);
}
else if (message.type == V_DIMMER) {
actRGBbrightness = message.getByte();
FastLED.setBrightness( actRGBbrightness );
FastLED.show();
Serial.println(F("DIMMER"));
Serial.println(actRGBbrightness);
}
else if (message.type == V_STATUS) { // if on/off type, toggle brightness
actRGBonoff = message.getInt();
FastLED.setBrightness((actRGBonoff == 1) ? actRGBbrightness : 0);
FastLED.show();
Serial.println(F("STATUS"));
Serial.println(actRGBonoff);
}
// FastLED.show();
}
float getTemp() {
//returns the temperature from one DS18S20 in DEG Celsius
byte data[12];
byte addr[8];
if ( !ds.search(addr)) {
//no more sensors on chain, reset search
ds.reset_search();
return -1000;
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println(PSTR("CRC is not valid!"));
return -1000;
}
if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print(PSTR("Device is not recognized"));
return -1000;
}
ds.reset();
ds.select(addr);
ds.write(0x44, 1); // start conversion, with parasite power on at the end
byte present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for (int i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}
ds.reset_search();
byte MSB = data[1];
byte LSB = data[0];
float tempRead = ((MSB << 8) | LSB); //using two's compliment
float TemperatureSum = tempRead / 16;
return TemperatureSum;
}
double GetTempCpu(void)
{
unsigned int wADC;
double t;
// The internal temperature has to be used
// with the internal reference of 1.1V.
// Channel 8 can not be selected with
// the analogRead function yet.
// Set the internal reference and mux.
ADMUX = (_BV(REFS1) | _BV(REFS0) | _BV(MUX3));
ADCSRA |= _BV(ADEN); // enable the ADC
wait(20); // wait for voltages to become stable.
ADCSRA |= _BV(ADSC); // Start the ADC
// Detect end-of-conversion
while (bit_is_set(ADCSRA,ADSC));
// Reading register "ADCW" takes care of how to read ADCL and ADCH.
wADC = ADCW;
// The offset of 324.31 could be wrong. It is just an indication.
t = (wADC - 324.31 ) / 1.22;
// The returned temperature is in degrees Celsius.
return (t);
}
float readVcc() {
// Read 1.1V reference against AVcc
// set the reference to Vcc and the measurement to the internal 1.1V reference
#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
ADMUX = _BV(MUX5) | _BV(MUX0);
#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
ADMUX = _BV(MUX3) | _BV(MUX2);
#else
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#endif
wait(20); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Start conversion
while (bit_is_set(ADCSRA,ADSC)); // measuring
uint8_t low = ADCL; // must read ADCL first - it then locks ADCH
uint8_t high = ADCH; // unlocks both
float result = (high<<8) | low;
result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
result=result/1000;
return result; // Vcc in millivolts
}