@raig would you sage share your sketch?
Posts made by Jan Gatzke
-
RE: New version of the MySensors adapter
@Raig I must confest I have no clue what these custom values are good for and should look like. What kind of values do you expect? Strings? Numbers?
Out of the API description for V_Custom: "Custom messages used for controller/inter node specific commands"
So it seems totally unspecified what commands or data is inside a V_Custom message.
-
RE: π¬ Sonoff relay using MySensors ESP8266 wifi or mqtt gateway
@gohan won't this option miss some features?
-
RE: π¬ Sonoff relay using MySensors ESP8266 wifi or mqtt gateway
@gohan I know some controller are aware of ESP Easy via MQTT. If you controller does not support this directly, you have to integrate it manually (with node red). In my opinion scenarios, where MySensors with ESP Easy frontend would be of use, do still exist.
-
RE: π¬ Sonoff relay using MySensors ESP8266 wifi or mqtt gateway
@dbemowsk You cannot because MQTT is just a transport and not a strict data format. You can however use MySenSors MQTT + ESP Easy MQTT + a broker + node red + a controller. Node Red can do data conversions and integrate everything.
-
RE: π¬ Sonoff relay using MySensors ESP8266 wifi or mqtt gateway
It's a shame that we cannot have both, mysensors and the ESP Easy stuff. There has been a project for this: https://github.com/letscontrolit/ESPEasyMySensors
-
New version of the MySensors adapter
I have just commited some changes to the iobroker MySensors Adapter on github. All set command are send with ack flag now and the states in iobroker get an ack on successful transmission, too. The new version is not being published via the iobroker admin, yet. You have to download it from github and copy it to your iobroker directory. Please test and report any problems you are facing.
-
RE: π¬ OH MySensors RGBW Controller
The problem with the linear fading was that a value of 100 almost looked the same as 150. So the goal was to make the fading look more linear. The logarythmic calculations needed for this cannot be done on an atmega 328p. (I tried it)
This is why I calculated the values with MS Excel and put them in an array.Making the fading process alway take the same time would be nice. Feel free to post your implementation.
-
RE: π¬ OH MySensors RGBW Controller
I am using Domoticz. This was the only way reading initial values from the controller. Directly requesting the value of a child did not work for me. Meanwhile MySensors support in Domoticz seems extremly bugy and uncomplete to me. I am going to give OpenHAB2 a try.
-
RE: π¬ OH MySensors RGBW Controller
Yes, I did! This sketch is working for me:
/** Based on the MySensors Project: http://www.mysensors.org This sketch controls a (analog)RGBW strip by listening to new color values from a (domoticz) controller and then fading to the new color. Version 1.1 - Added save/restore of values to/from controller, removed non linear fading code Version 1.0 - Changed pins and gw definition Version 0.9 - Oliver Hilsky **/ #define MY_DEBUG #define SN "RGBW 01" #define SV "1.1" #define MY_RADIO_NRF24 #define MY_PARENT_NODE_ID 10 // change the pins to free up the pwm pin for led control #define MY_RF24_CE_PIN 4 //<-- NOTE!!! changed, the default is 9 #define MY_RF24_CS_PIN 10 // default is 10 // Set LOW transmit power level as default, if you have an amplified NRF-module and // power your radio separately with a good regulator you can turn up PA level. #define MY_RF24_PA_LEVEL RF24_PA_LOW //Uncomment to enable repeater mode //#define MY_REPEATER_FEATURE //Uncomment to assign static node ID //#define MY_NODE_ID 9 // Load mysensors library #include <MySensors.h> // Load Serial Peripheral Interface library #include <SPI.h> // Arduino pin attached to driver pins #define RED_PIN 3 #define WHITE_PIN 9 #define GREEN_PIN 5 #define BLUE_PIN 6 #define NUM_CHANNELS 4 // how many channels, RGBW=4 RGB=3... #define CHILD_ID 1 // Smooth stepping between the values #define STEP 1 #define INTERVAL 10 MyMessage lastvalueMsg(CHILD_ID, V_VAR1); MyMessage lastisonMsg(CHILD_ID, V_VAR2); MyMessage lastdimmMsg(CHILD_ID, V_VAR3); // Stores the current color settings byte channels[4] = {RED_PIN, GREEN_PIN, BLUE_PIN, WHITE_PIN}; byte values[4] = {0, 0, 0, 0}; byte target_values[4] = {0, 0, 0, 0}; //Stores corrected values for each step from 0 to 255. See https://diarmuid.ie/blog/pwm-exponential-led-fading-on-arduino-or-other-platforms/ byte converted_values[256] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,6,6,6,6,6,6,7,7,7,7,7,7,8,8,8,8,8,9,9,9,9,9,10,10,10,10,11,11,11,11,12,12,12,13,13,13,13,14,14,14,15,15,15,16,16,17,17,17,18,18,19,19,20,20,20,21,21,22,22,23,23,24,24,25,26,26,27,27,28,29,29,30,31,31,32,33,34,34,35,36,37,38,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,54,55,56,57,58,60,61,62,64,65,67,68,70,71,73,75,76,78,80,81,83,85,87,89,91,93,95,97,99,101,104,106,108,111,113,116,118,121,123,126,129,132,135,138,141,144,147,150,154,157,161,164,168,171,175,179,183,187,191,195,200,204,209,213,218,223,228,233,238,243,249,255}; // stores dimming level byte dimming = 100; byte target_dimming = 100; // tracks if the strip should be on of off boolean isOn = false; // tracks if the strip's last status was off. This overrides isOn at startup boolean wasOff = true; //tracks if the old values have bben requested from the controller. This prevents the request from being send multipΓle times in the main loop. boolean valuesrequested = false; // time tracking for updates unsigned long lastupdate = millis(); void setup() { // Set all channels to output (pin number, type) for (int i = 0; i < NUM_CHANNELS; i++) { pinMode(channels[i], OUTPUT); } // debug if (isOn) { Serial.println("RGBW is running..."); } } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo(SN, SV); // Register this device as Waterflow sensor present(CHILD_ID, S_RGBW_LIGHT, SN, true); } void loop() { if (!valuesrequested) { // get old values if this is just a restart Serial.println("Requesting old values..."); //Request RGBW values request( CHILD_ID, V_VAR1 ); wait(200); //Request Status request( CHILD_ID, V_VAR2 ); wait(200); //Request dimm level request( CHILD_ID, V_VAR3 ); valuesrequested = true; } // set the new light colors if (millis() > lastupdate + INTERVAL) { updateLights(); lastupdate = millis(); } } // callback function for incoming messages void receive(const MyMessage &message) { Serial.print("Got a message - "); Serial.print("Messagetype is: "); Serial.println(message.type); // acknoledgment if (message.isAck()) { Serial.println("Got ack from gateway"); } // new dim level else if (message.type == V_DIMMER or message.type == V_VAR3) { Serial.println("Dimming to "); Serial.println(message.getString()); target_dimming = message.getByte(); send(lastdimmMsg.set(target_dimming)); if (!wasOff) { // a new dimmer value also means on, no seperate signal gets send (by domoticz) isOn = true; send(lastisonMsg.set(isOn)); } } // on / off message else if (message.type == V_STATUS or message.type == V_VAR2) { Serial.print("Turning light "); isOn = message.getInt(); if (isOn) { Serial.println("on"); wasOff = false; } else { Serial.println("off"); } send(lastisonMsg.set(isOn)); } // new color value else if (message.type == V_RGBW or message.type == V_VAR1) { const char * rgbvalues = message.getString(); send(lastvalueMsg.set(rgbvalues)); inputToRGBW(rgbvalues); if (!wasOff) { // a new color also means on, no seperate signal gets send (by domoticz); needed e.g. for groups isOn = true; send(lastisonMsg.set(isOn)); } } } // this gets called every INTERVAL milliseconds and updates the current pwm levels for all colors void updateLights() { int convertedvalue=0; // update pin values -debug //Serial.println(greenval); //Serial.println(redval); //Serial.println(blueval); //Serial.println(whiteval); //Serial.println(target_greenval); //Serial.println(target_redval); //Serial.println(target_blueval); //Serial.println(target_whiteval); //Serial.println("+++++++++++++++"); // for each color for (int v = 0; v < NUM_CHANNELS; v++) { if (values[v] < target_values[v]) { values[v] += STEP; if (values[v] > target_values[v]) { values[v] = target_values[v]; } } if (values[v] > target_values[v]) { values[v] -= STEP; if (values[v] < target_values[v]) { values[v] = target_values[v]; } } } // dimming if (dimming < target_dimming) { dimming += STEP; if (dimming > target_dimming) { dimming = target_dimming; } } if (dimming > target_dimming) { dimming -= STEP; if (dimming < target_dimming) { dimming = target_dimming; } } /* // debug - new values Serial.println(greenval); Serial.println(redval); Serial.println(blueval); Serial.println(whiteval); Serial.println(target_greenval); Serial.println(target_redval); Serial.println(target_blueval); Serial.println(target_whiteval); Serial.println("+++++++++++++++"); */ // set actual pin values for (int i = 0; i < NUM_CHANNELS; i++) { if (isOn) { // normal fading //analogWrite(channels[i], dimming / 100.0 * values[i]); //Fading with corrected values see https://diarmuid.ie/blog/pwm-exponential-led-fading-on-arduino-or-other-platforms/ analogWrite(channels[i], dimming / 100.0 * converted_values[values[i]]); } else { analogWrite(channels[i], 0); } } } // converts incoming color string to actual (int) values // ATTENTION this currently does nearly no checks, so the format needs to be exactly like domoticz sends the strings void inputToRGBW(const char * input) { Serial.print("Got color value of length: "); Serial.println(strlen(input)); if (strlen(input) == 6) { Serial.println("new rgb value"); target_values[0] = fromhex (& input [0]); target_values[1] = fromhex (& input [2]); target_values[2] = fromhex (& input [4]); target_values[3] = 0; } else if (strlen(input) == 9) { Serial.println("new rgbw value"); target_values[0] = fromhex (& input [1]); // ignore # as first sign target_values[1] = fromhex (& input [3]); target_values[2] = fromhex (& input [5]); target_values[3] = fromhex (& input [7]); } else { Serial.println("Wrong length of input"); } Serial.print("New color values: "); Serial.println(input); for (int i = 0; i < NUM_CHANNELS; i++) { Serial.print(target_values[i]); Serial.print(", "); } Serial.println(""); Serial.print("Dimming: "); Serial.println(dimming); } // converts hex char to byte byte fromhex (const char * str) { char c = str [0] - '0'; if (c > 9) c -= 7; int result = c; c = str [1] - '0'; if (c > 9) c -= 7; return (result << 4) | c; }
-
RE: Scene controller: how to do it bidirectional
@gohan I do! The scene controller activates domoticz scenes. Like this one: https://www.mysensors.org/build/scene_controller
-
RE: Scene controller: how to do it bidirectional
@gohan The sonoff touch switch. (Based on esp8266)
-
Scene controller: how to do it bidirectional
I have built a scene controller based on an sonoff touch switch. When I do a long press it cycles through the scenes. The devices created in domoticz are used as activation devices for several scenes. (color / brightness of my TV back light) So fa so good. Sometimes I use my smartphone to activate a scene. After this domoticz and the scene controller are out of sync. How do I update it's state? Domoticz does not send a status back to the activation device, right? So what's the best way? Lua?
-
RE: Your workshop :)
I've got the feeling this thread is going to be extreme expensive for me.
-
RE: Your workshop :)
@AWI Troubleshooting power probolems with the nrf24 is a good example, thx. I think at the beginning it is more a nice to have than a must have. I am always curios for such things. Still I don't want to buy trash. I will read a bit and watch ebay for good offers. Thx for your explanation.
-
RE: Your workshop :)
I noticed the many of you have an oscilloscope on their desk. What exactly do you use these for? There seems to be nothing under 200$ and I wonder if it is worth it.
-
RE: When powered from usb, nrf24I01 is ok, from external Power not
@mfalkvidd I bet the serial gateway. 2.1.1 is bugy. I solved this problem by upgrading to the 2.2 beta from github.
-
RE: Your workshop :)
@Yveaux I saw that thing on Amazon. There was a review saying the brackets would melt easily when using hot air. Did you use this with hot air?
-
RE: Your workshop :)
@gohan Then you can safely lean back and wait for my review.
-
RE: Your workshop :)
@gohan You are right. I just ordered the thing. With the case and the builtin battery it looks like a real tool. The price seems to be a promotion. Normal price is >30$.
You shoult by the way fix the link. Makes it easier for others to order it.I am looking for a soldering vise. Has anyone tested this one: https://www.amazon.de/dp/B00196RV9C/ref=wl_it_dp_o_pC_S_ttl?_encoding=UTF8&colid=2COJS1QZ6SUVJ&coliid=IQEGMI1GM2R46 ?
-
RE: How to best set up a bigger mysensors installation
I always got the same behavior. The ID should never change after it was first assigned, You need to flash the erase eeprom sketch to get rid of it.
-
RE: Payload always 0 when using Arduino Pro Mini
It looks like the node does not get a node ID from the controller. If you do not have a controller which supports assigning node IDs automatically, you have to assign a static ID in the sketch.
-
RE: Your workshop :)
I just bought a new soldering iron for it last year. Had to google for days to find spare parts.
-
RE: Your workshop :)
I am especially proud of my 20 years old analog soldering station.
-
RE: Gateway Backup
especially the synchronisation of the database would be interesting.
-
RE: Gateway Backup
This will work. You could even automate it with a heartbeat cluster.
-
RE: Serial Gateway restarting
Tested with 2.2 Beta gateway. Problem seems solved. I am running on 5V 16 Mhz / RF24_PA_MAX now. Could not reproduce the problem anymore. Thx for your help!
-
RE: Serial Gateway restarting
I chose 5V / 16Mhz in the Arduino IDE. If that did not fit the serial interface would not work, right?
I will try with the git version then.As your installation includes similar components, may I ask what your gateway looks like?
Edit: Tested with 2.2 Beta gateway. Problem seems solved. I am running on 5V 16 Mhz / RF24_PA_MAX now. Could not reproduce the problem anymore. Thx for your help!
-
RE: Detect Generator running
The rectifier is unnecessary, the optocoupler has an built-in diode. The 1 m resistor can burn. You'll have an voltage not much smaller than the input voltage at it. I would recommend to replace it with an capacitor.
Like this http://www.electroschematics.com/11922/mains-voltage-sensor/
-
RE: Serial Gateway restarting
I have tested these constallations:
3.3V Arduino, RF24_PA_MIN
5V Arduino, RF24_PA_MIN
5V arduino, RF24_PA_MAXAll with the amplified and the simple version of the radio. The Result was always the same:
2017-04-28 13:45:41.346 MySensors: Node: 11, Sketch Name: Molgan 2017-04-28 13:45:41.347 MySensors: Node: 11, Sketch Version: 1.0 2017-04-28 13:45:41.380 MySensors: Gateway Ready... 2017-04-28 13:45:41.456 MySensors: Gateway Version: 2.1.1
I will try another power supply for the Pi later. Just to be sure.
Do you think it would make sense to try the git hub version of MySensors?
-
RE: How to best set up a bigger mysensors installation
There can be only one gateway in one network. Auto fallback does not exist afaik. You can have one network per floor. This means you have to choose another channel/frequency.
I have used one repeater in a similar scenario. Problems occur when the node occasionally can reach the gateway directly. I had to specify the parent node/repeater. Now it works well. -
RE: Serial Gateway restarting
Any other ideas? Just tested with another power supply (3 * AA cell) but I am still facing the same problem.
-
RE: Serial Gateway crash and reloads
@martins Did you ever find a solution for this? I am facing similar problems with the serial gateway: https://forum.mysensors.org/topic/6684/serial-gateway-restarting/13
-
RE: Serial Gateway restarting
Wie probably have the same problems with the smd nrf24 that we have with the regular ones, too. There is no big capacitor in the circuit of the molgan hack pcb. Perhaps this the cause of the problems. I will try to add one.
Edit: Tried it with an additional 10 uF capacitor. That changed nothing.
-
RE: Serial Gateway restarting
Correct. I have tested this with some other nodes. This seems only a problem with the molgan nodes. Even other nodes with 2.1.1 work without problems. Differences I see with the Molgans is the use of the internal oscillator and the use of the smd version of the nrf.
-
RE: Serial Gateway restarting
@Yveaux I really don't know whether this is a genuine chip. But I can still reproduce the problem after replacing the LE33. Tested with a non amplified nrf24, too. Same problem.
I have restarted two other nodes with an older version of mysensors (2.0 or 1.8). The gateway did not restart.
-
RE: Serial Gateway restarting
oops, missed this limitation of the LE33. I will replace it by an ASM1117 and test again. Thx.
-
RE: Serial Gateway restarting
- Radio is nrf24l01. The version with antenna and pa + lna . http://www.ebay.de/itm/272260489477?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT .I have wrapped it in aluminum foil which improved the communications much. MY_RF24_PA_LEVEL is set to RF24_PA_HIGH.
- Yes, most of my nodes including the molgans are also 2.1.1. Some other nodes are still 1.8.
- I am using Rev 7 of this board: https://www.openhardware.io/view/4/EasyNewbie-PCB-for-MySensors . I have connected it to the 5V Line of my Raspberry Pi. Power Supply is good, the rpi runs fine and stable. On the board there is a 3.3V regulator + the recommended capacitors. I also have an additional capacitor (47 uF) soldered directly to the nrf.
-
RE: Serial Gateway restarting
Ok, now I can reproduce another bug that causes the serial gateway to restart:
2017-04-26 11:09:51.760 MySensors: Node: 14, Sketch Name: Molgan 2017-04-26 11:09:51.761 MySensors: Node: 14, Sketch Version: 1.0 2017-04-26 11:09:51.780 (MySensorsGw1) Lighting 2 (Security Sensor) 2017-04-26 11:09:51.928 MySensors: Gateway Ready... 2017-04-26 11:09:52.004 MySensors: Gateway Version: 2.1.1
I have built several nodes based on the Ikea Molgan hack
I am using the included sketch without modifications.
Every time one of these nodes starts up, the gateway restarts. Without a starting Molgan node I did not see a single gateway restart for 24 hours.
-
RE: Serial Gateway restarting
The restarts seem to have stopped after setting a static parent. But the gateway should never restart because of some failed transmission imho.
-
RE: Serial Gateway restarting
This has improved the overall latency for my node much, thanks.
Anyway the serial gateway still seems a little buggy regarding the handling of broken messages, right?
-
RE: Serial Gateway restarting
Does this affect messages sent from the gateway to the node, too? I found nothing in the documentation about this.
-
Serial Gateway restarting
My serial Gateway (2.1.1) is restarting in some situations. I have already replaced the hardware. It is running on an 3.3V Arduino. I am using an uncostomized version of the serial gateway sketch. Only the baud rate is reduced because of the 8 Mhz Arduino. The recommended capacitor is in place. I am using the "Newbie PCB" with an dedicated voltage regulator.
After some testing it seems that the restarts always occur when the gateway fails to transmit a message to a node. I had one node that was temporary offline. This node is normaly activated via some lua scripts in domotics. While it was offline this always caused a gateway restart.2017-04-19 23:27:00.450 EventSystem: Event triggered: Heizung Arbeitszimmer_2 2017-04-19 23:27:00.600 MySensors: Gateway Ready... 2017-04-19 23:27:00.676 MySensors: Gateway Version: 2.1.1 2017-04-19 23:27:01.801 MySensors: Gateway Ready... 2017-04-19 23:27:01.877 MySensors: Gateway Version: 2.1.1
I have an LED actuator node which is only reliably reachable via a repeater. It seems like the gateway tries to reach it directly which sometimes fails. In these situations the switching is delayed by about 2 seconds and according to the logs the gateway restarts.
This does not occur with nodes near the gateway.
Is this a bug or expected behaviour? Or am I doing something completely wrong?
-
RE: Molgan-Hack hack
You board is almost perfect. You could just expose some of the pins with the next version. This would keep it very generic anf make it easy to add additional functions. Commercial devices contain temp, hum and light sensors. And a vibration sensor as thief protection. Most of that could easily fit in the molgan.
-
RE: Newbie - Do not succeed to start
I think the generic board does not work because the default settings are not sufficient for ms. Be sure the settings match your actual esp8266 module.
Did you pull down gpio0 when you powered on the module? This activates the programming mode.
If you want to go the easy way just get a node mcu compatible board like wemos d1 mini. It has an onboard USB port and you don't have to manually put it in programming mode.
Mqtt adds complexity. If you don't need it you should choose plain ms. -
RE: π¬ Ikea Molgan Hack
Never mind, it's working now. I soldered a completely new pcb and this time it runs without problems. I still have no idea, why it did now work on first try. But I guess it has something to do with the fact, that I used hot air and solder paste for the first time.
Edit: I have assembled all the stuff and the node is kind of working. It presents itself to the gateway perfectly. What does not work is the motion sensor. The pin is always high. When I pull it down manually and release it again, the node sends its message.
I have removed the light sensor and R17. I have replaced R11 with a 1k resistor because that was the smallest one I had. Could this be a problem?Edit: Ok, found the problem. Seems like I have accidentally unsoldered R2 when I removed the light sensor. From your pictures I found out, that there has to be a 470k resistor. Now it works.
-
RE: π¬ Ikea Molgan Hack
@LastSamurai How exactly did you flash it? I am using an USBasp, too. As it seems I have bricked 2 atmega328p and one Arduino Pro mini already.
This is what I did:
"C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avrdude.exe" -C "C:\Program Files (x86)\Arduino\hardware\tools\avr\etc\avrdude.conf" -B 40 -c usbasp -p m328p -b 11520 -P usb -V -v -U efuse:w:0xFE:m -U hfuse:w:0xDA:m -U lfuse:w:0xE2:m"C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avrdude.exe" -C "C:\Program Files (x86)\Arduino\hardware\tools\avr\etc\avrdude.conf" -c usbasp -p m328p -b 115200 -P usb -V -U flash:w:ATmegaBOOT_168_atmega328_pro_8MHz.hex
After this I am not able to flash sketches via the Arduino IDE. Any ideas?
-
RE: Office plant monitoring
Which sketch did you use? The one from this page needs the fork connected to analog input pins Ax.
-
RE: Connect Serial Gateway to Openwrt routers TX RX pins
The console paramter needs to be removed completely. You cannot use the uart for domoticz and as serial console at the same time.
https://wiki.openwrt.org/doc/recipes/terminate.console.on.serial
-
RE: Connect Serial Gateway to Openwrt routers TX RX pins
Are you sure you need to set the rate in the code and recompile? Shouldn't it be enough to change it in config.h and domoticz? The uart of the router should be able to change the speed at runtime like other Linux devices, right?
-
RE: Connect Serial Gateway to Openwrt routers TX RX pins
Did you try it with a lower baud rate? 9600?
-
RE: How to scan rf remote
Ups, I should read more carefully.Sorry.
Edit: you could use a rflink gateway. Rflink shows code and protocol in the log.
-
RE: light and relay turn on automatically !
He only wrote about a blinking led not about the whole node failing.
-
RE: light and relay turn on automatically !
Does the blinking stop when you shutdown the controller?
-
RE: light and relay turn on automatically !
What do you mean with L led?
The gas sensor is sending a value for every iteration of the loop. You should only send a new value to the controller if it changed (more than x). This way the node is always active and spamming the controller.I don't see anything wrong with the relay sketch.
Regarding the self switching relay node I just wanted to say that I you should look for external reasons for this behaviour. Either the controller or another sender is telling the node to switch the relay on.
-
RE: light and relay turn on automatically !
The LED blinks when the radio is active. This could be caused by a bug in your code. Can you share your sketch?
The light turning in by itself could be a forgotten rule in your controller or maybe a neighbor using mysensors, too?
-
RE: π¬ Sonoff relay using MySensors ESP8266 wifi or mqtt gateway
Yes, I thought about that. But during my tests the web updater was just most reliable and easiest to use. Arduino ota needs extensions to the IDE and sometimes the node was not found. Web updater works out of the box and never made any problems.
-
RE: How to Reestablish lost NRF24 connection
When the node loses the connection, it tries to find a gateway or repeater and reestablish the connection. I don't know if it gives up at some point, however I have seen situations where it took some time for the connection to come back.
-
RE: π¬ Sonoff relay using MySensors ESP8266 wifi or mqtt gateway
Ok, I just wiped out (hopefully) all my passwords and IP information.
/** The MySensors Arduino library handles the wireless radio link and protocol between your home built sensors/actuators and HA controller of choice. The sensors forms a self healing radio network with optional repeaters. Each repeater and gateway builds a routing tables in EEPROM which keeps track of the network topology allowing messages to be routed to nodes. Created by Henrik Ekblad <henrik.ekblad@mysensors.org> Copyright (C) 2013-2015 Sensnology AB Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors Documentation: http://www.mysensors.org Support Forum: http://forum.mysensors.org This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. ******************************* REVISION HISTORY Version 1.0 - Henrik EKblad Contribution by a-lurker and Anticimex, Contribution by Norbert Truchsess <norbert.truchsess@t-online.de> Contribution by Ivo Pullens (ESP8266 support) DESCRIPTION The EthernetGateway sends data received from sensors to the WiFi link. The gateway also accepts input on ethernet interface, which is then sent out to the radio network. VERA CONFIGURATION: Enter "ip-number:port" in the ip-field of the Arduino GW device. This will temporarily override any serial configuration for the Vera plugin. E.g. If you want to use the defualt values in this sketch enter: 192.168.178.66:5003 LED purposes: - To use the feature, uncomment WITH_LEDS_BLINKING in MyConfig.h - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly - ERR (red) - fast blink on error during transmission error or recieve crc error See http://www.mysensors.org/build/esp8266_gateway for wiring instructions. nRF24L01+ ESP8266 VCC VCC CE GPIO4 CSN/CS GPIO15 SCK GPIO14 MISO GPIO12 MOSI GPIO13 GND GND Not all ESP8266 modules have all pins available on their external interface. This code has been tested on an ESP-12 module. The ESP8266 requires a certain pin configuration to download code, and another one to run code: - Connect REST (reset) via 10K pullup resistor to VCC, and via switch to GND ('reset switch') - Connect GPIO15 via 10K pulldown resistor to GND - Connect CH_PD via 10K resistor to VCC - Connect GPIO2 via 10K resistor to VCC - Connect GPIO0 via 10K resistor to VCC, and via switch to GND ('bootload switch') Inclusion mode button: - Connect GPIO5 via switch to GND ('inclusion switch') Hardware SHA204 signing is currently not supported! Make sure to fill in your ssid and WiFi password below for ssid & pass. */ #include <SPI.h> // Enable debug prints to serial monitor #define MY_DEBUG // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h #define MY_BAUD_RATE 9600 // Enables and select radio type (if attached) //#define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #define MY_GATEWAY_ESP8266 #define MY_ESP8266_SSID "MySSID" #define MY_ESP8266_PASSWORD "MyPSK" // Enable UDP communication //#define MY_USE_UDP // Set the hostname for the WiFi Client. This is the hostname // it will pass to the DHCP server if not static. // #define MY_ESP8266_HOSTNAME "sensor-gateway" // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP) #define MY_IP_ADDRESS 192,168,1,200 // If using static ip you need to define Gateway and Subnet address as well #define MY_IP_GATEWAY_ADDRESS 192,168,1,254 #define MY_IP_SUBNET_ADDRESS 255,255,255,0 // The port to keep open on node server mode #define MY_PORT 5003 // How many clients should be able to connect to this gateway (default 1) #define MY_GATEWAY_MAX_CLIENTS 2 // Controller ip address. Enables client mode (default is "server" mode). // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere. //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68 // Enable inclusion mode //#define MY_INCLUSION_MODE_FEATURE // Enable Inclusion mode button on gateway // #define MY_INCLUSION_BUTTON_FEATURE // Set inclusion mode duration (in seconds) //#define MY_INCLUSION_MODE_DURATION 60 // Digital pin used for inclusion mode button //#define MY_INCLUSION_MODE_BUTTON_PIN 3 // Flash leds on rx/tx/err // #define MY_LEDS_BLINKING_FEATURE // Set blinking period // #define MY_DEFAULT_LED_BLINK_PERIOD 300 // Led pins used if blinking feature is enabled above //#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin //#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin //#define MY_DEFAULT_TX_LED_PIN 16 // the PCB, on board LED #if defined(MY_USE_UDP) #include <WiFiUDP.h> #else #include <ESP8266WiFi.h> #endif #include <WiFiClient.h> #include <ESP8266WebServer.h> #include <ESP8266mDNS.h> #include <ESP8266HTTPUpdateServer.h> #include <MySensors.h> #define RELAY_1_Pin 12 #define LED_1_Pin 13 #define TOUCH_1_Pin 0 #define RELAY_1 1 #define TOUCH_1 3 #define TOUCH_2 4 boolean relayon = false; int activescene = 1; volatile unsigned long LastChange = 0; volatile boolean RelayToggleRequired = false; volatile boolean SceneSwitchRequired = false; volatile boolean SceneSwitchTriggeredByTimeout = false; volatile boolean SceneSwitchTriggeredByTimeout2 = false; MyMessage msg(RELAY_1, V_LIGHT); MyMessage msg1(TOUCH_1, V_SCENE_ON); MyMessage msg2(TOUCH_2, V_LIGHT); ESP8266WebServer httpServer(80); ESP8266HTTPUpdateServer httpUpdater; const char* host = "sonofftouch1"; const char* location = "Couch"; char* update_username = "admin"; //Benutzername zum login fΓΌr die OTA-Programmierung char* update_password = "MyPassword"; //Passwort String webPage = ""; unsigned long lastheartbeat = 0; void buttonChangeCallback() { if (digitalRead(TOUCH_1_Pin) == 1) { //LED off for feedback digitalWrite(LED_1_Pin, 1); //Button has been released, trigger one of the two possible options. if (millis() - LastChange > 500) { //Long Press if (!SceneSwitchTriggeredByTimeout) { SceneSwitchRequired = true; } } else if (millis() - LastChange > 50) { //Short press at least 50 ms for debounce RelayToggleRequired = true; } else { //Too short to register as a press } } else { //LED on for feedback digitalWrite(LED_1_Pin, 0); //Just been pressed - do nothing until released. } LastChange = millis(); SceneSwitchTriggeredByTimeout = false; SceneSwitchTriggeredByTimeout2 = false; } void setup() { webPage += "<h1>ESP8266 Web Server</h1>"; webPage += "<br><h1>"; webPage += host; webPage += "</h1>"; webPage += "<br><h1>"; webPage += location; webPage += "</h1>"; webPage += "<br><a href=/update>Click here to update</a>"; pinMode(TOUCH_1_Pin, INPUT_PULLUP); // sets the digital pin as output pinMode(RELAY_1_Pin, OUTPUT); pinMode(LED_1_Pin, OUTPUT); //LED off digitalWrite(LED_1_Pin, 1); MDNS.begin(host); httpUpdater.setup(&httpServer, "/update", update_username, update_password); httpServer.begin(); MDNS.addService("http", "tcp", 80); httpServer.on("/", []() { httpServer.send(200, "text/html", webPage); }); Serial.println("Enabling touch switch interrupt"); attachInterrupt(digitalPinToInterrupt(TOUCH_1_Pin), buttonChangeCallback, CHANGE); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Sonoff Touch Mysensors", "1.0"); present(RELAY_1, S_LIGHT, "single click/onboard relay"); present(TOUCH_1, S_SCENE_CONTROLLER, "double click/scene controller"); present(TOUCH_2, S_LIGHT, "long press virtuel switch"); } void loop() { httpServer.handleClient(); if (millis() - lastheartbeat > 30000) { //sendHeartbeat(); sendBatteryLevel(90); lastheartbeat = millis(); } if (RelayToggleRequired) { ToggleRelay(); RelayToggleRequired = false; } if (SceneSwitchRequired) { SwitchScene(); SceneSwitchRequired = false; } if (millis() - LastChange > 600) { if (digitalRead(TOUCH_1_Pin) == 0) { if (SceneSwitchTriggeredByTimeout == false) { SceneSwitchTriggeredByTimeout = true; SwitchScene(); } } } if (millis() - LastChange > 3000) { if (digitalRead(TOUCH_1_Pin) == 0) { if (SceneSwitchTriggeredByTimeout2 == false) { SceneSwitchTriggeredByTimeout2 = true; SwitchSceneOff(); } } } } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type == V_LIGHT) { // Change relay state if (message.sensor == RELAY_1) { digitalWrite(RELAY_1_Pin, message.getBool() ? 1 : 0); relayon = message.getBool() ? 1 : 0; } // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } } void ToggleRelay() { Serial.println("Single Click"); if (relayon) { digitalWrite(RELAY_1_Pin, 0); relayon = false; } else { digitalWrite(RELAY_1_Pin, 1); relayon = true; } send(msg.set(relayon ? 1 : 0)); } void SwitchScene() { //Domoticz does not like 1 as scene. So we start with scene 2. Serial.println("Long press"); activescene += 1; if (activescene > 6) { activescene = 2; } Serial.print("Activating Scene "); Serial.println(activescene); send(msg1.set(activescene)); } void SwitchSceneOff() { Serial.println("3sec Long Press"); send(msg1.set(7)); }
-
RE: π¬ Sonoff relay using MySensors ESP8266 wifi or mqtt gateway
All the touch stuff is handheld by an ic. You can use it like an normal button, active low. It is connected to pin 0. I have made a two way switch of it. With a long press I cycle through multiple scenes which control the color of my tv's led light. With a even longer press I can switch the tv light off. I can share the code when I found the time to clean it up.
I like the OTA update function of the esp very much. It's much simpler than the rf24/ Arduino solution. My sketch provides a browser based update function with just 5 lines of code. This was important to me because I don't want to get my switches out off the wall for every update. For the eu version of the sonoff this is mandatory because the programming header does not fit when the device is mounted.
-
RE: π¬ Sonoff relay using MySensors ESP8266 wifi or mqtt gateway
I don't see the problem here. An direct ip connection between the controller and the node is perfect for critical nodes as less components mean less things that can fail. I have flashed a Sonoff Touch switch with the esp8266 gateway sketch and it is running just fine. Or am I missing something?
-
RE: π¬ Sonoff relay using MySensors ESP8266 wifi or mqtt gateway
This is not really a gateway. You can use the esp8266 gateway sketch, disable the nrf24 / rfm69 and directly attach sensors. So basically it's an relay actuator which is configured as a mysensors gateway.
-
ESP8266 actuator keepalive?
When using an esp8266 actuator the connection is established by the controller. When the node is restarted this connection gets lost. This is why I set the data timeout to 1 minute in Domoticz. Now I have the problem, that Domoticz reconnects once a minute because the node is an pure actuator and does not send any data. I tried to use the sendkeepalive() function in the main loop every 30 seconds, but Domoticz still drops the connection. Next step would be to request the time from the controller or anything similar. Or is there any obvious solution I just don't see?
-
RE: API Documentation /Pairing?
There is no pairing. You could use deterrent channels or (if security matters) indeed have a look at signing.
-
RE: Install kicad mysensor components
Thx, this should get me started. I've never successfully designed a pcb before. I had a look at Eagle a few month ago and gave up. I hove I'll have more success with KiCad. Your help is very welcome.
-
RE: Install kicad mysensor components
So basicly I could use any power supply in the circuit and still HLK-PM01 in the layout? How do I map this?
-
RE: Radio FAIL after ~3 weeks [SOLVED]
Can you try to add the following line to your sketch?
#define MY_RF24_PA_LEVEL RF24_PA_LOW
Right at the top, along with the other defines. I had similar problems with a LED Dimmer node. This solved the problem.
-
RE: Radio FAIL after ~3 weeks [SOLVED]
Coul it be you are using modules with different chips? See https://forum.mysensors.org/topic/1153/we-are-mostly-using-fake-nrf24l01-s-but-worse-fakes-are-emerging
-
RE: Install kicad mysensor components
Sorry for hijacking this old thread, but I have problems finding libraries for all common parts. Does anybody have a working library for the HlK-PM01 power supply? There are tons of libs for the pcb layout, but i cannot find any symbols. How do you guys find this stuff? I am just asking google for "KiCad HlK-PM01".
-
RE: Radio FAIL after ~3 weeks [SOLVED]
The Problem is most likely a problem with your hardware. Try to lower the distance and see if the problem still exists. If not you should replace your radios. Look for radios with pa / lna.
-
RE: Radio FAIL after ~3 weeks [SOLVED]
Great analysis. I will surely send you my code for review next time.
-
RE: Radio FAIL after ~3 weeks [SOLVED]
@Reza
Which NRF Modules do you use? 50 meter with a wall in between wont function properly with the cheap ones. You need something like this for the Job: -
RE: π¬ OH MySensors RGBW Controller
Thx for the info. This comes 24 hours to late.
-
RE: π¬ OH MySensors RGBW Controller
I have tried to get some kind of non linear fading by calculating the values for 256 steps using Excel and putting them in an array. The result is pretty good. Please test and share your opinion.
/** Based on the MySensors Project: http://www.mysensors.org This sketch controls a (analog)RGBW strip by listening to new color values from a (domoticz) controller and then fading to the new color. Version 1.1 - Added save/restore of values to/from controller, removed non linear fading code Version 1.0 - Changed pins and gw definition Version 0.9 - Oliver Hilsky **/ #define MY_DEBUG #define SN "RGBW 01" #define SV "1.1" #define MY_RADIO_NRF24 // change the pins to free up the pwm pin for led control #define MY_RF24_CE_PIN 4 //<-- NOTE!!! changed, the default is 9 #define MY_RF24_CS_PIN 10 // default is 10 // Set LOW transmit power level as default, if you have an amplified NRF-module and // power your radio separately with a good regulator you can turn up PA level. #define MY_RF24_PA_LEVEL RF24_PA_LOW //Uncomment to enable repeater mode //#define MY_REPEATER_FEATURE //Uncomment to assign static node ID //#define MY_NODE_ID 9 // Load mysensors library #include <MySensors.h> // Load Serial Peripheral Interface library #include <SPI.h> // Arduino pin attached to driver pins #define RED_PIN 3 #define WHITE_PIN 9 #define GREEN_PIN 5 #define BLUE_PIN 6 #define NUM_CHANNELS 4 // how many channels, RGBW=4 RGB=3... #define CHILD_ID 1 // Smooth stepping between the values #define STEP 1 #define INTERVAL 10 MyMessage lastvalueMsg(CHILD_ID, V_VAR1); MyMessage lastisonMsg(CHILD_ID, V_VAR2); MyMessage lastdimmMsg(CHILD_ID, V_VAR3); // Stores the current color settings byte channels[4] = {RED_PIN, GREEN_PIN, BLUE_PIN, WHITE_PIN}; byte values[4] = {0, 0, 0, 0}; byte target_values[4] = {0, 0, 0, 0}; //Stores corrected values for each step from 0 to 255. See https://diarmuid.ie/blog/pwm-exponential-led-fading-on-arduino-or-other-platforms/ byte converted_values[256] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,6,6,6,6,6,6,7,7,7,7,7,7,8,8,8,8,8,9,9,9,9,9,10,10,10,10,11,11,11,11,12,12,12,13,13,13,13,14,14,14,15,15,15,16,16,17,17,17,18,18,19,19,20,20,20,21,21,22,22,23,23,24,24,25,26,26,27,27,28,29,29,30,31,31,32,33,34,34,35,36,37,38,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,54,55,56,57,58,60,61,62,64,65,67,68,70,71,73,75,76,78,80,81,83,85,87,89,91,93,95,97,99,101,104,106,108,111,113,116,118,121,123,126,129,132,135,138,141,144,147,150,154,157,161,164,168,171,175,179,183,187,191,195,200,204,209,213,218,223,228,233,238,243,249,255}; // stores dimming level byte dimming = 100; byte target_dimming = 100; // tracks if the strip should be on of off boolean isOn = false; // tracks if the strip's last status was off. This overrides isOn at startup boolean wasOff = true; //tracks if the old values have bben requested from the controller. This prevents the request from being send multipΓle times in the main loop. boolean valuesrequested = false; // time tracking for updates unsigned long lastupdate = millis(); void setup() { // Set all channels to output (pin number, type) for (int i = 0; i < NUM_CHANNELS; i++) { pinMode(channels[i], OUTPUT); } // debug if (isOn) { Serial.println("RGBW is running..."); } } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo(SN, SV); // Register this device as Waterflow sensor present(CHILD_ID, S_RGBW_LIGHT, SN, true); } void loop() { if (!valuesrequested) { // get old values if this is just a restart Serial.println("Requesting old values..."); //Request RGBW values request( CHILD_ID, V_VAR1 ); wait(200); //Request Status request( CHILD_ID, V_VAR2 ); wait(200); //Request dimm level request( CHILD_ID, V_VAR3 ); valuesrequested = true; } // set the new light colors if (millis() > lastupdate + INTERVAL) { updateLights(); lastupdate = millis(); } } // callback function for incoming messages void receive(const MyMessage &message) { Serial.print("Got a message - "); Serial.print("Messagetype is: "); Serial.println(message.type); // acknoledgment if (message.isAck()) { Serial.println("Got ack from gateway"); } // new dim level else if (message.type == V_DIMMER or message.type == V_VAR3) { Serial.println("Dimming to "); Serial.println(message.getString()); target_dimming = message.getByte(); send(lastdimmMsg.set(target_dimming)); if (!wasOff) { // a new dimmer value also means on, no seperate signal gets send (by domoticz) isOn = true; send(lastisonMsg.set(isOn)); } } // on / off message else if (message.type == V_STATUS or message.type == V_VAR2) { Serial.print("Turning light "); isOn = message.getInt(); if (isOn) { Serial.println("on"); wasOff = false; } else { Serial.println("off"); } send(lastisonMsg.set(isOn)); } // new color value else if (message.type == V_RGBW or message.type == V_VAR1) { const char * rgbvalues = message.getString(); send(lastvalueMsg.set(rgbvalues)); inputToRGBW(rgbvalues); if (!wasOff) { // a new color also means on, no seperate signal gets send (by domoticz); needed e.g. for groups isOn = true; send(lastisonMsg.set(isOn)); } } } // this gets called every INTERVAL milliseconds and updates the current pwm levels for all colors void updateLights() { int convertedvalue=0; // update pin values -debug //Serial.println(greenval); //Serial.println(redval); //Serial.println(blueval); //Serial.println(whiteval); //Serial.println(target_greenval); //Serial.println(target_redval); //Serial.println(target_blueval); //Serial.println(target_whiteval); //Serial.println("+++++++++++++++"); // for each color for (int v = 0; v < NUM_CHANNELS; v++) { if (values[v] < target_values[v]) { values[v] += STEP; if (values[v] > target_values[v]) { values[v] = target_values[v]; } } if (values[v] > target_values[v]) { values[v] -= STEP; if (values[v] < target_values[v]) { values[v] = target_values[v]; } } } // dimming if (dimming < target_dimming) { dimming += STEP; if (dimming > target_dimming) { dimming = target_dimming; } } if (dimming > target_dimming) { dimming -= STEP; if (dimming < target_dimming) { dimming = target_dimming; } } /* // debug - new values Serial.println(greenval); Serial.println(redval); Serial.println(blueval); Serial.println(whiteval); Serial.println(target_greenval); Serial.println(target_redval); Serial.println(target_blueval); Serial.println(target_whiteval); Serial.println("+++++++++++++++"); */ // set actual pin values for (int i = 0; i < NUM_CHANNELS; i++) { if (isOn) { // normal fading //analogWrite(channels[i], dimming / 100.0 * values[i]); //Fading with corrected values see https://diarmuid.ie/blog/pwm-exponential-led-fading-on-arduino-or-other-platforms/ analogWrite(channels[i], dimming / 100.0 * converted_values[values[i]]); } else { analogWrite(channels[i], 0); } } } // converts incoming color string to actual (int) values // ATTENTION this currently does nearly no checks, so the format needs to be exactly like domoticz sends the strings void inputToRGBW(const char * input) { Serial.print("Got color value of length: "); Serial.println(strlen(input)); if (strlen(input) == 6) { Serial.println("new rgb value"); target_values[0] = fromhex (& input [0]); target_values[1] = fromhex (& input [2]); target_values[2] = fromhex (& input [4]); target_values[3] = 0; } else if (strlen(input) == 9) { Serial.println("new rgbw value"); target_values[0] = fromhex (& input [1]); // ignore # as first sign target_values[1] = fromhex (& input [3]); target_values[2] = fromhex (& input [5]); target_values[3] = fromhex (& input [7]); } else { Serial.println("Wrong length of input"); } Serial.print("New color values: "); Serial.println(input); for (int i = 0; i < NUM_CHANNELS; i++) { Serial.print(target_values[i]); Serial.print(", "); } Serial.println(""); Serial.print("Dimming: "); Serial.println(dimming); } // converts hex char to byte byte fromhex (const char * str) { char c = str [0] - '0'; if (c > 9) c -= 7; int result = c; c = str [1] - '0'; if (c > 9) c -= 7; return (result << 4) | c; }
-
RE: π¬ OH MySensors RGBW Controller
Thx. Those new features, however, are kind of a workaround. It would have been better if the node could request the V_RGBW value directly. MySensors supports this, but domoticz doesn't seem to. I have testet this and domoticz always returned "0" as value. And because you and me are both using domoticz, I decided to implement this feature using V_VAR1-3.
I am still thinking about the fading. I think we could get better colors if we could compensate the non linear dimming of the LEDs. With the actual sketch colors composed of mid range values could be wrong because every PWM value above 150 or so looks like almost full power. So 00AAFF almost looks like 00FFFF. AA has a value of 170 where FF is 255. This should make a big difference.
-
RE: π¬ OH MySensors RGBW Controller
As promised I had a look at the sketch. The node can now save and restore values for rgbw, dimming and status to/from the controller. I had a look at the non linear fading, too. I got it partially working and refreshed my math knowledge a lot.
In the end I removed the code for it because it made the sketch much more complicated and I didn't like the results. The formula from the original sketch was ok for fading a single LED from 0% to 100%. It didn't cover other starting values and the combination of the colors. IMHO only the dimming can be done non linear without problems. For this I would use a static table of PWM values and percent values. Doing the log calculations on the pro mini seems to be too slow for a smooth fading. I saw massive flickering.Here is the sketch:
/** Based on the MySensors Project: http://www.mysensors.org This sketch controls a (analog)RGBW strip by listening to new color values from a (domoticz) controller and then fading to the new color. Version 1.1 - Added save/restore of values to/from controller, removed non linear fading code Version 1.0 - Changed pins and gw definition Version 0.9 - Oliver Hilsky **/ #define MY_DEBUG #define SN "RGBW 01" #define SV "1.1" #define MY_RADIO_NRF24 // change the pins to free up the pwm pin for led control #define MY_RF24_CE_PIN 4 //<-- NOTE!!! changed, the default is 9 #define MY_RF24_CS_PIN 10 // default is 10 // Set LOW transmit power level as default, if you have an amplified NRF-module and // power your radio separately with a good regulator you can turn up PA level. #define MY_RF24_PA_LEVEL RF24_PA_LOW //Uncomment to enable repeater mode //#define MY_REPEATER_FEATURE //Uncomment to assign static node ID //#define MY_NODE_ID 9 // Load mysensors library #include <MySensors.h> // Load Serial Peripheral Interface library #include <SPI.h> // Arduino pin attached to driver pins #define RED_PIN 3 #define WHITE_PIN 9 #define GREEN_PIN 5 #define BLUE_PIN 6 #define NUM_CHANNELS 4 // how many channels, RGBW=4 RGB=3... #define CHILD_ID 1 // Smooth stepping between the values #define STEP 1 #define INTERVAL 10 MyMessage lastvalueMsg(CHILD_ID, V_VAR1); MyMessage lastisonMsg(CHILD_ID, V_VAR2); MyMessage lastdimmMsg(CHILD_ID, V_VAR3); // Stores the current color settings byte channels[4] = {RED_PIN, GREEN_PIN, BLUE_PIN, WHITE_PIN}; byte values[4] = {0, 0, 0, 0}; byte target_values[4] = {0, 0, 0, 0}; // stores dimming level byte dimming = 100; byte target_dimming = 100; // tracks if the strip should be on of off boolean isOn = false; // tracks if the strip's last status was off. This overrides isOn at startup boolean wasOff = true; //tracks if the old values have bben requested from the controller. This prevents the request from being send multipΓle times in the main loop. boolean valuesrequested = false; // time tracking for updates unsigned long lastupdate = millis(); void setup() { // Set all channels to output (pin number, type) for (int i = 0; i < NUM_CHANNELS; i++) { pinMode(channels[i], OUTPUT); } // debug if (isOn) { Serial.println("RGBW is running..."); } } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo(SN, SV); // Register this device as Waterflow sensor present(CHILD_ID, S_RGBW_LIGHT, SN, true); } void loop() { if (!valuesrequested) { // get old values if this is just a restart Serial.println("Requesting old values..."); //Request RGBW values request( CHILD_ID, V_VAR1 ); wait(200); //Request Status request( CHILD_ID, V_VAR2 ); wait(200); //Request dimm level request( CHILD_ID, V_VAR3 ); valuesrequested = true; } // set the new light colors if (millis() > lastupdate + INTERVAL) { updateLights(); lastupdate = millis(); } } // callback function for incoming messages void receive(const MyMessage &message) { Serial.print("Got a message - "); Serial.print("Messagetype is: "); Serial.println(message.type); // acknoledgment if (message.isAck()) { Serial.println("Got ack from gateway"); } // new dim level else if (message.type == V_DIMMER or message.type == V_VAR3) { Serial.println("Dimming to "); Serial.println(message.getString()); target_dimming = message.getByte(); send(lastdimmMsg.set(target_dimming)); if (!wasOff) { // a new dimmer value also means on, no seperate signal gets send (by domoticz) isOn = true; send(lastisonMsg.set(isOn)); } } // on / off message else if (message.type == V_STATUS or message.type == V_VAR2) { Serial.print("Turning light "); isOn = message.getInt(); if (isOn) { Serial.println("on"); wasOff = false; } else { Serial.println("off"); } send(lastisonMsg.set(isOn)); } // new color value else if (message.type == V_RGBW or message.type == V_VAR1) { const char * rgbvalues = message.getString(); send(lastvalueMsg.set(rgbvalues)); inputToRGBW(rgbvalues); if (!wasOff) { // a new color also means on, no seperate signal gets send (by domoticz); needed e.g. for groups isOn = true; send(lastisonMsg.set(isOn)); } } } // this gets called every INTERVAL milliseconds and updates the current pwm levels for all colors void updateLights() { // update pin values -debug //Serial.println(greenval); //Serial.println(redval); //Serial.println(blueval); //Serial.println(whiteval); //Serial.println(target_greenval); //Serial.println(target_redval); //Serial.println(target_blueval); //Serial.println(target_whiteval); //Serial.println("+++++++++++++++"); // for each color for (int v = 0; v < NUM_CHANNELS; v++) { if (values[v] < target_values[v]) { values[v] += STEP; if (values[v] > target_values[v]) { values[v] = target_values[v]; } } if (values[v] > target_values[v]) { values[v] -= STEP; if (values[v] < target_values[v]) { values[v] = target_values[v]; } } } // dimming if (dimming < target_dimming) { dimming += STEP; if (dimming > target_dimming) { dimming = target_dimming; } } if (dimming > target_dimming) { dimming -= STEP; if (dimming < target_dimming) { dimming = target_dimming; } } /* // debug - new values Serial.println(greenval); Serial.println(redval); Serial.println(blueval); Serial.println(whiteval); Serial.println(target_greenval); Serial.println(target_redval); Serial.println(target_blueval); Serial.println(target_whiteval); Serial.println("+++++++++++++++"); */ // set actual pin values for (int i = 0; i < NUM_CHANNELS; i++) { if (isOn) { // normal fading analogWrite(channels[i], dimming / 100.0 * values[i]); } else { analogWrite(channels[i], 0); } } } // converts incoming color string to actual (int) values // ATTENTION this currently does nearly no checks, so the format needs to be exactly like domoticz sends the strings void inputToRGBW(const char * input) { Serial.print("Got color value of length: "); Serial.println(strlen(input)); if (strlen(input) == 6) { Serial.println("new rgb value"); target_values[0] = fromhex (& input [0]); target_values[1] = fromhex (& input [2]); target_values[2] = fromhex (& input [4]); target_values[3] = 0; } else if (strlen(input) == 9) { Serial.println("new rgbw value"); target_values[0] = fromhex (& input [1]); // ignore # as first sign target_values[1] = fromhex (& input [3]); target_values[2] = fromhex (& input [5]); target_values[3] = fromhex (& input [7]); } else { Serial.println("Wrong length of input"); } Serial.print("New color values: "); Serial.println(input); for (int i = 0; i < NUM_CHANNELS; i++) { Serial.print(target_values[i]); Serial.print(", "); } Serial.println(""); Serial.print("Dimming: "); Serial.println(dimming); } // converts hex char to byte byte fromhex (const char * str) { char c = str [0] - '0'; if (c > 9) c -= 7; int result = c; c = str [1] - '0'; if (c > 9) c -= 7; return (result << 4) | c; }
-
RE: Radio FAIL after ~3 weeks [SOLVED]
@flopp said:
ave a capacitor.
I will add power from other source.Do you think I can initialize it with another Arduino but use VCC and GND from Arduino Nano, then connect back all cables from Arduino Nano and then it will work?
I don't want to restart Arduino Nano.
If you connect ground of both Arduinos, this should work. You should assign the other Arduino the same node id statically. Let me know the result if you try.
-
RE: Radio FAIL after ~3 weeks [SOLVED]
Changing the radio online leaves it completely uninitialized. This proofs nothing.
This behaviour can be caused by problems with the power supply of the nrf. Did you add a capacitor? -
RE: π¬ OH MySensors RGBW Controller
If I find the time, I will clean it up. I want to have a look at the non linear fading. IMHO the initial settings need to be customized, too. Instead of switching the white LEDs on the node could request the values from the controller (if possible) or from eeprom.
-
RE: π¬ OH MySensors RGBW Controller
Great.Can you post the complete 2.0 sketch, please? I am going to upgrade and this would be a good starting point.
-
RE: π¬ OH MySensors RGBW Controller
The node always starts with white on. This is normal behaviour.
-
RE: MySensors shield and RGBW Controller
Yes, this was the problem we already discussed in the other thread.
-
RE: π¬ OH MySensors RGBW Controller
You have to fix the following part:
for (int i = 0; i < NUM_CHANNELS; i++) { if (isOn) { // normal fading //analogWrite(channels[i], dimming / 100.0 * values[i]); // non linear fading, idea from https://diarmuid.ie/blog/pwm-exponential-led-fading-on-arduino-or-other-platforms/ analogWrite(channels[i], pow (2, (dimming / R)) - 1); } else { analogWrite(channels[i], 0); } }
Corrected Version
for (int i = 0; i < NUM_CHANNELS; i++) { if (isOn) { // normal fading analogWrite(channels[i], dimming / 100.0 * values[i]); // non linear fading, idea from https://diarmuid.ie/blog/pwm-exponential-led-fading-on-arduino-or-other-platforms/ //analogWrite(channels[i], pow (2, (dimming / R)) - 1); } else { analogWrite(channels[i], 0); } }
Or else all channels are set to the Value of dimming. The sketch on openhardware.io is broken, too.
-
RE: π¬ OH MySensors RGBW Controller
I got my v1.3 pcbs from Smart Prototyping. Quality is good. The controller works fine BUT the sketch version in your github repo is broken. Seems like the non linear fading part never got finished. I am now using linear fading and the sketch is working.
-
RE: MySensors shield and RGBW Controller
I tried the new version of the pcb. I think the hardware is just working fine. However I have a problem with the sketch or domoticz. I can switch the light on and off. This switches all channels. So the FETs and the Arduino seem to work fine. I can dim the light, too. What does not work is the color selection with domoticz. If I select another color nothing happens. All 4 channels seem to habe the same level all the time. Any idea?
-
RE: Experimental: ESP Easy MySensors Edition
@martinus The last commit was in 2015. Is this going to be developed any further? I like the approach and would give it a try, if the project was still alive.
-
RE: Monitor if an outlet has power - send email
You could use an optocoupler. Limit the current by using a X2 capacitor. Like this: http://www.mikrocontroller.net/articles/Datei:230V_am_uC_Port-Pin.png
-
RE: Motion Sensor triggering on its own
@robosensor Have you tried to enable the ibternal pullup for the pin?
-
RE: Motion Sensor triggering on its own
I have solved this by reading the status of the HC-SR501 twice. Works finde for me.
boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; Serial.println(tripped); if (tripped==1){ //wait delay(100); //read the pin again tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; if (tripped==1){ gw.send(msg2.set(tripped?"1":"0")); // Send tripped value to gw } }
-
RE: 110v-230v AC to Mysensors PCB board
I am facing a little problem with the fuses. I am using these:
5V DC: http://www.ebay.de/itm/321697892220?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT
When I connect the pcb to power the LED on the Arduino flashes and then the 500 mA Fuse in the 5V circuit dies. I am now using the 300 mA resetable Fuse for the 5V part as well, which seems to work without problems. How can it be, that the 500 mA fuse dies and the 300 mA fuse does not?
-
RE: Office plant monitoring
@mfalkvidd At the moment I am testing a modified version of the sketch which always does two readings. I don't think this will have a big impact on the battery life because most power is consumend by the nrf and not by the sensor. Or am I wrong? The pullups are rated at 10k Ohm. The sensors resistance will be about the same in average. So we talk about 20k at 3V which is 0.15 mA. The nrf uses abot 15 mA when sending.
-
RE: Office plant monitoring
Just built this sensor and it is working great. However I am seeing different results with every run. It seems as if the value is always higher with one polarity than with the other one. Is this normal?
-
RE: 110v-230v AC to Mysensors PCB board
Most SSRs cannot be checked this way because they can only switch AC and not DC. See https://en.wikipedia.org/wiki/Zero_cross_circuit
-
RE: 110v-230v AC to Mysensors PCB board
Just ordered 10 pcs of this board. Great Job!
-
RE: Domoticz using wrong message Type
Ok, solved it myself. V_LOCK_STATUS is wrong in this case. The expected subtype for S_DOOR is V_TRIPPED. Changed it in the sketch and everything works as expected.