Navigation

    • Register
    • Login
    • Search
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. Dbagioni
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Dbagioni

    @Dbagioni

    Avid DIY guy......Still learning the code and programming sides of things, Im a soldering iron, oscilloscope, resistor and transistor guy.

    4
    Reputation
    24
    Posts
    482
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online
    Location Connecticut, USA

    Dbagioni Follow

    Best posts made by Dbagioni

    • Having an issue with message signing.

      Hello again

      I am having an issue with message signing. I have begun to expand my mysensors devices to include some actuators and sensors I want to secure. I have tried to get this to work, but keep hitting a wall.

      Here;s my set up for my testing. My mega Ethernet gateway with software backed signing enabled, and my Uno set up as a mock relay actuator with software backed signing enabled. If I set up MY_SIGNING_SIMPLE_PASSWD "blahblahblah", everything works great. As soon as thats disabled...nothing wants to talk to each other.

      How I have programmed the devices. On the gateway I ran the personalizer sketch and generated the HMAC and AES keys. I copied that info into the proper sections, disabled generate keys and enabled personalize soft. I then ran the personalizer on both the gateway and the node and received a "Succes" message.

      This is my gateway sketch.

      /**
       * 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 Tomas Hozza <thozza@gmail.com>
       *
       *
       * DESCRIPTION
       * The EthernetGateway sends data received from sensors to the ethernet link.
       * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
       *
       * The GW code is designed for Arduino 328p / 16MHz.  ATmega168 does not have enough memory to run this program.
       *
       * LED purposes:
       * - To use the feature, uncomment MY_DEFAULT_xxx_LED_PIN in the sketch below
       * - 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/ethernet_gateway for wiring instructions.
       *
       */
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG
      #define MY_DEBUG_VERBOSE_SIGNING
      
      // Enable and select radio type attached
      #define MY_RADIO_RF24
      
      // Enable gateway ethernet module type
      #define MY_GATEWAY_W5100
      
      // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
      //#define MY_W5100_SPI_EN 4
      
      // Enable Soft SPI for NRF radio (note different radio wiring is required)
      // The W5100 ethernet module seems to have a hard time co-operate with
      // radio on the same spi bus.
      #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
      #define MY_SOFTSPI
      #define MY_SOFT_SPI_SCK_PIN 14
      #define MY_SOFT_SPI_MISO_PIN 16
      #define MY_SOFT_SPI_MOSI_PIN 15
      #endif
      
      // When W5100 is connected we have to move CE/CSN pins for NRF radio
      #ifndef MY_RF24_CE_PIN
      #define MY_RF24_CE_PIN 5
      #endif
      #ifndef MY_RF24_CS_PIN
      #define MY_RF24_CS_PIN 6
      #endif
      
      // Enable UDP communication
      //#define MY_USE_UDP  // If using UDP you need to set MY_CONTROLLER_IP_ADDRESS below
      
      // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
      #define MY_IP_ADDRESS 192,168,1,69
      
      // If using static ip you can define Gateway and Subnet address as well
      #define MY_IP_GATEWAY_ADDRESS 192,168,1,1
      #define MY_IP_SUBNET_ADDRESS 255,255,255,0
      
      // Renewal period if using DHCP
      //#define MY_IP_RENEWAL_INTERVAL 60000
      
      // The port to keep open on node server mode / or port to contact in client mode
      #define MY_PORT 5003//
      
      // 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, 254
      
      // The MAC address can be anything you want but should be unique on your network.
      // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
      // Note that most of the Ardunio examples use  "DEAD BEEF FEED" for the MAC address.
      #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
      
      // 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_MAX
      
      // 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 90
      
      // Digital pin used for inclusion mode button
      #define MY_INCLUSION_MODE_BUTTON_PIN  3
      
      // Set blinking period
      #define MY_DEFAULT_LED_BLINK_PERIOD 300
      
      // Inverses the behavior of leds
      #define MY_WITH_LEDS_BLINKING_INVERSE
      
      // Flash leds on rx/tx/err
      // Uncomment to override default HW configurations
      #define MY_DEFAULT_ERR_LED_PIN 40  // Error led pin
      #define MY_DEFAULT_RX_LED_PIN  42  // Receive led pin
      #define MY_DEFAULT_TX_LED_PIN  44  // Transmit led pin
      
      #if defined(MY_USE_UDP)
      #include <EthernetUdp.h>
      #endif
      
      #define MY_SIGNING_SOFT
      #define MY_SIGNING_SOFT_RANDOMSEED_PIN 7
      #define MY_SIGNING_SIMPLE_PASSWD "MyEmmaBemma2015" 
      #define MY_SIGNING_WEAK_SECURITY
      
      #include <Ethernet.h>
      #include <MyConfig.h>
      #include <MySensors.h>
      
      void setup()
      {
          // Setup locally attached sensors
      }
      
      void presentation()
      {
          // Present locally attached sensors here
      }
      
      void loop()
      {
          // Send locally attached sensors data here
      }
      

      When I run the gateway I get the following message in the serial monitor

      8732 TSF:MSG:BC
      8734 TSF:MSG:FPAR REQ,ID=22
      8736 TSF:CKU:OK,FCTRL
      8738 TSF:MSG:GWL OK
      9288 SGN:SKP:MSG CMD=3,TYPE=8
      9293 TSF:MSG:SEND,0-0-22-22,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
      9300 TSF:MSG:READ,6-6-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
      9306 TSF:MSG:PINGED,ID=6,HP=1
      9308 SGN:SGN:NREQ=6
      9312 TSF:MSG:SEND,0-0-6-6,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=OK:1
      10048 TSF:MSG:READ,6-6-0,s=3,c=1,t=1,pt=7,l=5,sg=0:53.3
      10778 TSF:MSG:READ,22-22-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
      10783 TSF:MSG:PINGED,ID=22,HP=1
      10786 SGN:SKP:MSG CMD=3,TYPE=25
      10791 TSF:MSG:SEND,0-0-22-22,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=OK:1
      10813 TSF:MSG:READ,22-22-0,s=255,c=3,t=15,pt=6,l=2,sg=0:0101
      10819 SGN:PRE:SGN REQ,FROM=22
      10822 SGN:PRE:SGN NREQ,TO=22
      10824 SGN:PRE:WHI NREQ,TO=22
      10827 SGN:SKP:MSG CMD=3,TYPE=15
      10834 TSF:MSG:SEND,0-0-22-22,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
      10842 SGN:PRE:XMT,TO=22
      10846 TSF:MSG:READ,22-22-0,s=255,c=0,t=17,pt=0,l=5,sg=0:2.3.0
      10856 TSF:MSG:READ,22-22-0,s=255,c=3,t=6,pt=1,l=1,sg=0:0
      12869 TSF:MSG:READ,22-22-0,s=255,c=3,t=11,pt=0,l=5,sg=0:Relay
      12879 TSF:MSG:READ,22-22-0,s=255,c=3,t=12,pt=0,l=3,sg=0:2.0
      12890 TSF:MSG:READ,22-22-0,s=1,c=0,t=3,pt=0,l=0,sg=0:
      12901 TSF:MSG:READ,22-22-0,s=255,c=3,t=26,pt=1,l=1,sg=0:2
      12906 SGN:SKP:MSG CMD=3,TYPE=16
      12913 TSF:MSG:SEND,0-0-22-22,s=255,c=3,t=16,pt=0,l=0,sg=0,ft=0,st=OK:
      12919 SGN:SGN:NCE REQ,TO=22
      12940 TSF:MSG:READ,22-22-0,s=255,c=3,t=17,pt=6,l=25,sg=0:<NONCE>
      12946 SGN:NCE:FROM=22
      12948 SGN:BND:NONCE=B8E06B367486872EC1CE2CADBF969CAAE127BADED76DF0095DAAAAAAAAAAAAAA
      13035 SGN:BND:HMAC=0699DD1F9CE2830EC9F09D858D8AB9627DDA55AFBE587C1115A95C962E0AFFF1
      13043 SGN:SGN:SGN
      13048 TSF:MSG:SEND,0-0-22-22,s=255,c=3,t=27,pt=1,l=1,sg=1,ft=0,st=OK:1
      

      Here is my node sketch

      /**
       * 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
       **** Dave Version 1
       */
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG
      #define MY_DEBUG_VERBOSE_SIGNING
      
      // Enable and select radio type attached
      #define MY_RADIO_RF24
      //#define MY_RADIO_NRF5_ESB
      //#define MY_RADIO_RFM69
      //#define MY_RADIO_RFM95
      
      // Enable repeater functionality for this node
      //#define MY_REPEATER_FEATURE
      
      // Inverses the behavior of leds
      #define MY_WITH_LEDS_BLINKING_INVERSE
      
      // Flash leds on rx/tx/err
      // Uncomment to override default HW configurations
      #define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
      #define MY_DEFAULT_RX_LED_PIN  5  // Receive led pin
      #define MY_DEFAULT_TX_LED_PIN  6  // the PCB, on board LED
      
      #define MY_NODE_ID 22
      
      // Select soft/hardware signing method
      #define MY_SIGNING_SOFT  //SOFTWARE BASED
      //#define MY_SIGNING_ATSHA204 //HARDWARE BASED
      
      #define MY_SIGNING_REQUEST_SIGNATURES
      
      //Hardware configuration for signing services
      #define MY_SIGNING_SOFT_RANDOMSEED_PIN 7
      //#define MY_SIGNING_ATSHA204_PIN A3
      
      #define MY_SIGNING_SIMPLE_PASSWD "MyEmmaBemma2015"
      
      #include <MyConfig.h>
      #include <MySensors.h>
      #include <SPI.h>
      
      #define RELAY_1 3 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
      #define NUMBER_OF_RELAYS 1// Total number of attached relays
      #define RELAY_ON 1  // GPIO value to write to turn on attached relay
      #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
      
      
      void before()
      {
          for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
              // Then set relay pins in output mode
              pinMode(pin, OUTPUT);
              // Set relay to last known state (using eeprom storage)
              digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
          }
      }
      
      void setup()
      {
      
      }
      
      void presentation()
      {
          // Send the sketch version information to the gateway and Controller
          sendSketchInfo("Relay", "2.0");
      
          for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
              // Register all sensors to gw (they will be created as child devices)
              present(sensor, S_BINARY);
          }
      }
      
      
      void loop()
      {
      
      }
      
      void receive(const MyMessage &message)
      {
          // We only expect one type of message from controller. But we better check anyway.
          if (message.type==V_STATUS) {
              // Change relay state
              digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
              // Store state in eeprom
              saveState(message.sensor, message.getBool());
              // Write some debug info
              Serial.print("Incoming change for sensor:");
              Serial.print(message.sensor);
              Serial.print(", New status: ");
              Serial.println(message.getBool());
          }
      }
      

      And this is the serial monitor output.

      |  \/  |_   _/ ___|  ___ _ __  ___  ___  _ __ ___
      | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __|
      | |  | | |_| |___| |  __/ | | \__ \  _  | |  \__ \
      |_|  |_|\__, |____/ \___|_| |_|___/\___/|_|  |___/
              |___/                      2.3.0
      
      16 MCO:BGN:INIT NODE,CP=RNNNAS--,VER=2.3.0
      25 MCO:BGN:BFR
      50 !SGN:PER:TAMPERED
      86 SGN:INI:BND OK
      87 TSM:INIT
      88 TSF:WUR:MS=0
      95 TSM:INIT:TSP OK
      97 TSM:INIT:STATID=22
      102 TSF:SID:OK,ID=22
      104 TSM:FPAR
      105 SGN:SGN:NREQ=255
      142 TSF:MSG:SEND,22-22-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      954 TSF:MSG:READ,0-0-22,s=255,c=3,t=8,pt=1,l=1,sg=0:0
      959 SGN:SKP:MSG CMD=3,TYPE=8
      962 TSF:MSG:FPAR OK,ID=0,D=1
      988 TSF:MSG:READ,6-6-22,s=255,c=3,t=8,pt=1,l=1,sg=0:1
      992 SGN:SKP:MSG CMD=3,TYPE=8
      1762 TSF:MSG:READ,1-1-22,s=255,c=3,t=8,pt=1,l=1,sg=0:1
      1767 SGN:SKP:MSG CMD=3,TYPE=8
      2150 TSM:FPAR:OK
      2151 TSM:ID
      2152 TSM:ID:OK
      2154 TSM:UPL
      2155 SGN:SGN:NREQ=0
      2161 TSF:MSG:SEND,22-22-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
      2176 TSF:MSG:READ,0-0-22,s=255,c=3,t=25,pt=1,l=1,sg=0:1
      2181 SGN:SKP:MSG CMD=3,TYPE=25
      2184 TSF:MSG:PONG RECV,HP=1
      2187 TSM:UPL:OK
      2188 TSM:READY:ID=22,PAR=0,DIS=1
      2191 SGN:PRE:SGN REQ
      2193 SGN:PRE:WHI NREQ
      2195 SGN:SGN:NREQ=0
      2198 TSF:MSG:SEND,22-22-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0101
      2205 SGN:PRE:XMT,TO=0
      2207 SGN:PRE:WAIT GW
      2217 TSF:MSG:READ,0-0-22,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
      2223 SGN:SKP:MSG CMD=3,TYPE=15
      2226 SGN:SGN:NREQ=0
      2230 TSF:MSG:SEND,22-22-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.3.0
      2236 SGN:SGN:NREQ=0
      2242 TSF:MSG:SEND,22-22-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
      4248 SGN:SGN:NREQ=0
      4253 TSF:MSG:SEND,22-22-0-0,s=255,c=3,t=11,pt=0,l=5,sg=0,ft=0,st=OK:Relay
      4260 SGN:SGN:NREQ=0
      4264 TSF:MSG:SEND,22-22-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:2.0
      4271 SGN:SGN:NREQ=0
      4277 TSF:MSG:SEND,22-22-0-0,s=1,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
      4283 MCO:REG:REQ
      4284 SGN:SGN:NREQ=0
      4290 TSF:MSG:SEND,22-22-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
      4297 TSF:MSG:READ,0-0-22,s=255,c=3,t=16,pt=0,l=0,sg=0:
      4302 SGN:SKP:MSG CMD=3,TYPE=16
      4320 SGN:SGN:NREQ=0
      4327 TSF:MSG:SEND,22-22-0-0,s=255,c=3,t=17,pt=6,l=25,sg=0,ft=0,st=OK:<NONCE>
      4334 SGN:NCE:XMT,TO=22
      4468 TSF:MSG:READ,0-0-22,s=255,c=3,t=27,pt=1,l=1,sg=1:1
      4473 !SGN:VER:STATE
      4475 !TSF:MSG:SIGN VERIFY FAIL
      4477 MCO:BGN:STP
      4480 MCO:BGN:INIT OK,TSP=1
      

      What am I missing here?

      posted in Development
      Dbagioni
      Dbagioni
    • RE: Trying to get a dual mode sleep going.

      @skywatch

      Perfect - works like a charm.

      Thank you

      Dave

      posted in Troubleshooting
      Dbagioni
      Dbagioni
    • MySensors 2.3.0 on Mega 2560 Ethernet Gateway

      All
      A little while ago I had upgraded to MySensors 2.3.0 with horrible results....my 18 node network went kablooey. I couldn't get anything stable to save my own life. I was getting 30-90 minutes of runtime on the gateway before it was shutting down and going off line. I of course did this at the exact same time I was rebuilding my gateway, transitioning to the Mega 2560 from thr UNO 328 due to memory and lag issues. To top it all off I am running an NRF24 LNA/PNA radio at MAX because of distance and placement issues.

      Initial gateway

      What I have found was needed to stabilize the gateway.....POWER POWER POWER! It became the Achilles heel of my project. I was initially feeding into the radio then sending power to the Mega via its VCC input (this was ok for the UNO). Voltage going over was good, current wasn't and the gateway would shutdown no matter what the radio power settings were of which radio chip I used. So I switched to a 12v 2.5A power supply and wyed it one connection to the radio board (which has its own voltage regulator) and the other to the Mega's DC jack. Second issue I noted was heat - the Mega runs hotter than the UNO did. I had 130 degrees Fahrenheit on the processor chip. I solved that with a heat sink I had from a raspberry pi and adding a small fan fed from the Mega's 5v pin placed at the back of the Mega. Since that, chip is a cool 80 degrees. I suspect since Im using the Ethernet shield that played a big role in the Mega heating up and the fan really helped.

      Gateway Attempt 3

      The Fan is seen to the immediate left of the LAN jack.
      The toggle switch serves 2 functions...when pushed to the right it resets the gateway, to the left enables inclusion mode. The three LEDs are TX/RX/ERR.

      Hope this helps folks. I will add my wiring and code when I get a chance.

      Heres the gateway mounted in my Ubuntu box, which runs my home media server and OpenHab.

      alt text

      Happy Building and THANK YOU to everyone who has posted ideas and code snipets that made this possible.

      posted in General Discussion
      Dbagioni
      Dbagioni

    Latest posts made by Dbagioni

    • RE: Did HA just give up on MySensors?

      @OldSurferDude
      The complete wipe seems to have worked. I also changed the version on HA's integration to 2.3 to match the MySensors library I use on the sketches.
      Thanks for the workaround.

      posted in Home Assistant
      Dbagioni
      Dbagioni
    • RE: Did HA just give up on MySensors?

      My set up is via a Serial gateway. MySensors nodes/gateway are running V2.3, but my HA only is listing version as 1.4, not sure if that could be part of my issue. Im going to try shutting down the gateway, uninstalling the intergration and then going form there. Presently Im only seeing traffic from one sensor.

      posted in Home Assistant
      Dbagioni
      Dbagioni
    • Did HA just give up on MySensors?

      Ive been running HA for about a year now. Around July(ish) I noticed Mysensors just suddenly seemed to only work with nodes that were registered prior. None of my new sensors or switches are discovered and many of my sensors have gone dead. Any thoughts or fixes?

      posted in Home Assistant
      Dbagioni
      Dbagioni
    • HA throwing invalid serial port message on new HA install

      All
      Im new to HA. Ive just transitioned from another platform to HA. Im running my HA on a Ubuntu 20.04 server, and installled the HA via Docker.
      When I search I can find me serial gateway on /dev/ttyUSB0, but when I enter the info into the HA integration I get "invalid serial port". Can anyone give me a clue as to how to get this running?

      posted in Home Assistant
      Dbagioni
      Dbagioni
    • RE: OH3 - MySensors Binding

      @vores8 just down loaded it and installed. Showing up online with my serial gateway. Gonna let it run but looks like it’s working now. Nice work, and thank you.

      posted in OpenHAB
      Dbagioni
      Dbagioni
    • RE: Safe AC dimmer with code

      The code I posted is the raw code for the zero-cross dimmer. When I had tried to merge the "dimmer with rotary encoder" sketch and the zero-cross code I had wired it up with the ZC pin as 2 and the PWM pin on 3. Encoder was wired: SW pin on 4, CLK pin on 5 and CE pin on 6. 7/8/A2 were used for status LED's.

      I was running it with an older NANO with the 328.

      posted in My Project
      Dbagioni
      Dbagioni
    • Safe AC dimmer with code

      All

      Has anyone found a safe and reliable dimmer code to with with an AC dimmer? I have been racking my brains and cant find a good working code. I'm using commercially made pwm/zero cross dimmers from RobotDYN(see picture). I can get a 12 volt version working but have been unsuccessful in getting this to work. Disclaimer - Im a hardware guy not a code guy.
      alt text

      My end goal would be to get it working with the rotary encoder. This is the RAW pwm/zero crossing code.

      #include "hw_timer.h"
      #include <Time.h>
      #include <TimeLib.h>
      #include <TimeAlarms.h>
      
      //Pin Setups
      const int zcPin = 12; //zero-cross detection pin D6
      const int pwmPin = 13;  //pwm pin - fires the triac D7
      
      //Dimmer Settings including fades.
      byte fade = 1;
      byte state = 1;
      byte tarBrightness = 255; //"target" brightness - going to have go convert this to a precentage for OH
      byte curBrightness = 0; //current brightness level
      byte zcState = 0; // 0 = ready; 1 = processing;
      
      char lvl[50];
      
      void setup() {
        Serial.begin(115200); //Sets the data rate in bits per second (baud) for serial data transmission.
      
        //Dimmer pins -set up the pwm and zero cross pins
        pinMode(zcPin, INPUT_PULLUP);
        pinMode(pwmPin, OUTPUT);
        attachInterrupt(zcPin, zcDetectISR, RISING);    // Attach an Interupt to Pin 2 (interupt 0) for Zero Cross Detection
        hw_timer_init(NMI_SOURCE, 0);
        hw_timer_set_func(dimTimerISR);
      
       } // END SETUP
      
      void dimTimerISR() {
        if (fade == 1) {
          if (curBrightness > tarBrightness || (state == 0 && curBrightness > 0)) {
            --curBrightness;
          }
          else if (curBrightness < tarBrightness && state == 1 && curBrightness < 255) {
            ++curBrightness;
          }
        }
        else {
          if (state == 1) {
            curBrightness = tarBrightness;
          }
          else {
            curBrightness = 0;
          }
        }
      
        if (curBrightness == 0) {
          state = 0;
          digitalWrite(pwmPin, 0);
        }
        else if (curBrightness == 255) {
          state = 1;
          digitalWrite(pwmPin, 1);
        }
        else {
          digitalWrite(pwmPin, 1);
        }
      
        zcState = 0;
      }
      
      void zcDetectISR() {
        if (zcState == 0) {
          zcState = 1;
      
          if (curBrightness < 255 && curBrightness > 0) {
            digitalWrite(pwmPin, 0);
      
            int dimDelay = 30 * (255 - curBrightness) + 400;//400
            hw_timer_arm(dimDelay);
          }
        }
      }
      

      Can anyone help?

      posted in My Project
      Dbagioni
      Dbagioni
    • Status LED issues with Raspberry Pi gateway

      Morning all.
      Ive just had to completely rebuild my openhab and mysensors set up. Im running OH 2.4 on a Raspberry Pi 3B+, with the MySensors 2.4 bindings. Gateway compiles and runs fine....butttt I acidentaly configured --my-leds-blinking-inverse. How do i unconfigure it.

      Second led issue. The red error led is always lit, no blink, just steady burn. It is wired as noted in the guide.

      Should i reneter the options and then remake the gate way? Im not sure how to go about this I was using arduinos before and there you just deleted the options from the sketch and reloaded it.

      Thanks for the advice in advance

      posted in OpenHAB
      Dbagioni
      Dbagioni
    • Having an issue with message signing.

      Hello again

      I am having an issue with message signing. I have begun to expand my mysensors devices to include some actuators and sensors I want to secure. I have tried to get this to work, but keep hitting a wall.

      Here;s my set up for my testing. My mega Ethernet gateway with software backed signing enabled, and my Uno set up as a mock relay actuator with software backed signing enabled. If I set up MY_SIGNING_SIMPLE_PASSWD "blahblahblah", everything works great. As soon as thats disabled...nothing wants to talk to each other.

      How I have programmed the devices. On the gateway I ran the personalizer sketch and generated the HMAC and AES keys. I copied that info into the proper sections, disabled generate keys and enabled personalize soft. I then ran the personalizer on both the gateway and the node and received a "Succes" message.

      This is my gateway sketch.

      /**
       * 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 Tomas Hozza <thozza@gmail.com>
       *
       *
       * DESCRIPTION
       * The EthernetGateway sends data received from sensors to the ethernet link.
       * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
       *
       * The GW code is designed for Arduino 328p / 16MHz.  ATmega168 does not have enough memory to run this program.
       *
       * LED purposes:
       * - To use the feature, uncomment MY_DEFAULT_xxx_LED_PIN in the sketch below
       * - 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/ethernet_gateway for wiring instructions.
       *
       */
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG
      #define MY_DEBUG_VERBOSE_SIGNING
      
      // Enable and select radio type attached
      #define MY_RADIO_RF24
      
      // Enable gateway ethernet module type
      #define MY_GATEWAY_W5100
      
      // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
      //#define MY_W5100_SPI_EN 4
      
      // Enable Soft SPI for NRF radio (note different radio wiring is required)
      // The W5100 ethernet module seems to have a hard time co-operate with
      // radio on the same spi bus.
      #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
      #define MY_SOFTSPI
      #define MY_SOFT_SPI_SCK_PIN 14
      #define MY_SOFT_SPI_MISO_PIN 16
      #define MY_SOFT_SPI_MOSI_PIN 15
      #endif
      
      // When W5100 is connected we have to move CE/CSN pins for NRF radio
      #ifndef MY_RF24_CE_PIN
      #define MY_RF24_CE_PIN 5
      #endif
      #ifndef MY_RF24_CS_PIN
      #define MY_RF24_CS_PIN 6
      #endif
      
      // Enable UDP communication
      //#define MY_USE_UDP  // If using UDP you need to set MY_CONTROLLER_IP_ADDRESS below
      
      // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
      #define MY_IP_ADDRESS 192,168,1,69
      
      // If using static ip you can define Gateway and Subnet address as well
      #define MY_IP_GATEWAY_ADDRESS 192,168,1,1
      #define MY_IP_SUBNET_ADDRESS 255,255,255,0
      
      // Renewal period if using DHCP
      //#define MY_IP_RENEWAL_INTERVAL 60000
      
      // The port to keep open on node server mode / or port to contact in client mode
      #define MY_PORT 5003//
      
      // 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, 254
      
      // The MAC address can be anything you want but should be unique on your network.
      // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
      // Note that most of the Ardunio examples use  "DEAD BEEF FEED" for the MAC address.
      #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
      
      // 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_MAX
      
      // 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 90
      
      // Digital pin used for inclusion mode button
      #define MY_INCLUSION_MODE_BUTTON_PIN  3
      
      // Set blinking period
      #define MY_DEFAULT_LED_BLINK_PERIOD 300
      
      // Inverses the behavior of leds
      #define MY_WITH_LEDS_BLINKING_INVERSE
      
      // Flash leds on rx/tx/err
      // Uncomment to override default HW configurations
      #define MY_DEFAULT_ERR_LED_PIN 40  // Error led pin
      #define MY_DEFAULT_RX_LED_PIN  42  // Receive led pin
      #define MY_DEFAULT_TX_LED_PIN  44  // Transmit led pin
      
      #if defined(MY_USE_UDP)
      #include <EthernetUdp.h>
      #endif
      
      #define MY_SIGNING_SOFT
      #define MY_SIGNING_SOFT_RANDOMSEED_PIN 7
      #define MY_SIGNING_SIMPLE_PASSWD "MyEmmaBemma2015" 
      #define MY_SIGNING_WEAK_SECURITY
      
      #include <Ethernet.h>
      #include <MyConfig.h>
      #include <MySensors.h>
      
      void setup()
      {
          // Setup locally attached sensors
      }
      
      void presentation()
      {
          // Present locally attached sensors here
      }
      
      void loop()
      {
          // Send locally attached sensors data here
      }
      

      When I run the gateway I get the following message in the serial monitor

      8732 TSF:MSG:BC
      8734 TSF:MSG:FPAR REQ,ID=22
      8736 TSF:CKU:OK,FCTRL
      8738 TSF:MSG:GWL OK
      9288 SGN:SKP:MSG CMD=3,TYPE=8
      9293 TSF:MSG:SEND,0-0-22-22,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
      9300 TSF:MSG:READ,6-6-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
      9306 TSF:MSG:PINGED,ID=6,HP=1
      9308 SGN:SGN:NREQ=6
      9312 TSF:MSG:SEND,0-0-6-6,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=OK:1
      10048 TSF:MSG:READ,6-6-0,s=3,c=1,t=1,pt=7,l=5,sg=0:53.3
      10778 TSF:MSG:READ,22-22-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
      10783 TSF:MSG:PINGED,ID=22,HP=1
      10786 SGN:SKP:MSG CMD=3,TYPE=25
      10791 TSF:MSG:SEND,0-0-22-22,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=OK:1
      10813 TSF:MSG:READ,22-22-0,s=255,c=3,t=15,pt=6,l=2,sg=0:0101
      10819 SGN:PRE:SGN REQ,FROM=22
      10822 SGN:PRE:SGN NREQ,TO=22
      10824 SGN:PRE:WHI NREQ,TO=22
      10827 SGN:SKP:MSG CMD=3,TYPE=15
      10834 TSF:MSG:SEND,0-0-22-22,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
      10842 SGN:PRE:XMT,TO=22
      10846 TSF:MSG:READ,22-22-0,s=255,c=0,t=17,pt=0,l=5,sg=0:2.3.0
      10856 TSF:MSG:READ,22-22-0,s=255,c=3,t=6,pt=1,l=1,sg=0:0
      12869 TSF:MSG:READ,22-22-0,s=255,c=3,t=11,pt=0,l=5,sg=0:Relay
      12879 TSF:MSG:READ,22-22-0,s=255,c=3,t=12,pt=0,l=3,sg=0:2.0
      12890 TSF:MSG:READ,22-22-0,s=1,c=0,t=3,pt=0,l=0,sg=0:
      12901 TSF:MSG:READ,22-22-0,s=255,c=3,t=26,pt=1,l=1,sg=0:2
      12906 SGN:SKP:MSG CMD=3,TYPE=16
      12913 TSF:MSG:SEND,0-0-22-22,s=255,c=3,t=16,pt=0,l=0,sg=0,ft=0,st=OK:
      12919 SGN:SGN:NCE REQ,TO=22
      12940 TSF:MSG:READ,22-22-0,s=255,c=3,t=17,pt=6,l=25,sg=0:<NONCE>
      12946 SGN:NCE:FROM=22
      12948 SGN:BND:NONCE=B8E06B367486872EC1CE2CADBF969CAAE127BADED76DF0095DAAAAAAAAAAAAAA
      13035 SGN:BND:HMAC=0699DD1F9CE2830EC9F09D858D8AB9627DDA55AFBE587C1115A95C962E0AFFF1
      13043 SGN:SGN:SGN
      13048 TSF:MSG:SEND,0-0-22-22,s=255,c=3,t=27,pt=1,l=1,sg=1,ft=0,st=OK:1
      

      Here is my node sketch

      /**
       * 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
       **** Dave Version 1
       */
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG
      #define MY_DEBUG_VERBOSE_SIGNING
      
      // Enable and select radio type attached
      #define MY_RADIO_RF24
      //#define MY_RADIO_NRF5_ESB
      //#define MY_RADIO_RFM69
      //#define MY_RADIO_RFM95
      
      // Enable repeater functionality for this node
      //#define MY_REPEATER_FEATURE
      
      // Inverses the behavior of leds
      #define MY_WITH_LEDS_BLINKING_INVERSE
      
      // Flash leds on rx/tx/err
      // Uncomment to override default HW configurations
      #define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
      #define MY_DEFAULT_RX_LED_PIN  5  // Receive led pin
      #define MY_DEFAULT_TX_LED_PIN  6  // the PCB, on board LED
      
      #define MY_NODE_ID 22
      
      // Select soft/hardware signing method
      #define MY_SIGNING_SOFT  //SOFTWARE BASED
      //#define MY_SIGNING_ATSHA204 //HARDWARE BASED
      
      #define MY_SIGNING_REQUEST_SIGNATURES
      
      //Hardware configuration for signing services
      #define MY_SIGNING_SOFT_RANDOMSEED_PIN 7
      //#define MY_SIGNING_ATSHA204_PIN A3
      
      #define MY_SIGNING_SIMPLE_PASSWD "MyEmmaBemma2015"
      
      #include <MyConfig.h>
      #include <MySensors.h>
      #include <SPI.h>
      
      #define RELAY_1 3 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
      #define NUMBER_OF_RELAYS 1// Total number of attached relays
      #define RELAY_ON 1  // GPIO value to write to turn on attached relay
      #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
      
      
      void before()
      {
          for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
              // Then set relay pins in output mode
              pinMode(pin, OUTPUT);
              // Set relay to last known state (using eeprom storage)
              digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
          }
      }
      
      void setup()
      {
      
      }
      
      void presentation()
      {
          // Send the sketch version information to the gateway and Controller
          sendSketchInfo("Relay", "2.0");
      
          for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
              // Register all sensors to gw (they will be created as child devices)
              present(sensor, S_BINARY);
          }
      }
      
      
      void loop()
      {
      
      }
      
      void receive(const MyMessage &message)
      {
          // We only expect one type of message from controller. But we better check anyway.
          if (message.type==V_STATUS) {
              // Change relay state
              digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
              // Store state in eeprom
              saveState(message.sensor, message.getBool());
              // Write some debug info
              Serial.print("Incoming change for sensor:");
              Serial.print(message.sensor);
              Serial.print(", New status: ");
              Serial.println(message.getBool());
          }
      }
      

      And this is the serial monitor output.

      |  \/  |_   _/ ___|  ___ _ __  ___  ___  _ __ ___
      | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __|
      | |  | | |_| |___| |  __/ | | \__ \  _  | |  \__ \
      |_|  |_|\__, |____/ \___|_| |_|___/\___/|_|  |___/
              |___/                      2.3.0
      
      16 MCO:BGN:INIT NODE,CP=RNNNAS--,VER=2.3.0
      25 MCO:BGN:BFR
      50 !SGN:PER:TAMPERED
      86 SGN:INI:BND OK
      87 TSM:INIT
      88 TSF:WUR:MS=0
      95 TSM:INIT:TSP OK
      97 TSM:INIT:STATID=22
      102 TSF:SID:OK,ID=22
      104 TSM:FPAR
      105 SGN:SGN:NREQ=255
      142 TSF:MSG:SEND,22-22-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      954 TSF:MSG:READ,0-0-22,s=255,c=3,t=8,pt=1,l=1,sg=0:0
      959 SGN:SKP:MSG CMD=3,TYPE=8
      962 TSF:MSG:FPAR OK,ID=0,D=1
      988 TSF:MSG:READ,6-6-22,s=255,c=3,t=8,pt=1,l=1,sg=0:1
      992 SGN:SKP:MSG CMD=3,TYPE=8
      1762 TSF:MSG:READ,1-1-22,s=255,c=3,t=8,pt=1,l=1,sg=0:1
      1767 SGN:SKP:MSG CMD=3,TYPE=8
      2150 TSM:FPAR:OK
      2151 TSM:ID
      2152 TSM:ID:OK
      2154 TSM:UPL
      2155 SGN:SGN:NREQ=0
      2161 TSF:MSG:SEND,22-22-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
      2176 TSF:MSG:READ,0-0-22,s=255,c=3,t=25,pt=1,l=1,sg=0:1
      2181 SGN:SKP:MSG CMD=3,TYPE=25
      2184 TSF:MSG:PONG RECV,HP=1
      2187 TSM:UPL:OK
      2188 TSM:READY:ID=22,PAR=0,DIS=1
      2191 SGN:PRE:SGN REQ
      2193 SGN:PRE:WHI NREQ
      2195 SGN:SGN:NREQ=0
      2198 TSF:MSG:SEND,22-22-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0101
      2205 SGN:PRE:XMT,TO=0
      2207 SGN:PRE:WAIT GW
      2217 TSF:MSG:READ,0-0-22,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
      2223 SGN:SKP:MSG CMD=3,TYPE=15
      2226 SGN:SGN:NREQ=0
      2230 TSF:MSG:SEND,22-22-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.3.0
      2236 SGN:SGN:NREQ=0
      2242 TSF:MSG:SEND,22-22-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
      4248 SGN:SGN:NREQ=0
      4253 TSF:MSG:SEND,22-22-0-0,s=255,c=3,t=11,pt=0,l=5,sg=0,ft=0,st=OK:Relay
      4260 SGN:SGN:NREQ=0
      4264 TSF:MSG:SEND,22-22-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:2.0
      4271 SGN:SGN:NREQ=0
      4277 TSF:MSG:SEND,22-22-0-0,s=1,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
      4283 MCO:REG:REQ
      4284 SGN:SGN:NREQ=0
      4290 TSF:MSG:SEND,22-22-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
      4297 TSF:MSG:READ,0-0-22,s=255,c=3,t=16,pt=0,l=0,sg=0:
      4302 SGN:SKP:MSG CMD=3,TYPE=16
      4320 SGN:SGN:NREQ=0
      4327 TSF:MSG:SEND,22-22-0-0,s=255,c=3,t=17,pt=6,l=25,sg=0,ft=0,st=OK:<NONCE>
      4334 SGN:NCE:XMT,TO=22
      4468 TSF:MSG:READ,0-0-22,s=255,c=3,t=27,pt=1,l=1,sg=1:1
      4473 !SGN:VER:STATE
      4475 !TSF:MSG:SIGN VERIFY FAIL
      4477 MCO:BGN:STP
      4480 MCO:BGN:INIT OK,TSP=1
      

      What am I missing here?

      posted in Development
      Dbagioni
      Dbagioni