Announcement

Collapse
No announcement yet.

How to pass to devices the information of sensors coming from arduino serial port?

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

  • How to pass to devices the information of sensors coming from arduino serial port?

    Hello!

    I am using an arduino mega with multiple analog inputs connected to various sensors and digital relay outputs, connected to the HS3 by ethernet.
    This system works well.

    The point is that I wanted to start monitoring in HS3, instantaneous power and the total energy consumed.

    The power and energy information is available on another arduino mega that analyzes the number of pulses of the electricity meter in a given time period, the calculations are made in the mega and is available in the arduino serial output.

    Is there any way to use this plugin to pass this information to two HS3 devices (power and energy)?

    How can I manage the information that comes to me via serial port in order to assign it to the correct devices in HS3?

    Thanks

  • #2
    Yes. This is what the API mode is for on the boards. You can send the information to HS form your own sketches.

    Greig.
    Zwave = Z-Stick, 3xHSM100� 7xACT ZDM230, 1xEverspring SM103, 2xACT HomePro ZRP210.
    X10 = CM12U, 2xAM12, 1xAW10, 1 x TM13U, 1xMS13, 2xHR10, 2xSS13
    Other Hardware = ADI Ocelot + secu16, Global Cache GC100, RFXtrx433, 3 x Foscams.
    Plugings = RFXcom, ActiveBackup, Applied Digital Ocelot, BLDeviceMatrix, BLGarbage, BLLAN, Current Cost, Global Cache GC100,HSTouch Android, HSTouch Server, HSTouch Server Unlimited, NetCAM, PowerTrigger, SageWebcamXP, SqueezeBox, X10 CM11A/CM12U.
    Scripts =
    Various

    Comment


    • #3
      Originally posted by enigmatheatre View Post
      Yes. This is what the API mode is for on the boards. You can send the information to HS form your own sketches.

      Greig.
      It seems to me I forgot to read the manual … The api mode makes the plugin much more interesting. Thanks!

      Comment


      • #4
        Originally posted by ANTOLIVEIRA View Post
        Hello!

        I am using an arduino mega with multiple analog inputs connected to various sensors and digital relay outputs, connected to the HS3 by ethernet.
        This system works well.

        The point is that I wanted to start monitoring in HS3, instantaneous power and the total energy consumed.

        The power and energy information is available on another arduino mega that analyzes the number of pulses of the electricity meter in a given time period, the calculations are made in the mega and is available in the arduino serial output.

        Is there any way to use this plugin to pass this information to two HS3 devices (power and energy)?

        How can I manage the information that comes to me via serial port in order to assign it to the correct devices in HS3?

        Thanks
        This is exactly what I'm doing: I use an nodemcu with API sketch. It count total pulse in a day, the time between every pulse and calculate the power, To send data to homeseer simply "SendToHS(1, power)"
        API mode is fantastic world!

        Comment


        • #5
          Trying to do something similar. How does the code work when passing the data? If we have a device on A0 is it as simple as SendToHS(1,A0) or does A0 need declared? Its been forever since doing this type of programming and I can't remember. Trying to pull soil sensor readings using NodeMCU. I'm hoping to put a few in my yard to determine why its so muddy

          Comment


          • #6
            Originally posted by enigmatheatre View Post
            Yes. This is what the API mode is for on the boards. You can send the information to HS form your own sketches.

            Greig.
            Concerning the API mode,
            is there any restriction on using arduino interrupts in my code?

            Can you post some example code for reading and writing to HS3 in order to minimize the learning curve?

            Comment


            • #7
              Originally posted by ANTOLIVEIRA View Post

              Concerning the API mode,
              is there any restriction on using arduino interrupts in my code?

              Can you post some example code for reading and writing to HS3 in order to minimize the learning curve?

              Hi Greig,
              I just checked the API mode with a little program on the arduino mega.
              The program simply reads four analog ports and transmits the information to the HS3.
              It also includes the code needed to count pulses and display the value of power and energy.
              (my target!)
              My point is that I have not come to any conclusion...
              It all started to work fine, but after a few hours I lost the connection and did not worked anymore.
              I do not usually have connection loss problems in arduino mode.
              Can you get a look at the code to see if there's something I'm doing wrong and can justify this erratic behavior?
              Obviously I'm not a programmer…


              Thanks

              Attached Files

              Comment


              • #8
                Hi ANTOLIVEIRA,
                I'm not Greig and not a skill programmer but 2 consideration on your sketch:
                1) I think that that interrupt can impact on Arduino plugin. I already tested with not success the same condition (interrupt) exactly for a WattMetter (pulse).
                2) For analogues pin should be better to use a timer (use millis) in order to send the data every x seconds. Your sketch could generate a data flooding.
                I'm my sketch I send data to homeseer only if the data is not egual to previous and only every x seconds. In this mode there is not a lot data communication.

                For a watt meter, consider to use "pulsein" function.

                This is my sketch:
                Code:
                pinval = digitalRead(getpulsepin);   // legge il pin del sensore
                
                  if ((state == 1) && (pinval == 0) && (arduino_riavviato == 0)) { // punto di transizione
                    duration = millis() - startime;       // calcola la duration della pulsazione
                    startime = millis();            // setta il nuovo tempo di partenza
                    conteggio_impulsi = conteggio_impulsi + 1;
                    power = 3600.0 / duration * 1000; // calcola consumo
                    duration3 = duration / 1000.0;  //duration in seconds
                Then you can send power, duration3 and the number of pulse (conteggio_impulsi) to homeseer.


                Comment


                • #9
                  Like khriss75 said I think the problem is you are flooding the plugin with data. You need to control how often the data is sent to the plugin from the board otherwise it will cause problems.
                  I have not used interrupts in any of my code but can not see a reason for this to cause problems unless it is blocking like Delay().

                  Greig.
                  Zwave = Z-Stick, 3xHSM100� 7xACT ZDM230, 1xEverspring SM103, 2xACT HomePro ZRP210.
                  X10 = CM12U, 2xAM12, 1xAW10, 1 x TM13U, 1xMS13, 2xHR10, 2xSS13
                  Other Hardware = ADI Ocelot + secu16, Global Cache GC100, RFXtrx433, 3 x Foscams.
                  Plugings = RFXcom, ActiveBackup, Applied Digital Ocelot, BLDeviceMatrix, BLGarbage, BLLAN, Current Cost, Global Cache GC100,HSTouch Android, HSTouch Server, HSTouch Server Unlimited, NetCAM, PowerTrigger, SageWebcamXP, SqueezeBox, X10 CM11A/CM12U.
                  Scripts =
                  Various

                  Comment


                  • #10
                    Originally posted by enigmatheatre View Post
                    I have not used interrupts in any of my code but can not see a reason for this to cause problems unless it is blocking like Delay().

                    Greig.
                    Hi Greig,
                    some time ago (when the plugin was alpha (need to declare in and out in the sketch) I tried interrupt with no good results. Sure, could be that my sketch was not correct.
                    My question: using intterupts in your sketch is not like use a delay? If arduino need to send something to hs via plugin and the programs stops for the interrupt, is not problematic? Sure, after interrupt the program restart from the end point but there is not the possibility to stop or slow down the data arduino <--> HS?

                    Comment


                    • #11
                      Originally posted by khriss75 View Post

                      Hi Greig,
                      some time ago (when the plugin was alpha (need to declare in and out in the sketch) I tried interrupt with no good results. Sure, could be that my sketch was not correct.
                      My question: using intterupts in your sketch is not like use a delay? If arduino need to send something to hs via plugin and the programs stops for the interrupt, is not problematic? Sure, after interrupt the program restart from the end point but there is not the possibility to stop or slow down the data arduino <--> HS?
                      Yes this is what I was saying if it is blocking it could miss data from HS and cause problems.

                      Greig.
                      Zwave = Z-Stick, 3xHSM100� 7xACT ZDM230, 1xEverspring SM103, 2xACT HomePro ZRP210.
                      X10 = CM12U, 2xAM12, 1xAW10, 1 x TM13U, 1xMS13, 2xHR10, 2xSS13
                      Other Hardware = ADI Ocelot + secu16, Global Cache GC100, RFXtrx433, 3 x Foscams.
                      Plugings = RFXcom, ActiveBackup, Applied Digital Ocelot, BLDeviceMatrix, BLGarbage, BLLAN, Current Cost, Global Cache GC100,HSTouch Android, HSTouch Server, HSTouch Server Unlimited, NetCAM, PowerTrigger, SageWebcamXP, SqueezeBox, X10 CM11A/CM12U.
                      Scripts =
                      Various

                      Comment


                      • #12
                        Hi, khriss75!

                        it's good to know that there's someone here who already did what I'm trying to do

                        The part of the sketch relating to the analog inputs was made only to be sure that there was no difficulty transmitting this information to the devices created in the HS3
                        At the beginning I did not put any restrictions on the transmission of information and I could see in the "Last Change Column" the devices to be updated every second
                        Obviously this situation is neither acceptable nor necessary
                        Then I put the restriction of only transmitting to HS3 if the difference between successive readings was significant and I made several experiments to the point of totally preventing communication
                        The truth is that I had situations in which I was able to receive the information update of the analog inputs and the power and power consumption at very high rates and other situations in which although no information was transmitted from the analog inputs I could not have energy readings... (and the flow in the sketch is independent)
                        I spent several hours trying various combinations and small changes in the sketch; even just with the routine of the interrupt the behavior appears to be random and there are situations in which even after turning off the HS3 and the arduino, on reboot, the board does not connect...

                        To summarize: I am aware of the need to only transmit as often as necessary and that the sketch is not optimized for this, but this sketch was only used to test the communication. My conclusion is: If even without information transmission of the analog inputs I have had erratic behavior, I think I can draw the conclusion that I can not actually use interrupts, since apparently the procedure of download the sketch and the sketch (itself) appear to be sufficiently correct.

                        Next steps: I will delete the sketch power/energy interrupt and create a timing to send the other information. I will check connection and data

                        @khriss75: concerning the pulse detection whitout interrupt, I was thinking of connecting the watt meter output to an analog input and check through the serial which would be the range of values that are read at the pulse momentum. Thus create a trigger value and whenever that port reaches this value consider that there was a pulse. It seems that you solved differently ... In your code to detect the pulse, what is the meaning of the "state" and the "arduino_riavviato" vars?


                        Thanks!

                        Comment


                        • #13
                          Originally posted by enigmatheatre View Post
                          Like khriss75 said I think the problem is you are flooding the plugin with data. You need to control how often the data is sent to the plugin from the board otherwise it will cause problems.

                          Greig.
                          Although I fully understand the answer, given the above situation it seems to me that the problem lies in the interrupt

                          Comment


                          • #14

                            @khriss75: concerning the pulse detection whitout interrupt, I was thinking of connecting the watt meter output to an analog input and check through the serial which would be the range of values that are read at the pulse momentum. Thus create a trigger value and whenever that port reaches this value consider that there was a pulse. It seems that you solved differently ...
                            Just thinking ... another way would be to leave the interrupt in a small dedicated arduino and send the information via the serial to the arduino that is connected to the plugin ...

                            Comment


                            • #15
                              Originally posted by ANTOLIVEIRA View Post

                              Just thinking ... another way would be to leave the interrupt in a small dedicated arduino and send the information via the serial to the arduino that is connected to the plugin ...
                              Yes, this is the goal :-)
                              I use for my watt meter a nodemcu. I simply count the time every 2 pulse and calculate the power.

                              Originally posted by ANTOLIVEIRA View Post
                              In your code to detect the pulse, what is the meaning of the "state" and the "arduino_riavviato" vars?
                              Now I have to check my sketch because I don't remember well but the "state" variable is to check if the state of the pin is changed in order to "listen" the pulse.
                              I added an other variable to check if arduino was restarted (arduino riavviato = arduino restarted)... why?
                              Simple, arduino count every pulse (one pulse is one Wh). Every pulse, arduino send to HS the total pulse. If I restart arduino, or if arduino reset/restart I lose the count of pulse (power consumption). So, if "arduino_riavviato" var is 1 (arduino restarted), arduino read the "old" number of pulses from HS, in this way, arduino can sum other pulse to the previous... (It is hard for me to explain... :-) )

                              If you want, I can share with you my sketch.

                              Originally posted by ANTOLIVEIRA View Post
                              concerning the pulse detection whitout interrupt, I was thinking of connecting the watt meter output to an analog input and check through the serial which would be the range of values that are read at the pulse momentum.
                              Sorry, I don't understand... If is a pulse, why you want to check as analogue signal?

                              Comment

                              Working...
                              X