Announcement

Collapse
No announcement yet.

How do I send UDP messages ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Are you aware of the Arduino plugin? http://board.homeseer.com/forumdisplay.php?f=1222

    Regards
    Morten

    Comment


    • #17
      Yes I am, but couldn't find a solution there to display Homeseer data on my 7 segment display. Or can you confirm that that would be possible?


      Verzonden vanaf mijn iPhone met Tapatalk

      Comment


      • #18
        Originally posted by ABL View Post
        Yes I am, but couldn't find a solution there to display Homeseer data on my 7 segment display. Or can you confirm that that would be possible?


        Verzonden vanaf mijn iPhone met Tapatalk
        Although I don't have any 7 seg displays I do have an arduino with an ethernet shield - if your code is suitable for an uno/leonardo and you are willing then post it and I will see if I can create a HomeSeer script to send data to it.
        My Plugins:

        Pushover 3P | DoorBird 3P | Current Cost 3P | Velleman K8055 3P | LAMetric 3P | Garadget 3P | Hive 3P |
        Yeelight 3P | Nanoleaf 3P

        Comment


        • #19
          Sorry haven't used it since HS2 tests. But Try asking Greig.

          Comment


          • #20
            @MrHappy: that would be very kind. Of course I'm willing to share the code (it is in the end a combination of codes other people wrote and quite some trial and error): The XXX's should be replaced by the IP number of the Arduino (in my case a Arduino mega with ethernet module on top)

            const int ledClockPin = 10;
            const int ledDataPin = 9;
            const int ledLatchPin = 3;
            char bitSent = 'LSBFIRST';
            int numbers[11] = {126, 12, 182, 158, 204, 218, 250, 14, 254, 222, 0}; //0 will turn off the display
            int nummer;
            int dig1;
            int dig2;
            int dig3;
            int dig4;
            #include <SPI.h>
            #include <Ethernet.h>
            #include <EthernetUdp.h>
            byte mac[] = {
            0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
            };
            IPAddress ip(XXX, XXX, XXX, XXX);
            unsigned int localPort = 8888;
            char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
            char ReplyBuffer[] = "acknowledged";
            EthernetUDP Udp;


            void setup(){
            Ethernet.begin(mac, ip);
            Udp.begin(localPort);
            Serial.begin(9600);
            pinMode(ledLatchPin, OUTPUT);//Latch
            pinMode(ledClockPin, OUTPUT);//Clock
            pinMode(ledDataPin, OUTPUT);//Data
            digitalWrite(ledLatchPin, HIGH);
            Serial.begin(9600);
            }

            void loop(){

            int packetSize = Udp.parsePacket();
            Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
            Serial.println(packetBuffer);
            long nummer = atoi(packetBuffer);
            dig1 = nummer / 1000;
            nummer = nummer - (dig1*1000);
            dig2 = nummer / 100;
            nummer = nummer - (dig2*100);
            dig3 = nummer / 10;
            dig4 = nummer - (dig3*10);
            digitalWrite(ledLatchPin, HIGH);
            shiftOut(ledDataPin, ledClockPin, bitSent, numbers[dig4]);
            shiftOut(ledDataPin, ledClockPin, bitSent, numbers[dig3]);
            shiftOut(ledDataPin, ledClockPin, bitSent, numbers[dig2]);
            shiftOut(ledDataPin, ledClockPin, bitSent, numbers[dig1]);
            digitalWrite(ledLatchPin, LOW);
            delay(1000);
            }

            Within Homeseer I use the drhsIPplugin (Drule) with a recurring event. This works but I can't send variable data (values of devices for instance)...

            Comment


            • #21
              I've tested a simple script and it certainly sends the data to the board, not having the displays I can't be certain how it is reacting but it seems to get stuck in a bit of a loop. I know a little enough to be dangerous so not sure whether you wish to check if the UDP string is different to what the board already knows or you are happy setting the displays every time the function loops.

              Regardless, this as an example HomeSeer script sends '1234' to the socket on the Arduino. Quite whether you are going to need to do further work on it or the AToI conversion is going to work I don't know. It does not appear to error for me and sends the serial response but I don't have the displays to check.

              You can decide what you wish to do with the script, it could be that you wish to pass the data in by parameter or fix the data to a device value which might need additional safeguards in terms of what you send to the board.

              I did modify the Arduino project very slightly to discover a DHCP address rather than a specific IP but I doubt that will cause you any issues.

              Code:
              const int ledClockPin = 10;
              const int ledDataPin = 9;
              const int ledLatchPin = 3;
              char bitSent = 'LSBFIRST';
              int numbers[11] = {126, 12, 182, 158, 204, 218, 250, 14, 254, 222, 0}; //0 will turn off the display
              int nummer;
              int dig1;
              int dig2;
              int dig3;
              int dig4;
              
              #include <SPI.h>         // needed for Arduino versions later than 0018
              #include <Ethernet.h>
              #include <EthernetUdp.h>         // UDP library from: bjoern@cs.stanford.edu 12/30/2008
               
              byte mac[] = {
              0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
              };
              
              unsigned int localPort = 8888;
              char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
              char ReplyBuffer[] = "acknowledged";
              EthernetUDP Udp;
              
              void setup(){
              Ethernet.begin(mac);
              Udp.begin(localPort);
              Serial.begin(9600);
              pinMode(ledLatchPin, OUTPUT);//Latch
              pinMode(ledClockPin, OUTPUT);//Clock
              pinMode(ledDataPin, OUTPUT);//Data
              digitalWrite(ledLatchPin, HIGH);
              Serial.begin(9600);
              }
              
              void loop(){
              
              int packetSize = Udp.parsePacket();
              Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
              Serial.println(packetBuffer);
              long nummer = atoi(packetBuffer);
              dig1 = nummer / 1000;
              nummer = nummer - (dig1*1000);
              dig2 = nummer / 100;
              nummer = nummer - (dig2*100);
              dig3 = nummer / 10;
              dig4 = nummer - (dig3*10);
              digitalWrite(ledLatchPin, HIGH);
              shiftOut(ledDataPin, ledClockPin, bitSent, numbers[dig4]);
              shiftOut(ledDataPin, ledClockPin, bitSent, numbers[dig3]);
              shiftOut(ledDataPin, ledClockPin, bitSent, numbers[dig2]);
              shiftOut(ledDataPin, ledClockPin, bitSent, numbers[dig1]);
              digitalWrite(ledLatchPin, LOW);
              delay(1000);
              }
              Code:
              Imports System.Net.Sockets
              Imports System.Text
              
              Sub Main(ByVal Parm As Object)
              
                  Dim udpClient As New UdpClient("192.168.1.108", 8888)
                  Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("1234")
                  hs.writelog("UDPSend", "Sending UDP Data")
              
                  Try
                      udpClient.Send(sendBytes, sendBytes.Length)
                  Catch e As Exception : hs.writelog("UDPSend", "Exception: " & e.message.tostring)
                  End Try
              
              End Sub
              My Plugins:

              Pushover 3P | DoorBird 3P | Current Cost 3P | Velleman K8055 3P | LAMetric 3P | Garadget 3P | Hive 3P |
              Yeelight 3P | Nanoleaf 3P

              Comment


              • #22
                Thanks for your assistance.
                I tried to execute the script in Homeseer.
                The following error message appears:

                Running script, script run or compile error in file: C:/Program Files/HomeSeer HS3/scripts/testscript.txt1006:Expected ')' in line 4 More info: Expected ')'

                Comment


                • #23
                  It is a VB.net script so please name the file with a .vb extension and try and run it. I don't know of a method off hand for VBScript.
                  My Plugins:

                  Pushover 3P | DoorBird 3P | Current Cost 3P | Velleman K8055 3P | LAMetric 3P | Garadget 3P | Hive 3P |
                  Yeelight 3P | Nanoleaf 3P

                  Comment


                  • #24
                    Ran it again and it works!
                    What would be the best way to replace that 1234 by the value of a homeseer device? That would be the last part of my puzzle...

                    Comment


                    • #25
                      In the simplest form you should be able to replace

                      Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("1234")

                      with

                      Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(hs.devicevalue(345))

                      Where 345 is your device reference for the device you wish to send, the issue to be mindful of is that this might work and be absolutely fine but on the other hand what do you want to be shown on your display, whole number, decimal number - if a decimal number how are you coping with decimal places, what is your Arduino going to do about them - is it going to get stuck in some sort of exception.

                      If you run into issues then say what you wish to do it may be possible to do it in either the Arduino code or the HS script. If I ever do anything similar I make the Arduino code as small as I possibly can because editing a script on the HS system is far easier than digging out the Arduino, connecting it up, loading the editor etc etc.
                      My Plugins:

                      Pushover 3P | DoorBird 3P | Current Cost 3P | Velleman K8055 3P | LAMetric 3P | Garadget 3P | Hive 3P |
                      Yeelight 3P | Nanoleaf 3P

                      Comment


                      • #26
                        You made me a happy man!
                        It works; only issue as you mentioned the decimals, but that should be something that I can figure out by googling...

                        The idea was to build a wood cube led display that I can connect to the network and that displays my total water/power/gas usage during the day...

                        The electronics part is done, now starts the (more boring) wood part of it...

                        Thanks again for your help!

                        Comment


                        • #27
                          Originally posted by ABL View Post
                          You made me a happy man!
                          It works; only issue as you mentioned the decimals, but that should be something that I can figure out by googling...

                          The idea was to build a wood cube led display that I can connect to the network and that displays my total water/power/gas usage during the day...

                          The electronics part is done, now starts the (more boring) wood part of it...

                          Thanks again for your help!
                          No problems and sounds like a nice little project - I have built similar things in the past and I have never really used UDP so you have shown me that it appears a little easier to understand than TCP

                          For decimals you can look at the function hs.devicevalueex (http://www.homeseer.com/support/home...icevalueex.htm) but because the data type returned is a double you can have a lot of decimals, you may need to look at some of the Math.Round or String.Format methods to make it suitable for display.
                          My Plugins:

                          Pushover 3P | DoorBird 3P | Current Cost 3P | Velleman K8055 3P | LAMetric 3P | Garadget 3P | Hive 3P |
                          Yeelight 3P | Nanoleaf 3P

                          Comment


                          • #28
                            Have a new scrolling display and wanted to enhance this project by sending more than just one value. Now one single hs.devicevalue (of water usage) is being sent by UDP. Instead I would like to send say up to 5 data at once and have the UDP client converting the string to display these 5 values.

                            I've googled for two days now, but am not getting any relevant information (probably using the wrong search terms). Anyone that can point me in the good direction?

                            Comment

                            Working...
                            X