Navigation

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

    Posts made by soif

    • RE: NodeManager: plugin for a rapid development of battery-powered sensors

      It sounds absolutely terrific ! 👍

      Thank you very much !

      posted in NodeManager
      soif
      soif
    • RE: MYS Library Startup Control ? After()? OnRegistration()?

      hi @Boots33

      Thank you for your really helpful answer! 😄

      Following your guidelines, I've succeeded to send MyMessages after registration is completed. Here is the code :

      boolean executeOnce = false;
      
      void setup(){ }
      
      void loop(){
       if ( ! executeOnce  && isTransportReady() ) {
          // code here to be executed once at startup
         // ...
          executeOnce = true;
       }
      }
      

      Regarding 3), here is the behaviour I would like to build:

      • Start MYsensors library
      • if startup registration works, continue to loop
      • if startup registration fails before 5s, continue to the loop
      • every 15 min try to register to the GW (either if initially failed, or if transport have dropped later)

      I've read the helpfull topic you have linked, and started to guess from reading the MyConfig.h : Is this simple code, the right one to act like I wish

      #define MY_TRANSPORT_WAIT_READY_MS 5000
      #define MY_TRANSPORT_SANITY_CHECK
      // already set as default
      //#define MY_TRANSPORT_SANITY_CHECK_INTERVAL_MS (15*60*1000ul)
      

      Obviously, in the loop, I always have to send MyMessages, with the ACK parameter set to false, to NOT wait for ACK replies whenever the GW is not available, right?

      Cheers

      posted in General Discussion
      soif
      soif
    • MYS Library Startup Control ? After()? OnRegistration()?

      In v2.0+ (I dont remember if it was the same in 1.5), there seems to be a sort of pseudo multitasking sequence happening in background when Mysensors.h is included in the sketch.

      One of the consequence is that setup() function occurs at the "same" time as the Mysensor launch/presentation/registration process.

      I discovered a before() function, which permits to be sure to launch instructions BEFORE launching MYS, but I did not discovered any after() function wich would allow me to send MyMessages only ONCE the init with the gateway has been completed :
      I mean after the "init complete, id=xx, parent=0, distance=1, registration=1"

      So the questions are :

      1. What is the recommended way to launch (setup) code only ONCE the node is registered at the gateway, ie for sensing state of initial values. Is there some sort of after() function, or OnRegistered() function ?

      2. Is there some documentation (expect reverse engineering the big MYS library) to understand all the steps that are happening in the background, when launching the library as a node.

      3. It seems that since v2.0 , if the node is unable to find a gateway (ie the GW is too far, or offline) the sketch no longer launch... is there any mechanism to controls this behaviour (ie start anyway, being able to determine is the registration was successfull or not, and if not periodically try to register) ?

      Thank you

      posted in General Discussion
      soif
      soif
    • RE: RFC : Lazy Submission to OpenHardware.io using GitHub

      Except adding a little bit more work to maintain changes in version, date, description, adding photos, etc... 😉 So as it is not used I this time , I will remove it.

      Anyway, It would be really easy to revert the (clean-up) commit, whenever you'd decide to use this suggested (or another similar) standard.

      posted in Feature Requests
      soif
      soif
    • RE: RFC : Lazy Submission to OpenHardware.io using GitHub

      Did you still consider adding the mysensors.json file or some sort of file stucture standardization in the Github repos?

      FYI I have some MySensors projects using the previous proposed standard :

      https://github.com/soif/MySensors_ChristmasTree
      https://github.com/soif/MySensors_MonitorsRelay
      https://github.com/soif/MySensors_HSV_RGB_IR

      and still
      https://github.com/soif/MySensors_Template
      https://github.com/soif/MySensors_Php_API

      But it you finally don't mind (I guess) to use the proposed file structure or json files, I would like to make some clean-up in my repos...

      posted in Feature Requests
      soif
      soif
    • RE: S_HSV_LIGHT + V_HSV Sensor type

      The problem is not really concerning RGB to HSV or vice-versa (BTW if you have a working-well RGB to HSV code, i'm interested. I'm currently using the FastLED one ...)

      The idea (and this is the main reason why HSV ever existed) is to get a easy and natural way to describe colors.
      For anyone in the world it is easyer to say "I want a red, pale, not so bright" light, instead of a" #FFAA11" light! 😉 😉

      When you are from a controller point of view, talking directly in HSV, allows to easily set a dim level (which is a major feature for a light, isn't it?), and a color (Hue). Devs like the Domoticz ones even dropped the Saturation at this time, but they are currently receiving (and could easily send) H(S)V values.
      Also most (if not all) javascript color pickers are natively talking HSV.

      About HSL vs HSV I think this not really important because it is just a story of different gamma correction / color space (if i understand well), and for devices intended as a Light (not as screen), color deviation is not a big issue. I just vote for the most used in related software (arduino lib + Javascripts color pickers), to try to match the requested color as accuratly as possible.

      posted in Feature Requests
      soif
      soif
    • RE: MySensors Php API class + command line script + Form

      If you dont use git just replace the form.php with the one at GitHub

      Let me know if it works flawlessly (eth or serial?).

      cheers

      posted in My Project
      soif
      soif
    • RE: MySensors Php API class + command line script + Form

      Seems like Chrome + IE does not like function argument default values in JS, while mozilla does.

      I've just pushed v1.21 which fixes this bug.

      git pull 😉

      posted in My Project
      soif
      soif
    • RE: MySensors Php API class + command line script + Form

      Updated to v1.2 adding Serial gateway experimental support!

      As I don't have any serial gateway to test, I can't figure if it work or not, but I've implemented all the needed components to make it work.

      Would you please test if it work fine for you, and push some PR if some things need to be fixed for the serial connection.
      If you had to modify the "PhpSerial" class, would you please also push it back to the original developer repo

      HTH

      posted in My Project
      soif
      soif
    • RE: Other Controller get disconnected when sending any command to the Eth. Gateway (v2.0)

      My GW don't crash while the second controller get a connection, it just throw away the previous connection.
      I've tested this with MYS v1.51, 1.54 and 2.0beta.

      My two controllers are :

      • Domoticz (primary)
      • a simple telenet connection from the terminal

      You can check this by having one controller connected, then from a terminal console type :

        telnet IP_OF_THE_GW 5003
      

      It will launch a telnet session an you will see the GW messages scrolling, but when you send any characters (ie just hit return), boom, the first connected controller is immediately disconnected.

      posted in Troubleshooting
      soif
      soif
    • RE: S_HSV_LIGHT + V_HSV Sensor type

      I'm not worried about any losses while converting HSV->RGB : in this direction, it work pretty well (whenever the software is well written). This is in the opposite direction that conversion is happening bad. (FastLed note about this)

      I mean from the node, if I would like to work internally in HSV (in order to be able to support SMOOTH and easy dimmimg of any colors). Geting data from the controller in RGB, then converting in HSV is both approximative and adds some uneeded processing.

      Being able to easely DIM any color (ie just changing HSV.v), is one of the main argument to use HSV against raw RGB. In HSV mode you can aslo easily fade between colors (just changing the hue). This is both easy, and really intuitive.

      IMHOThese 2 features are importants to well suport RGB strips.
      Doing this in HSV, is just a few lines of code (ie using FastLed) while doing this in RGB is a nightmare and absolutely not intuitive.

      Anyway my test node works in both modes, but receiving HSV datas, would be a must and thus allow the controller so expose an HSV parameters in the API/script/GUI.

      Just imagine creating a LUA script ie, in Domoticz (or any controller) to dim an RGB strip in raw RGB mode, vs doing this in HSV.... One is very complicated while the other is really easy. and dimming a RGB strip should be as simple as dimming a single color bulb, isnt it?

      posted in Feature Requests
      soif
      soif
    • S_HSV_LIGHT + V_HSV Sensor type

      I'm proposing to add an S_HSV_LIGHT type for controlling Led Strips.

      Why

      • HSV is way more intuitive for humans to set a color than RGB. ie you can easily set a Hue (rainbow color), a Saturation (Color strength) and a brightness Level, rather than fighting against RGB values.
      • Dimming a RGB color, is at least complicated, if not impossible, while setting a HSV.v level is SO simple.
      • Controllers colors palettes are most often build from a HSV palettes, then APPROXIMATELY converted to RGB (ie Domoticz)
      • using the amazing arduino FastLed library makes converting HSV datas to RGB leds Strips (whatever the LedStrip technology) really simple, fast, precise and efficient.
      • converting on the node from HSV to RGB is precise (using FastLed) while the opposite is always approximate.
      • FastLed IS the library to use when you're talking to advanced/modern RGB chipsets, and internally talk HSV before converting to RGB.
      • some Hardware manufacturers did undertsood the interest of HSV and already implemented it this way in their products (ie Philips Hue Lights )
      • this does not prevent to use the S_RGB_LIGHT format when needed

      How

      • Define an S_HSV_LIGHT type
      • The S_HSV_LIGHT type could use the exact same payload format as the V_RGB format (3 byte of datas, encoded as a hexadecimal string): ie instead or RGB(0-255,0-255,0-255) , we would have HSV(0-255,0-255,0-255). This means that instead of having V_RGB + V_HSV , they could be merged into a shared "V_3HEX" format.

      FYI : I already have developed an (almost finished) sketch/proof-of-concept that controls a RGB led strip from HSV messages , and/or RGB messages, using the FastLed library. Obviously, the HSV messages are more intuitives and precises than the RGB messages.

      posted in Feature Requests
      soif
      soif
    • RE: Chinese Solar Lipo powered PIR led lamp.

      @gyro
      Keep up the good work debugging this chinese box !

      This box is a really good value for money box to build mysensors projects ( at least box + lipo + solar panel).

      If your investigations let us to also use the built in Charger / PIR / LEDS , it would just be amazing.

      Please keep us in touch ! 😉

      posted in My Project
      soif
      soif
    • RE: MySensors Php API class + command line script + Form

      I've just posted version 1.1, including the form showed above. 😉

      Any current users ?
      Comments?

      posted in My Project
      soif
      soif
    • RE: Other Controller get disconnected when sending any command to the Eth. Gateway (v2.0)

      Issue #398 opened at GitHub.

      Now seeking for a C++ hero ! 😛 😛 😛

      HTH

      posted in Troubleshooting
      soif
      soif
    • RE: Other Controller get disconnected when sending any command to the Eth. Gateway (v2.0)

      BTW would you mind if I opened an issue at GH about this, linking to this topic, to help you and others developpers to have a reminder at the right place.

      And maybe another C++ hero would see it, and start working on it! 😛

      posted in Troubleshooting
      soif
      soif
    • RE: MySensors Php API class + command line script + Form

      Currently Working (develop branch) on a convenient form to convert/send messages .

      Form

      It should certainly help developers to test their sensors/gateway 😉

      posted in My Project
      soif
      soif
    • RE: Other Controller get disconnected when sending any command to the Eth. Gateway (v2.0)

      Happy if i could have helped you to save you some time to find a way for implementing a solution.

      Let us know when you'd made some progress 😉

      posted in Troubleshooting
      soif
      soif
    • RE: Other Controller get disconnected when sending any command to the Eth. Gateway (v2.0)

      Yep, comments are often useful when we are not that lazy to include them 😄

      BTW I've found a topic telling about modifying the Eth library to get the Source IP, and being then able to support multiple clients. I don't know if it really helps.

      Also found this where the guy says that W5100 supports 4 sockets (so max 4 clients) but the Eth lib can NOT distinguish them if they are on the same port (might be a a workaround, to open 4 port instead of one, ie 5003,5004,5005,5006). He's finally submitted a patch against the Eth lib to allow 4 different sockets on the same port.... But the more interesting seems to be a comment by "Gene" who has posted complete sketch showing how to connect multiple telnet clients . Here is his code:

      /* exampleMultiTelnetServer.ino */
      /* 
       *  Created: May 21, 2015
       *
       *  Created by Gene Reeves to demonstrate how the W5100 eithenet handles multiple connections
       *  using a single server object instance.
       * 
       *  once the sketch is loaded on your arduino and you see the start up banner display in the
       *  Serial Monitor, fire up your favorite telnet client and connect a few instances.
       *  
       *  from the serial monitor you can send text to one or all clients. Use '*" for the ID to send
       *  to all, otherwise use the ID you wish to send to, using this format to send,
       *   "ID:TEDXT_TO_SEND".  That should make everything as clear as mud  :-)
       *
       *  Dependencies:
       *
       *  uses LinkedList class from here https://github.com/ivanseidel/LinkedList
       *  to store list of connected clients.
       *
       *  uses StringStream class from here https://gist.github.com/cmaglie/5883185
       *  Not sure why this was not a part of the StringObject to start with..
       *
       *  uses elapsedMillis class from here http://playground.arduino.cc/Code/ElapsedMillis
       *  much improved version (for Teensy brand mcu's) here https://www.pjrc.com/teensy/td_timing_elaspedMillis.html
       *  Unless I am mistaken, I beleive this code was originated by Paul Stoffregen of www.pjrc.com
       *  If you are not famialar with Paul or his Teensy microcontroller, you would do yourself a 
       *  solid to spend some time reviewing his code and you can't beat the Teensy 3.1 for 
       *  price/performance/support!!!   
       *  Teensy 3.1 - 32bit-ARM  mcu @ 72MHz (overclockable to 168MHz) w/ 256K flash / 64K ram / USB
       *  for under $20.  https://www.pjrc.com/teensy/index.html
       *
       *  BTW, I am in no way affilaited with Paul or PJRC, I just think he built an awesome mcu.
       *
       */
       
       
      #include <SPI.h>
      #include <LinkedList.h>
      #include <elapsedMillis.h>
      #include <StringStream.h>
      #include <Arduino.h>
      #include <EthernetUdp.h>
      #include <EthernetServer.h>
      #include <EthernetClient.h>
      #include <Ethernet.h>
      #include <Dns.h>
      #include <Dhcp.h>
      #include <IPAddress.h>
      #include <Server.h>
      #include <Client.h>
       
       
      /*  DEFINES  */
                            
      /*****************************************************/
      /*  Change the following to suite your environment.  */
      #define TELNET_SERVER_PORT 23
      #define TELNET_SERVER_MAC 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
      #define TELNET_SERVER_IP 192, 168, 1, 177
      #define TELNET_SERVER_GATEWAY 192, 168, 1, 1
      #define TELNET_SERVER_NETMASK 255, 255, 255, 0
      #define SERIAL_BAUD 115200
      #define WELCOME_BANNER_STRING "Welcome to MultiTelnetServer.\r\nType 'exit' to disconnect\r\n"
      #define GOODBYE_BANNER_STRING "Come Back Again,   Goodbye.."
       
      #define APP_BANNER_STRING "\r\n\r\n\tMultiTelnetServer Example\r\n  This example application strives to\r\ndemonstrate using the Wiznet W5x00\r\nEthernet Shield's Arduino library usage\r\nwhen serving mulitple concurrent\r\nconnects using a single 'server object'\r\ninstance."
      #define SERVER_LISTENING_STRING "\tServer Listening on"
       
      /******************************************************/
       
       
      /*
       *  This is required to add RemoteIP, RemotePort support to the EthernetClient class
       *  I stole it from here http://forum.arduino.cc/index.php?topic=210857.0
       */
      //namespace ethernet_fix
      //{
        #include <utility/w5100.h>
       
        template<typename Tag, typename Tag::type M>
        struct AccessMember{
          friend typename Tag::type get(Tag){ return M; }
        };
       
        struct EthernetClient_Socket{
          typedef uint8_t EthernetClient::*type;
          friend type get(EthernetClient_Socket);
        };
       
        template struct AccessMember < EthernetClient_Socket, &EthernetClient::_sock > ;
       
        IPAddress RemoteIP(EthernetClient &c){
          byte remoteIP[4];
          W5100.readSnDIPR(c.*get(EthernetClient_Socket()), remoteIP);
          return (remoteIP);
        }
       
        uint16_t RemotePort(EthernetClient &c){
          return W5100.readSnDPORT(c.*get(EthernetClient_Socket()));
        }
      //} // namespace "ethernet_fix"
      /*
       *  EthernetClientEx - Because there is still no RemoteIP or RemotePort
       *  properties built in to th current EthernetClient!!
       *
       */
       
      class EthernetClientEx :
        public EthernetClient
      {
      protected:
        uint8_t _sock; // hack to get access to socket #
      public:
        EthernetClientEx(const EthernetClient &orig) : EthernetClient(orig) {}
        IPAddress remoteIP() { return RemoteIP((EthernetClient &)(*this)); }
        int16_t remotePort() { return RemotePort((EthernetClient &)(*this)); }
       
        bool isSameSock(const EthernetClientEx &c) { return (_sock == c._sock); }
      };
       
       
      /*
       *  ClientItem is class to wrap EthernetClient for storage on linked list
       *  we will use it to add a ts (millis at connection time) and an index.
       *
       */
      class ClientItem
      {
      public:
        unsigned long timestamp;
        int index;
        size_t recv_cnt;
        String recv_buffer;
        EthernetClientEx *client;
       
        ClientItem() { timestamp = millis(); index = -1; client = (EthernetClientEx *)false; }
        virtual ~ClientItem() { delete client; /* release memory */}
         
        unsigned long elapsed(void) { unsigned long ts = millis(); return (ts - timestamp); }
      };
       
      /*
       *  ClientList is linkedlist for storing connected clients. 
       *  For now, we'll just use it to store our clients, but should
       *  expand this close to include testing all clients for disconnects,
       *  testing all clients for pending recv data and sending data
       *  to all connected clients.
       */
       
      class LinkedClientList :
        public LinkedList<ClientItem*> //ClientList;
      {
      public:
        //EthernetServer *server;
       
        ClientItem *getClientItem(int idx)
        {
          for (ListNode<ClientItem *> *n = root;n;n=n->next)
          { 
            if (n->data->index == idx)
              return n->data;
          }
          return (ClientItem *)0;
        }
         
        bool exists(const EthernetClientEx &ece)
        {
          for (ListNode<ClientItem *> *n = root; n; n = n->next)
            if (n->data->client->isSameSock(ece))
              return true;
          return false;
        }
       
        void drop(int idx)
        {
          ClientItem *cli;
          int real_idx = -1;
          int ci = 0;
          for (ListNode<ClientItem *> *n = root; n; n = n->next)
            if (n->data->index != idx)
              ci++;
            else
            {
              cli = n->data;
              real_idx = ci;
              break;
            }
       
          if (real_idx != -1)
          {
            if (cli->client->connected())
              cli->client->stop();
            cli->index = -1;
            remove(real_idx);
          }
        }
       
        size_t send(const String &s, int idx)
        {
          size_t ret = 0;
          ClientItem * cli = getClientItem(idx);
          if (cli)
          {
            ret = cli->client->print(s);
            cli->client->flush();
          }
          return ret;
        }
       
        size_t send2All(const String &s)
        {
          size_t ret = 0;
          for (ListNode<ClientItem *> *n = root; n; n = n->next)
          {
            ret += n->data->client->print(s);
            n->data->client->flush();
          }
          return ret;
        }
      };
       
      LinkedClientList ClientList;
       
      // Enter a MAC address and IP address for your controller below.
      // The IP address will be dependent on your local network.
      // gateway and subnet are optional:
      byte mac[] = { TELNET_SERVER_MAC };
      IPAddress ip(TELNET_SERVER_IP);
      IPAddress gateway(TELNET_SERVER_GATEWAY);
      IPAddress subnet(TELNET_SERVER_NETMASK);
       
      // buffer to hold input from console
      StringStream con_buffer("");
       
      // telnet defaults to port 23
      EthernetServer server(TELNET_SERVER_PORT);
       
      /* forward's */
      void server_check_new_connections(void);
      void server_check_client_recv(void);
      int server_accept(EthernetClientEx *enetcli);
      bool clientExists(const EthernetClientEx &c);
      bool test_for_cmd(const String &itm, const String &src);
      size_t console_recv(void);
      void proc_line(StringStream &ss);
       
      size_t client_recv(ClientItem *cli);
      void client_disconnecting(ClientItem *cli);
      void client_disconnected(ClientItem *cli);
       
      size_t send_to(int idx, const String &str);
      size_t send_to_all(const String &str);
       
      /*********************************************************/
      void setup()
      {
       
        /* add setup code here */
        // reserve some space for input buffer
        con_buffer.reserve(256);
       
        // Open serial communications and wait for port to open:
        Serial.begin(SERIAL_BAUD);
        delay(3000);  // 3 second delay for Serial to connect.
       
        pinMode(10, OUTPUT);
        digitalWrite(10, HIGH);
        pinMode(4, OUTPUT);
        digitalWrite(4, HIGH);
       
        // initialize the ethernet device
        Ethernet.begin(mac, ip, gateway, subnet);
        // start listening for clients
        server.begin();
       
        // Print "App Banner" and "Server Listening" notice.
        Serial.println(F(APP_BANNER_STRING));
        Serial.println(F(SERVER_LISTENING_STRING));
        Serial.print(F("\t\t"));
        Serial.print(ip);
        Serial.print(':');
        Serial.println(TELNET_SERVER_PORT);
        Serial.println(F("\r\n\r\n"));
       
      }
       
      void loop()
      {
       
        /* add main program code here */
       
        // check for any new clients
        server_check_new_connections();
       
        // give up a timeslice
        yield();
       
        // check to see if any of the clients 
        // have recv data pending
        if (ClientList.size() > 0)
          server_check_client_recv();
       
        // give up a timeslice
        yield();
       
        // check to see if console has any 
        // pending recv data.
        if (Serial.available())
          console_recv();
       
        // give up a timeslice
        yield();
      }
       
      /*********************************************************/
       
      size_t console_recv(void)
      {
        size_t ret = 0;
        int c = 0;
        while ((c = Serial.read()) >= 0)
        {
          if (c == 10)
          {
            proc_line(con_buffer);
            con_buffer = String("");
            con_buffer.begin();
            continue;
          }
          if (c != 13)
          {
            con_buffer += (char)c;
            ret++;
          }
        }
        return ret;
      }
       
      void proc_line(StringStream &ss)
      {
       
        //  Console input should be in the for of
        //  "ID:string_literal"
        //  where: 
        //    ID is client index to send to or "*" (all)
        //    string_literal is string to send
        //
        // check to ensure 2nd char is a ":"
        if ((ss.length() < 3) || (ss.charAt(1) != ':'))
        {
          Serial.print(F("Invalid Console Input \""));
          Serial.print(ss);
          Serial.print(F("\"\r\nPlease use the following format:\r\n\t"));
          Serial.println(F("\"ID:string_literal\"\r\n"));
          Serial.flush();
          return;
        }
        int idx = -1;
        Serial.print(F(" first char is '"));
        Serial.print(ss.charAt(0));
        Serial.print(F("',  "));
        if (ss.charAt(0) != '*')
        {
          idx = ss.parseInt();
        }
        Serial.print(F("idx="));
        Serial.print(idx);
        Serial.print(F(", indexOf(':')="));
        Serial.println(ss.indexOf(':'));
        ss = ss.substring(1 + ss.indexOf(':'));
        ss += F("\r\n");
        if (idx < 0)
          ClientList.send2All(ss);
          //send_to_all(ss);
        else
          ClientList.send(ss, idx);
      }
       
      size_t console_print_connected_count(void)
      {
        size_t ret =
          Serial.print(F("\t\t")) +
          Serial.print(ClientList.size()) +
          Serial.println(F(" connected client(s).\r\n"));
        Serial.flush();
        return ret;
      }
       
      bool test_for_cmd(const String &itm, const String &src)
      {
        String tst(src);
        tst.toLowerCase();
        return tst.startsWith(itm);
      }
       
      void server_check_new_connections(void)
      {
        EthernetClient obj = server.available();  
        if (obj)
        {
          // convert to EthernetClientEx
          EthernetClientEx new_client(obj);
          // is it a new connection?
          if (!ClientList.exists(new_client))
          {
            // accept new connection
            server_accept((EthernetClientEx *)&new_client);
       
            // send welcome banner
            new_client.println(F(WELCOME_BANNER_STRING));
            new_client.flush();
          }
        }
      }
       
      int server_accept(EthernetClientEx *enetcli)
      {
        // add itm to list
        ClientItem *itm = new ClientItem();
        itm->timestamp = millis();
        itm->index = ClientList.size();
        itm->client = new EthernetClientEx((*enetcli));
        ClientList.add(itm);
       
        // print notice on console
        Serial.print(F("Accepted new connection ("));
        Serial.print(itm->index);
        Serial.print(F(") from "));
        Serial.print(enetcli->remoteIP());
        Serial.print(':');
        Serial.println(enetcli->remotePort());
        Serial.println();
        Serial.flush();
       
        // print connected count
        console_print_connected_count();
       
        // return items index
        return itm->index;
      }
       
      void server_check_client_recv(void)
      {
        if (ClientList.size() == 0) return;
        ClientItem *itm;
        for (int idx = ClientList.size() - 1; idx >= 0; idx--)
        {
          itm = ClientList.get(idx);
          if (itm->client->connected()==0)
          {
            client_disconnected(itm);
            continue;
          }
          if (itm->client->available())
          {
            size_t rc = client_recv(itm);
            if (rc > 0)
            {
              // echo to Serial port
              Serial.print(F("Client #"));
              Serial.print(itm->index);
              Serial.print(F(" sent \""));
              Serial.print(itm->recv_buffer);
              Serial.println('\"');
              Serial.flush();
            }
            // rc will == 0 if nothing received
            // rc will == -1 if client entered "exit"
          }
          yield();
        }
      }
       
      size_t client_recv(ClientItem *cli)
      {
        int c;
        EthernetClientEx *cIn = (EthernetClientEx *)cli->client;
        cli->recv_buffer = "\0";
        cli->recv_cnt = 0;
        while ((c = cIn->read()) >= 0)
        {
          cli->recv_buffer += (char)c;
          cli->recv_cnt++;
        }
        // check to see if they typed "exit"
        if (test_for_cmd(String(F("exit")), cli->recv_buffer))
        {
          client_disconnecting(cli);
          delay(1); // give up timeslice
          cli->client->stop();
          Serial.print(F("called client->stop() for #")); Serial.println(cli->index); Serial.flush();
          return -1;
        }
        return cli->recv_cnt;
      }
       
      void client_disconnecting(ClientItem *cli)
      {
        Serial.print(F("Client #"));
        Serial.print(cli->index);
        Serial.println(F(" is disconnecting."));
        // send Goodbye Banner
        send_to(cli->index, String(F(GOODBYE_BANNER_STRING)));
        Serial.flush();
        delay(1);
        cli->client->stop();
      }
       
      void client_disconnected(ClientItem *cli)
      {
        // print notice on console
        Serial.print(F("Client #"));
        Serial.print(cli->index);
        Serial.print(F(" was connected for "));
        Serial.print(cli->elapsed() / 1000);
        Serial.print(F(" seconds, and has disconnected."));
        Serial.flush();
       
        // remove from list of clients
        ClientList.drop(cli->index);
        (*cli) = (*(ClientItem *)(unsigned long)0);
        // print connected count
        console_print_connected_count();
       
        // this causes seg fault ??
        //delete cli;
      }
       
      size_t send_to(int idx, const String &str)
      {
        return ClientList.send(str, idx);
      }
       
      size_t send_to_all(const String &str)
      {
        return ClientList.send2All(str);
      }
      
      

      Bingo ? Sounds good?

      Again, sorry my C++ knowledge is very limited...

      HTH

      posted in Troubleshooting
      soif
      soif
    • RE: Other Controller get disconnected when sending any command to the Eth. Gateway (v2.0)

      Thank you for poiting me to this part of the code. It immediately showed something interesting :

      Your highlighted code is for ESP8266 but i'm using W5100 (the recommended one)...
      If I read correctly the code just following for the W5100, I see that :

      // W5100/ENC module does not have hasClient-method. We can only serve one client at the time.
      
      • Would it mean there is absolutely no way to get multiple clients connected with the W5100?
      • Not codable?
      • only workaround it to buy a ESP8266 Wifi (wifi sucks) module ?

      Sorry my C++ knowledge is very limited...

      posted in Troubleshooting
      soif
      soif
    • Other Controller get disconnected when sending any command to the Eth. Gateway (v2.0)

      Short :

      I'm trying to send mysensors message to the ethernet gateway. I've also another Controller (domoticz) connected at the same time. Whatever message I type (even a simple CR) cause Domoticz to be immediatly disconnected.

      Long :

      As I knew that my 1.51 version is not supposed to support mutiple connection to the Eth gateway, I've downloaded the latest dev version from github (# 1f27c3d ) and compiled the GatewayW5100.ino example and just added at top of the file (around line 108, just before the first include):

      #define MY_GATEWAY_MAX_CLIENTS 3
      

      I suppose this makes the gateway able to handle multiple connections at the same time.

      It seems to work, as I can see messages printed on the telnet, while Domoticz is also connected, sending hearbeat messages.

      But sending any message, or just sending a CarriageReturn) from telnet, just make Domoticz to be immediately disconnected, with a message in its log file :

      MySensors: Connection reset!
      TCP: Reconnecting in 30 seconds...
      

      obviously letting him away for 30 seconds is not acceptable in production.

      According to Domoticz MySensors source code, the error may be caused by :

      (error == boost::asio::error::eof) ||
      (error == boost::asio::error::connection_reset)
      

      Questions:

      • Am I doing something wrong (my C++ understanding being very limited?
      • Is #define MY_GATEWAY_MAX_CLIENTS 3 supposed to work at this time?
      • Is this a bug from MySensors? From Domoticz?
      • Is it definitively not possible to send messages when another controller is also connected?

      Any help would be greatly appreciated ! 🙂

      posted in Troubleshooting
      soif
      soif
    • RE: Generic text variable type

      @AWI Thank you very much for poiting me to this interesting project.

      If it has been discussed, it has not been solved, wasn't it? I've read @John proposal, which sounds really similar to mine.

      Any progress or decision from the maintainers about this ?

      posted in Feature Requests
      soif
      soif
    • RE: Chinese Solar Lipo powered PIR led lamp.

      Really interested by your investigations, as i stared build some sensor based on this box (ie the Weather station project). But I had trashed the original pcb and replaced by mine, rebuilding a charger, and getting rid of the builtin PIR. But if it is enough hackable, why not keep it as an addionnal sensor.

      So please post your results here.

      A few remarks :

      • if there is no LDR, I guess they've simply used the solar panel to detect if there is sun 🙂
        There should be something like :
        Solar+ --------- Resistor ------------ BIS0001 pin 9, so the challenge would be to find which resitor it is, explode it with a cutter or a drill, and put pin 9 to high (ie 3,3v) to make PIR alway ON.

      • to controll the light there should be something like this:
        BIS0001 pin 2 --------- Transistor (base) : remove this connection and connect pin2 to an arduino input and the transistor base to an arduino output.

      • You would also have to check is the retrigering time fit your need, and it the sensibility is well setup...

      • for the arduino software it will really simple, ie some pseudo code :

        • When input pin is high send Mysensor Message to gateway
        • On incoming Mysensor Message1, set output PIN to High for 30 seconds.
        • On incoming Mysensor Message2, set output PIN to blink for 1 hour.
      posted in My Project
      soif
      soif
    • RE: Generic text variable type

      V_TEXT already exists in version 2.0 : see in the code, or in Doxygen ! 😛

      But because of the NRF24L01 limitation, the maximum payload size is 25 bytes!.
      This means that V_TEXT messages would be limited to 25 characters, which could be too short in some case.

      Maybe Mysensors could split longer V_TEXT in multiple messages when sending, then recomposing it when receiving ie:

      "Here is a sentence longer than 25 characters that should be splitted."

      Could be encoded into messages like this :

      1;0;0;47;Here is a sentence lon;1;4
      1;0;0;47;ger than 25 characters;2;4
      1;0;0;47; that should be splitt;3;4
      1;0;0;47;ed.;4;4
      

      Then it would be automatically decoded at the arrival.

      This way V_TEXT message would be limited to 23*255 characters (more than enought), without writing complicated code from the controllers or in the sketch !

      posted in Feature Requests
      soif
      soif
    • RE: RFC : Lazy Submission to OpenHardware.io using GitHub

      @hek just keep up your AMAZING work on MySensors.
      Maybe my command line tool may help you to save some time typing in a telnet console.

      We're all wishing to get a few more hours per days 😉

      posted in Feature Requests
      soif
      soif
    • RE: RFC : Lazy Submission to OpenHardware.io using GitHub

      I've just posted a PHP class for Mysensors. More at :
      http://forum.mysensors.org/topic/3102/mysensors-php-api-class-command-line-script
      https://github.com/soif/MySensors_Php_API

      It currently uses the .json file / file structure Standard proposed above.

      Enjoy

      posted in Feature Requests
      soif
      soif
    • MySensors Php API class + command line script + Form

      As I needed a simple tool to test MySensors send/receive messages, I've created a basic php class, including a command line script , that can be used to send/receive mysensors messages directly to the Ethernet Gateway.

      You can use it in your php controllers, or directly on the command line by tapping commands like:

      ./mysensors_bin.php 192.168.0.240 set 12 0 V_STATUS 1
      

      This example send a command to the gateway at IP 192.168.0.240, to set the V_STATUS to 1, for Node 12, child 0...

      The project is at GitHub, and your contributions are most welcome !
      https://github.com/soif/MySensors_Php_API

      BTW I did my best to understand how MySensors messages worked, but without more documentation, I may have missed some things. So test it, and feel free to commit PR to the develop branch !

      HTH 😛

      posted in My Project
      soif
      soif
    • RE: RFC : Lazy Submission to OpenHardware.io using GitHub

      anyone else comments?

      posted in Feature Requests
      soif
      soif
    • RE: RFC : Lazy Submission to OpenHardware.io using GitHub

      I'm very happy that you've liked the concept. 🙂

      Asking developpers to prefix their repos name with 'mysensors-' does add some "wild" search abilities, but it'd still not fully let you properly index projects.

      But a REALLY SIMPLE (this IS the key) JSON file + file structure, is easy to implement for developpers, and would make your life crawling their repo, really safer while letting developpers being focused on what they do best (coding), whithout asking them to follow (boring for them) procedures to publish their projects on OH.io.

      They (or anybody else) would just have to submit the repo URL, and your robots could SAFELY do the rest.

      I do believe that standardization is the shortest way and the key to success for both parties (developpers and maintainers), assuming the standard is really simple to implement. Look how fast composer has become the absolute leader in php libraries packages in just a few months, while other (complicated) solutions have pre-existed since years (ie PEAR).

      BTW, in my Template JSON definition, I've filled a 'type' (=project) field, intended to define that the repo is a 'project'. But there could be some others useful types, ie:

      • library : for arduino libraries relying on Mysensors
      • devtool : for applications like MYSController or NRF24_Sniffer
      • misc : IE, I've made an Excel file which translate Gateway or Debug messages to human readable messages : where sould I share this back to the community, except in an obscure forum post at MySensors website?
      • etc....

      You could also, like in Composer, include libraries dependencies imanagement.

      Food for the mind 😛

      posted in Feature Requests
      soif
      soif
    • RFC : Lazy Submission to OpenHardware.io using GitHub

      Here is a proposal (RFC) to encourage developers to publish MySensors projects on Github, and get their projects published/updated on OpenHardware.io.

      IMHO, developers are lazy, and tracking / gathering project information from the forums, or asking developpers to submit on OpenHardware.io, is also a time consuming process for OH.io maintainers.

      What if developpers would just have to follow a very basic file structure, when publishing their projects on GitHub and then to just have to submit their repo URL to MySensors, to get their project AUTOMAGICALLY recorded/updated at OpenHardware.io.

      From a developper point of view :

      • developers love GitHub but hate filling forms or making documentations
      • most developers are LAZY (right?) and just asking them to follow easy conventions when publishing on GH is certainly not that hard, if clearly advertised on mysensors.org or OH.io.
      • just pushing new commits to GH, is really more funny/natural , than taking the time to go to OH.io, and submit modifications, new images, new code, etc...
      • others developpers could contribute to each others project using GH pull-requests, submitting issues, adding pictures, etc...

      From OpenHardware.io mainteners point of view :

      • the more way to submit projects, the more projects to get published
      • updates could be fully automated (developer push to GH, then OH.io can just automatically fetch new infos)
      • It don't prevent non-GH users to use the regular OH.io submission form if they wish
      • GH users would be more able/naturally prompted to contribute to each other projects
      • Don't re-invent the wheel for developpers interaction/collaboration, by just interfacing with GH
      • easy to implement

      So to make this more comprehensible, I've pushed a proposal of a Mysensors Template Project at:
      https://github.com/soif/mysensors_template

      and a demo showing how this could be easily parsed at :
      https://jsfiddle.net/soif/ek5j7pao/

      Obviously this is just a draft, and standards should be defined/fixed by OH.io maintainers...

      Sounds interesting for you developpers?
      And for you OH.io maintainers?

      HTH

      posted in Feature Requests
      soif
      soif
    • RE: Solar Powered Mini-Weather Station

      This is similar to the one I have also bought at aliexpress 😉

      posted in My Project
      soif
      soif
    • RE: Nodes on the Gateway or connected via I2C

      @mfalkvidd Thank you very much for pointing me to the dev branch which now implements nodes on the gateway. Things are evolving really fast here 😉 I'm certainly gonna wait until it reach the master branch to use it "in production".

      While this is just an excellent news solving the sensor-on-gateway issues, it don't solve/standardize multiple arduinos communication. But maybe this feature is outside of the scope od MySensors, and should be developped independently by extending the Wire.h methods.

      Any other thoughts?

      posted in Feature Requests
      soif
      soif
    • RE: Solar Powered Mini-Weather Station

      @Yveaux Thank you very much for the diode explanation, as well as the very interesting diode tutorial.
      Thanks to you, I've learned something more today.

      I'm gonna test it very soon, and will report back.

      posted in My Project
      soif
      soif
    • RE: Solar Powered Mini-Weather Station

      @Yveaux thank you for the amazing fast and really helpful answer.

      Droping the voltage by 0.7v would certainly change the charger beahaviour to behave properly, and not be in "protection mode", Definitively better than inserting a stepDown module.
      I assume that I put the diode in serie from the VCC+ out of the Solar panel TO the VCC+ IN of the charger (right?), ie:
      Solar VCC out ------ --->| ---- Charger VCC in.

      3 questions:

      • Is there any diode reference recommendation, or any value do the job (1N400x) ?
      • Will the diode "eat" some current, ot just drop the voltage -0,7v. ?
      • BTW what is a "Silicon" diode?

      thank you very much for your valuable support !

      Berst regards,

      posted in My Project
      soif
      soif
    • Nodes on the Gateway or connected via I2C

      Hi there,
      First cheers for this AMAZING project which woken up the electronics passion of my childhood...

      I've succefully built an ethernet gateway and some nodes, but I would like to add some nodes directly in the gateway.
      For example, I would like to add a 433mghz tranceiver, a 315Mhz tranceiver, as well as a few sensors like BS18B20, and such directly in the gateway...

      Here is how I understand it can / cannot be done:

      1. wiring all on the GW arduino, but as read on the forums, it seems that at this time, Mysensors Gateway code does not support sensor (nodes) directly in the Gateway sketch. and I understand that it might be challenging.
        Any progress on the idea? Would you implement it a day or definitively not?

      2. current solution seems to build multiple hardware nodes (Arduino + radio) in the same box, which is taking more space(unused radio), taking more hardware (multiple radios) , is slower than a wire, and spending more radio messages just to communicate to an arduino near him within the same box.

      3. Wiring another arduino (acting as node) on the I2C bus to the gateway arduino, an make him exchange infos with the gateway.
        The benefit of this approach (if implemented in MySensors) is that:

      • This would allow easy implementation of sensors/actuator on the gateway, by simply adding another arduino, connected to the 2 pins of I2C bus, and just adding a line on the gateway, ie "gw.useNodesOnI2C()" telling him to also communicate to I2C nodes, plus adding a MySensor "gw(I2C, I2C_ID)" declaration line in each connected node.

      • This would also permit to extends some complicated nodes (those that need to run parrallel tasks), to easily solve the huge complexity of building multi-threading arduino applications, by simply running multiple arduinos (in the same box), who talk together on the I2C bus.

      • nodes would be seens as normal nodes, except that their transport is on the I2Cbus instead on the radio module

      • It might * maybe* be simplier from the Mysensors library side to implement I2C slaves nodes, by "simply" implementing a new transport type, isnt it?

      It seems to be possible to code this "manually" for the I2Cbus using Wire.h library, but it would definitively be more elegant and cool to implement it directly in MySensor Lib. Unfortunately my C++ skill are so limited that I can't understand if is is easily feasible or not.

      Does it make sense to you?
      Any thoughts?
      Other Solutions?

      Keep up the excellent work !
      Best regards

      posted in Feature Requests
      soif
      soif
    • RE: Solar Powered Mini-Weather Station

      I really liked this project (@Salmoides ThankYou for sharing it)
      Expecially the solar powered box.

      I've successully prototyped one, but would like to report something to pepople trying to also make this.

      The solar panel included in the box, is outputting 6V, while the Charger board is sized to acced only 5V as input.
      The consequence, is (at least on my prototype) that when there is enought sun, the charger board don't charge the battery (the blue led lights on, and the red seems to vibrate slighty : I guess this is a "protection mode" when VCCin is to high). If i remove the solar panel, and put a usb cable in the charger input, then the RED led lights on, and the barrety is being charged.

      I guess that slighly modifying the charger board, would allow it to accept 6V as input, but this is too far from my electronic skills (Anyone?)

      As a workaround, I've ordered a StepDown module to reduce the 6V provided by the solar panel to 5V for the charger input. I guess It will do the job. I will report back as soon as I get the StepUp module from china.

      HTH those interested in this excellent project.

      BTW @Salmoides , How did you solved it? Does your Solar panel outputs 5V, instead of 6V? Does your charger works with 6V input (might be slighly diffrent board or mine has an issue)? Did you modified the charger or added extra component to reduce the input voltage ?

      Cheeers to evereyone !

      posted in My Project
      soif
      soif