Announcement

Collapse
No announcement yet.

Arduino Script Testing. (Enigmatheatre)

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

    This is something I have on my list of things to do.
    I want to make it possible to send the data for all boards to one port so you can use one wireless gateway for all boards.

    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


      The Moteino is totally open source. You can pick up all the board schematics and designs from lowpowerlab.com and build your own from scratch.
      All sotware required to make them work is available for free, all thanks to the work of Felix Rusu.

      If you want to avoid all that hussle, just give your credit card a run for the money and order a couple of Moteinos from Felix at https://lowpowerlab.com/shop

      As I mentioned before, I have no affiliation with them. I'm just a very satisfied customer.

      There is also a very good support forum at https://lowpowerlab.com/forum
      with lots of knowledgeable people on board ready to help you out, withou any "attitude" wathsoever, no matter what you ask.

      My knowledge on this matters was very low when I started and managed to increase my know-how regarding HS2, microcontrollers, arduinos and radio controlled devices just by googling stuff on the net.

      A basic berebones Moteino board with the Atmel chip pre-assembled will cost you $12.95 plus ship. You can get the radio daughter board and solder it yourself, or you can ask for it to be pre-assembled, which I highly recommend.

      So the minimum initial costs are:

      1 - R4 Moteino, with
      - Moteino Transceiver: RFM69HW - 868/915Mhz
      - Extras (flash memory): With 4Mbit flash chip
      - Extras (headers): add male side header
      -----> $23.95

      1 - USB Moteino, with
      - Moteino Transceiver: RFM69HW - 868/915Mhz
      - Extras (flash memory): With 4Mbit flash chip
      - Extras (headers): add male side header
      -----> $29.95

      1 - FTDI adapter
      -----> $14.50

      Total: $68.40 + $2.80 (shiping to USA) = $71.20

      You could get the FTDI adapter on ebay much cheaper from China (http://www.ebay.com/ftdi) but I don't mind spending a bit more and $upport what Felix is doing.

      There is also a Moteino Mega, which is the equivalent of the Arduino Mega, with a lot more of I/O. Some of the I/O pins are dedicated to control the radio so they are not available. Plus, one of the Interrupt pins is used for the wakeup function. So if you want to use a lot of pins, you should get the Mega, which costs the same as the USB Moteino. The Mega doesn't have the USB plug, so another FTDI adapter is required for this one.

      To interface a Moteino with HS2 (I don't have HS3, sorry), all that is required is that you create some sort of communication protocol between them, and pass all the data that comes trough the COM port.

      To do this, you start by editing your Startup.txt file (in C:\Program Files\HomeSeer HSPRO\Scripts) and add
      Code:
           hs.run "comport_open.txt"
      
      End Sub
      before the End Sub.

      This orders HS to open a file named comport_open.txt, which is in the same Script directory (in C:\Program Files\HomeSeer HSPRO\Scripts), at startup and run its contents.

      The file comport_open.txt, in my case, contains the following script:

      Code:
       com port script to send/receive data to/from a COM port
      ' this script registers a callback script named com_event.txt
      ' when data is received on the COM port the com_event.txt script is called and the
      ' data can be processed there
      ' this script only needs to be called once as the com port will stay open
      sub main()
          dim e
      
          e=hs.OpenComPort(8,"115200,n,8,1",1,"com_event.txt","main")
          if e <> "" then
              hs.writelog "Error opening com port",e
          else
              hs.writelog "COM 8","Port correctly OPEN"
          end if
          
          ' if you need to send data to the com port when the port is open, it can be done here
          ' hs.SendToComPort 5,"data"+vbcrlf
              
           hs.writelog "COM SCRIPT","Script Complete"
      end sub
      All this script do is handling the opening of a comm port and assigning a script to handle what comes trough it and presents some logging of these action for debugging purposes.

      I which I could have enough know-how to create a way of making this com port number editable as if it was a HS device with editable properties and use it as a variable on the code. This way if the com port changes, I wouldn't have to run all overs all scripts looking for the com number to replace it for the new one.
      Code:
      hs.OpenComPort(8,"115200,n,8,1",1,"com_event.txt","main")
      Here we define the com port number that was assigned to our FTDI adapter or USB Moteino pluged into our HS computer. In my case it was COM8. Next is the Baud speed, data bit, stop bit and the last "1" is for strings mode.
      Com_event.txt is the event handling script, which contains the routines to handle what comes in or goes out from to the Moteino via the USB port.
      This com_event.txt file is also in the same Scripts subdir.
      "main" is the name of the function in com_event.txt to which we pass data.

      Let me show you my com_event.txt:

      Code:
      ' when mode is a 1, data is complete string
      
      sub main(data) '<---- Here is the main() function that was called and all data will be stored in a variable called "data"
      
      
      Const ForReading = 1
      Const comport = 8
      Const tank_min = 150 '150 cm for tank to be considered empty
      Const tank_max = 10 '10 cm for tank to be considered full
      Const pos_min = 252 '252 cm for garage gate to be considered closed
      Const pos_max = 5 '5 cm for garage gate to be considered open
      Dim tagFile
      Dim posNode_init
      Dim posNode_end
      Dim nodeNumber
      Dim posTag_init
      Dim posTag_end
      Dim tagNumber
      Dim FileToRead
      Dim tagLine
      Dim infoResult
      Dim tagDir
      Dim objFile
      Dim posTemp_init
      Dim posTemp_end
      Dim posDist_init
      Dim posDist_end
      Dim gateDist_init
      Dim gateDist_end
      Dim tempValue
      Dim fuelLevel
      Dim gatePos
      Dim fuelPercent
      Dim gatePercent
      Dim virt_device
      Dim default_hc
      Dim prev_result
      Dim e
      
      'virtual device list
      default_hc = "Z"
      
      tagDir = "C:\RFID\"
      tagFile = "tags.csv"
      FileToRead = tagDir & tagFile
      
      
          ' process the com port data here
      
          ' hs.writelog "COM DATA",data
      
      
      '=============================================================
      '        Check if incoming data is from RFID reader
      '=============================================================
      
      
          if instr(1,data,"TAGID") then
         
              posTag_init = instr(1,data,"Data 1:")+8
              posTag_end = instr(1,data,"Data 2:")-1
              'msgbox (Mid(data,posTag_init,posTag_end - posTag_init))       
              tagNumber = Mid(data,posTag_init,posTag_end - posTag_init)
              'Se o tag usado for o MASTER TAG
              If tagNumber = "xxxxxxxxx" Then
      
                  hs.Run "Pisca_luzes_pilares_Desarmar.vb"
                  hs.WaitSecs 1
                  hs.CloseComPort comport
                  error = hs.OpenComPort(comport,"115200,n,8,1",1,"new_tag.txt","main")
                  if e <> "" then
                      hs.writelog "Error opening com port",e
                  else
                      hs.writelog "COM 8","Port correctly OPEN"
                  end if
                      else
              'Se não for o MASTER tAG, ver se consta da lista de tags autorizados
                       Set objFSO = CreateObject("Scripting.FileSystemObject")
                  Set objFile = objFSO.OpenTextFile(FileToRead, ForReading)
                  Do Until objFile.AtEndOfStream 'lê o ficheiro linha a linha até encontrar o tag id
                      tagLine = objFile.ReadLine ' carrega o conteúdo da linha na variável tagLine
                      tagData = Split(tagLine, ";") ' espalha o conteúdo da linha pela array tagData
                      tagId = tagData(0)
                      name = tagData(1)
                      sched = tagData(2)
                      starttime = tagData(3)
                      endTime = tagData(4)
      
                      if tagNumber = tagId Then 'se o número enviado pelo RFID consta da lista
                          if sched = "Y" Then ' se existe um horário limite
      
                              if Hour(Now()) >= CInt(startTime) And Hour(Now()) < CInt(endTime) Then ' se está dentro do horário  permitido
                                  hs.writelog "RFID",name & " abriu o portão pequeno" ' faz um log da abertura do portão
                                  hs.SendToComPort 8,"#2/1/" ' abre o portão
                              else
                                  ' se não está no horário autorizado
                                  hs.writelog "RFID",name & " tentou abriu o portão pequeno fora do horário"
                                  hs.URLAction "https://www.freevoipdeal.com/myaccount/sendsms.php?username=luisr321&password=xxxxxxxxx&from=351xxxxxxxxx&to=351xxxxxxxxx&text=TENTATIVA DE ABERTURA DO PORTÃO PEQUENO FORA DO HORÁRIO!!!", "GET", "", ""
                              end if
                              exit do
                          else
                              'Se não há um horário restrito
                              hs.writelog "RFID",name & " abriu o portão pequeno"
                              hs.SendToComPort 8,"#2/1/"
                          end if
                          exit do
                      end if
                  Loop
                  objFile.Close()
              End if
          end If
      
      
      
      
      
      '=============================================================
      '        Check if incoming data is from the boiler
      '=============================================================
      
          if instr(1,data,"BOILR") then
      
              posTemp_init = instr(1,data,"Data 2:")+8
              posTemp_end = instr(1,data,"Data 3:")-1
              tempValue = Mid(data,posTemp_init,posTemp_end - posTemp_init)
              virt_device=default_hc+"80"
              prev_result=hs.DeviceString(virt_device)
              hs.SetDeviceString virt_device,tempValue,true
               if tempValue<>prev_result then
                  hs.SetDeviceLastChange virt_device, Now()
                  hs.SetDeviceValue virt_device,tempValue
              end if
      
              posDist_init = instr(1,data,"Data 3:")+8
              posDist_end = instr(1,data,"- ACK")-1
              fuelLevel = Mid(data,posDist_init,posDist_end - posDist_init)
             
              fuelPercent = CInt(((tank_min - int(fuelLevel/100)) * 100) / (tank_min - tank_max) )
             
              virt_device=default_hc+"81"
              prev_result=hs.DeviceString(virt_device)
              hs.SetDeviceString virt_device,fuelPercent,true
               if fuelPercent<>prev_result then
                  hs.SetDeviceLastChange virt_device, Now()
                  hs.SetDeviceValue virt_device,fuelPercent
              end if
      
          end if
      
      '=============================================================
      '        Check if incoming data is a PING!
      '=============================================================
      
          if instr(1,data,"PING!") then
      
              posNode_init = instr(1,data,"[")+1
              posNode_end = instr(1,data,"]")
              'msgbox (Mid(data,posNode_init,posNode_end - posNode_init))       
              nodeNumber = Mid(data,posNode_init,posNode_end - posNode_init)
              hs.writelog "PING!", "A Ping was received from node " & nodeNumber
          end if
      
      end Sub
      Data to be sent to HS is created in the Moteino Nodes by sensors or switches and has the following format: [NODE ID][nodeid][DATA 1:][data1][DATA 2:][data2][DATA 3:][data3] where the Node ID is a specific name, like BOILR or TADIG allowing me to refer to them by its function and not a number, then a RFID tag ID if the node is the RFID node, then some data like the temp of the water, and next some other data like the tank level.

      So for HS to look inside the "data" variable I use this function
      Code:
      if instr(1,data,"TAGID")
      In this case I'm checking if data was sent by the RFID node and then I process that according to my needs.

      To return something back to Moteino I established another protocol and push it out trough the com port with
      Code:
      hs.SendToComPort 8,"#2/1/"
      where 8 is the com port number, # marks the beguining of a data package, 2 is the node destination, 1 is the action that that node will interpret and act upon.

      This can be done as a logic established on the com_event.txt, as you can see above, os as an event fired from HS directly, like a order to close all gates when the alarm is turned on.

      To use an event on HS start some action on a Node, I just create an event that runs "&hs.SendToComPort 8,"#5/2/"" as a script, which in this case sends a "2" to the outer gate node, which is interpreted by its software as "PULSE RELAY 2", which will close the gate.

      The Gateway Moteino (the one connected to the HS computer by USB cable) is always watching for what comes trough the Serial Port and has a routine to check the data according to the established protocol.

      It then constructs a data package to be sent to the destination node and pushes it trough the radio.

      All Nodes Moteinos have a simple routine that handle the radio comunication and when something comes trough the receiver, it checks if the data is ment for it, and if it is, it reads what it is and acts upon its contents, with some algoritm defined by me.
      It may then control some relay to open a gate or whatever.

      I can post all the routines running on the Nodes or Gateway if required.

      I'm sure there must be a more efficient way of handling this com port data but, for me a good solution is one that works and this works well for me.

      Now go and buy some Moteinos and start an automation revolution. No more 100's of dollars for a light switch or thermostats.

      Comment


        Originally posted by luisr320 View Post
        The Moteino is totally open source. You can pick up all the board schematics and designs from lowpowerlab.com and build your own from scratch.
        Thanks for posting. Looks very interesting. It appears to be similar in intent as the mysensors.org system. There's a beta plugin available for it for HS3.

        Cheers
        Al
        HS 4.2.8.0: 2134 Devices 1252 Events
        Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

        Comment


          Hummm, great stuff at Mysensors.org. These Moteinos use the HOPE FRM69HW transceivers that have up to 2.7km demonstrated range and come neatly mounted on the underside of the board, so, no wires required.

          What really interest me is the HS plugin. But it looks like it is only for the HS3

          Comment


            Originally posted by luisr320 View Post
            Hummm, great stuff at Mysensors.org. These Moteinos use the HOPE FRM69HW transceivers that have up to 2.7km demonstrated range and come neatly mounted on the underside of the board, so, no wires required.

            What really interest me is the HS plugin. But it looks like it is only for the HS3
            That is a great form factor for the Moteino and having the rf module mounted right on the board does make it much more compact. However, it may shield the rf in certain directions. Pretty reasonable prices as well although with the Chinese modules, mysensors should be cheaper. Mysensors use modules in the 2.4Ghz band so see some advantages to Moteino where there's a few different frequency choices. Would be nice to have a plugin that supports both . The main reason I upgraded to HS3 was to take advantage of new and updated plugins. You may have to do the same.

            Cheers
            Al
            HS 4.2.8.0: 2134 Devices 1252 Events
            Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

            Comment


              Just waiting for the right promotion offer to jump on the HS3 wagon.
              There are 3 types of frequencies for the Moteino. You can choose from 433Mhz or 869/915 Mhz. There is also a wick antenna that you have to solder on to the board so there is no shielding problem for the radio to be on the lower side of the board.

              I have just finished assembling my Outer gate controlled and now I can open or close the gate with my phone or trough a event, like when I turn the alarm on.

              I'll post some photos of the project.

              Comment


                This project uses a couple of components:
                1 rectyfing bridge, 1 condenser, 2 transistors to control the relays, two relays and a LM2596 power regulator board (the blue thing) I got from ebay.

                The rectifying bridge is necessary because there is only 12v AC available in the box, so it must be converted into DC, filtered with the condenser and regulated to 5v.

                Here is my gate, with the control box on the left:


                Size fitting a perfoboard (top right):


                Parts layout, without the moteino installed:


                And now, with the moteino:


                Board spaghetti:


                All in its place, ready to use:


                Some more detail:

                Comment


                  Looks great, thanks for sharing!

                  Cheers
                  Al
                  HS 4.2.8.0: 2134 Devices 1252 Events
                  Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

                  Comment


                    Originally posted by enigmatheatre View Post
                    This is something I have on my list of things to do.
                    I want to make it possible to send the data for all boards to one port so you can use one wireless gateway for all boards.

                    Greig.
                    Hi Greig,
                    That sound even better. Not being af programmer to have this in your plugin would be great!
                    For mee the price of the smalls boards mentioned seems very attractive and combined with your plugin really cool.
                    Best,
                    Jakob Sand, I automate everything!

                    Comment


                      Homeseer devices

                      Perhaps I missed something but how do I create Homeseer devices and tie them to the Moteino world. I don't understand how or when you created any devices that represent the sensors.

                      BTW I am computerizing a chickencoop and want to use Jeenodes which I already have (very similar to Moteino) to monitor things such as temperature etc. and to open and close a sliding door to keep the fox out of the henhouse.

                      Comment


                        In my case, all devices are created as "Virtual Devices".
                        Then I pass values for it to display.

                        For instance:


                        virt_device="Z80"
                        hs.SetDeviceValue virt_device,tempValue

                        Will update the virt_device Value with the data received from the temperature probe.

                        Comment


                          OK, thanks

                          Comment


                            So you didn't use the enigmatheatre plugin for your devices. I was hoping to figure out a way to use the plugin for all my devices. I want to turn on a heat lamp if it is cold, open and close a sliding door mechanism morning and night, and fill the water dish and feed bowl when empty. If I understand correctly, you trigger an event with input from your sensors and use that to send commands through the com port to your devices using your packet definition. You use HS basically to display status, trigger events and log activity. I guess I could make that work in my case also but I was looking for a different approach.

                            Is there a reason why we cannot provide a moteino or jeenode wireless interface to the plugin? I wanted to use the devices established with the plugin or something like it and write vb scripts in HS to read their status and command them to perform the ON/OFF actions I desire. As you can tell, my expertise in this area is minimal.

                            Comment


                              Originally posted by alback View Post
                              So you didn't use the enigmatheatre plugin for your devices. I was hoping to figure out a way to use the plugin for all my devices. I want to turn on a heat lamp if it is cold, open and close a sliding door mechanism morning and night, and fill the water dish and feed bowl when empty. If I understand correctly, you trigger an event with input from your sensors and use that to send commands through the com port to your devices using your packet definition. You use HS basically to display status, trigger events and log activity. I guess I could make that work in my case also but I was looking for a different approach.

                              Is there a reason why we cannot provide a moteino or jeenode wireless interface to the plugin? I wanted to use the devices established with the plugin or something like it and write vb scripts in HS to read their status and command them to perform the ON/OFF actions I desire. As you can tell, my expertise in this area is minimal.
                              Take a look at post 182 in this thread where he describes how he's getting the data into HS. You should be able to do something similar for the Jeenodes.

                              There are currently two plugins that support Arduino's: Enigmatheatre's and MySensors. I use both for different purposes. There's currently no plugin that supports the Moteinos or the Jeenodes.

                              Cheers
                              Al
                              HS 4.2.8.0: 2134 Devices 1252 Events
                              Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

                              Comment


                                Thanks, I'll check them out.

                                Comment

                                Working...
                                X