Announcement

Collapse
No announcement yet.

Arduino Script Testing. (Enigmatheatre)

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

  • enigmatheatre
    replied
    HI gdyrdave,

    I have dug out a backup of the script and compiled a new version but have not had time to test it.
    If backup your Arduino.vbn file and replace it with the one attached then add the line "Baud=" without quotes to the arduino.ini then set this to the value you require. It will default to 115200 if the script can not find this value in the ini.

    I hope this works for you.

    Greig.
    Last edited by enigmatheatre; April 25, 2014, 06:51 PM.

    Leave a comment:


  • mrhappy
    replied
    This is a simpler one that I am using that reads 8 digital inputs from my Alarm panel. The script on the Arduino just throws the data out of the serial port in the format "#0:0:0:0:1:1:0:0" representing D2 to D10.

    Code:
    Dim DC As Byte = 25
    Const HC As String = "W"
    Const LT As String = "AlarmIO"
    Const PN As Integer = 11 'this is the port number
    
    Sub Main(ByVal Parms As Object)
    
        Dim RecData As String = Parms.ToString
        If hs.ison("Q13") Then my.computer.filesystem.writealltext(hs.getapppath & "\data\debug.csv", now() & ", AlarmIO," & parms.tostring & vbNewLine, True)
    
        hs.setdevicestring(HC & (DC + 8), Now(), True)
    
        Dim ArData() As String
    
        RecData = RecData.Replace("#", "")
        ArData = RecData.Split(":")
    
        For i As Integer = 0 To ArData.GetUpperBound(0)
            If ArData(i) = "1" Then
                hs.setdevicestatus(HC & DC + i, 2)
            ElseIf ArData(i) = "0" Then
                hs.setdevicestatus(HC & DC + i, 3)
            Else
                hs.setdevicestatus(HC & DC + i, 17)
            End If
        Next
    
    End Sub
    
    Sub Watch(ByVal Parms As Object)
    
        Dim TS As New TimeSpan
        ts = DateTime.Now - Convert.ToDateTime(hs.devicestring(HC & (DC + 8)))
    
        If TS.Minutes > 5 Then
            Log("Data Has Not Changed In Five Minutes")
            hs.setdevicevalue(HC & (DC + 8), 1)
        Else : hs.setdevicevalue(HC & (DC + 8), 0)
        End If
    
    End Sub
    
    Sub OpenP(ByVal Parms As Object)
        hs.closecomport(PN)
        Log("Port Close Attempt")
        hs.waitsecs(2)
        Dim ReplyStr As String = hs.opencomport(PN, "9600,N,8,1", 1, "alarmIO.vb", "Main")
        If ReplyStr IsNot "" Then Log("Reply:" & replystr)
        Log("Port Open Attempt")
    
    End Sub
    
    Sub Log(ByVal Data As String)
        hs.writelog(LT, Data)
    End Sub
    
    Sub CDevices(ByVal Data As Object)
    
        Dim objDevice As Object
        For i As Integer = 1 To 9
            If hs.deviceexists(HC & DC) <> -1 Then
            Else
                If i = 9 Then objDevice = hs.NewDeviceEx("AlarmIO Status") Else objDevice = hs.NewDeviceEx("AlarmIO Input " & i)
                objDevice.location = "AlarmIO"
                objDevice.hc = HC
                objDevice.dc = Trim(Str(DC))
                objDevice.misc = &H10
                objDevice.dev_type_string = "AlarmIO Input Device"
                hs.SetDeviceStatus(objDevice.hc & objDevice.dc, 3)
                Log("Creating Device: " & HC & DC)
            End If
            DC += 1
        Next
    End Sub
    I run the CDevices function once to create nine devices (eight inputs and one status that holds the date/time of the last update, just used to watch whether or not the port is still connected because I am using Bluetooth serial devices).

    When HS starts I run the "OpenP" function that tries to open the COM port at the specified baud rate, giving the function that is called when serial data arrives.

    When the serial port gets a new line it runs the Main routine, I remove the first "#" and then split up the remainder of the line by the colon. Testing the bit between the respective colon I then set a device on/off. I have another device that is a temperature sensor also using Bluetooth serial transceivers, the script is mostly the same except the Main routine just converts the parameter into a value for temperature and sets a device.

    Code:
    Sub Main(ByVal Parms As Object)
    
        If hs.ison("Q13") Then my.computer.filesystem.writealltext(hs.getapppath & "\data\debug.csv", now() & ", BlueTemp," & parms.tostring & vbNewLine, True)
    
        hs.setdevicestring(HC & (DC + 1), Now(), True)
    
        Dim CTempVal As Double = Convert.ToDouble(Parms.ToString) - offset
    
        hs.setdevicestring(HC & DC, HTMLStr & Format(CTempVal, "00.0") & " C", True)
        hs.setdevicevalue(HC & DC, Math.Round(CTempVal, 2) * 10)
    
    End Sub

    Leave a comment:


  • gdyrdave
    replied
    Thanks Mrhappy. My scripting is very rusty these days. Can you give me an example of one that receives data from the com port and parses the data and creates a device for it if it does not exist. It might jog my memory. Data is sent 57600 no parity in the same format as Enigmatheater's sketch. I still won't give up on his use but wouldn't mind getting data from this for the time being. Any help will be appreciated.

    Leave a comment:


  • mrhappy
    replied
    Originally posted by gdyrdave View Post
    UPDATE: I managed to get the Ph sensor to work and sent out the RF1. I set it for 115200 and connected it to HS2. It doesn't see it. I am not surprised though. Must be some format that the plugin needs to create a device. Any way still plugging at it.
    Not wanting to step on enigmatheatre's toes here but it is relatively easy to get a script going to read data from an arduino and put it into some HS devices. I put a couple of DHT11's and an I2C UV/light sensor in yesterday and the script is not that complex, splits up the serial data from the arduino and then sets some HS devices.

    Leave a comment:


  • gdyrdave
    replied
    UPDATE: I managed to get the Ph sensor to work and sent out the RF1. I set it for 115200 and connected it to HS2. It doesn't see it. I am not surprised though. Must be some format that the plugin needs to create a device. Any way still plugging at it.

    Leave a comment:


  • gdyrdave
    replied
    Here is my progress so far. I have the arduino communicating to a terminal program via Xbees. Have garbage at 115200 but at 57600 it works great. Now if I can only slow the baud rate to 57600 in the homeseer plugin I am in like flint. It is sending temperatures just fine.

    I will try to use the HS3 plug at some time but I need to interface a Ph sensor using software serial and try to transmit like a one wire sensor for the time being. At least making some progress. This will be a pool monitor to monitor the ph, pool temp, and the solar panel heating system. Next???? I'll dream of something.

    Dave

    Leave a comment:


  • gdyrdave
    replied
    Thanks alot Greig. I appreciate this. I will eventually upgrade to 3 after I figure out how to bypass the plugin problem. I am redoing a system with a fresh W7 system and HS3. Will test the new version of your plugin on it. This was a fantastic idea and great plug.

    Thanks again

    Leave a comment:


  • enigmatheatre
    replied
    If I have time and more to the point can find the code as I have a hard drive fail a while back and am not sure what I have recovered then I will have a look and send you a changed copy.

    But there are no promises on time or if this will happen.

    Greig.

    Leave a comment:


  • gdyrdave
    replied
    Thanks Greig. I would move up to HS3 but there are a few plugins I use that haven't been ported to HS3 yet or will never be ported. I just need to slow the transmission rate to the Xbees. Getting a lot of garbage transmissions between the 2 at 115200. Just wish I could change it to 9600 for a test.

    Leave a comment:


  • enigmatheatre
    replied
    Originally posted by gdyrdave View Post
    This may be a stupid question, but will the HS3 plug work with HS2 or are they totally different?
    There is not such a thing as a stupid question if you don't know the answer.
    The script for HS2 was rewritten and converted in to a full plugin for HS3 so it is much easier to use so no it is not compatible with HS2.

    Greig.

    Leave a comment:


  • gdyrdave
    replied
    This may be a stupid question, but will the HS3 plug work with HS2 or are they totally different?

    Leave a comment:


  • enigmatheatre
    replied
    Originally posted by gdyrdave View Post
    Is this thread still alive????
    Sorry for not replying sooner but life is very busy at the moment.
    In answer to your question No it is hard coded in to the script and I have stopped working on HS2 in replacement of my HS3 plugin found HERE. I could add this as an option in the plugin for HS3 if you would like but I cant give a time because as I said before life is taking over the Hobby.

    Sorry,

    Greig.

    Leave a comment:


  • gdyrdave
    replied
    Is this thread still alive????

    Leave a comment:


  • gdyrdave
    replied
    Is there anyway to change the baud rate in Homeseer lower. like 57600 or lower? I know I can change it in the .ino file but in the Homeseer PC.
    I want to use it with Xbee's and I think 115200 is too fast for the radios. Is the source for the (vben) script available or can someone change it for me. From 9600 to 115200. Thanks
    Last edited by gdyrdave; April 15, 2014, 06:38 PM.

    Leave a comment:


  • gdyrdave
    replied
    Yes thats funny. Trying to cut the cord by using 2 RF1's. I need to make a transciever out of this code and make another plain tranciever for the HS2 side. I have been using HS since 2001. And it evolved for 3 homes. This is my last home now. I want to monitor the solar heater for the pool and ultimately be able to open or close the valve to the panels and ultimately be able to monitor the pH and control the pump. After that maybe some other things too like the neighbors home across the street. Can't upgrade to HS3 yet because there are plugins I use that aren't compatable. Nice to see you here.

    Dave

    Leave a comment:

Working...
X