Announcement

Collapse
No announcement yet.

push data out of zee s2

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

    push data out of zee s2

    could someone point me in the right direction, please provide an example script that runs on s2 and can push data out to a remote cloud service like ubidots, googlesheets, etc.

    I like to push my temperature/humidity data from multiple sensors to some sort of cloud dashboard service on regular time intervals.

    thank you

    #2
    This is a script I was running that posted data to ThingSpeak which sounds like a similar service.

    Code:
    Imports System.Net
    Imports System.Text
    Imports System.IO
    
    Sub Main(ByVal Parms As Object)
    
        Try
            'each channel will have a new API key
            Dim wAPIKey As String = Nothing 'writing API key
            Dim rAPIKey As String = Nothing 'reading API key
            Dim dList() As Integer
            Dim sData As String = Nothing
            Dim sR As WebRequest
            Dim ChannelID As String = convert.toint64(Parms.ToString)
    
            Select Case ChannelID
                Case 74657
                    wAPIKey = ""
                    rAPIKey = ""
                    dList = {141, 38, 104, 448, 159, 534, 151S, 453}
                Case 74665
                    wAPIKey = ""
                    rAPIKey = ""
                    dList = {449}
                Case 74683
                    wAPIKey = ""
                    rAPIKey = ""
                    dList = {252, 291}
            End Select
    
            'L("Write API Key Selected: " & wAPIKey)
            'L("Read API Key Selected: " & rAPIKey)
    
            If BuildDataString(dList) <> "error" Then
    
                sR = WebRequest.Create("http://api.thingspeak.com/update")
                Dim dArr() As Byte = Encoding.UTF8.GetBytes(BuildDataString(dList))
    
                sR.Method = "POST"
                sR.ContentLength = dArr.Length
                sR.ContentType = "application/x-www-form-urlencoded"
                sR.Headers.Add("X-THINGSPEAKAPIKEY", wAPIKey)
    
                Dim dataStream As Stream = sR.GetRequestStream()
                dataStream.Write(dArr, 0, dArr.Length)
                dataStream.Close()
    
                Dim response As WebResponse = sR.GetResponse()
                Dim responseStr As String = CType(response, HttpWebResponse).StatusDescription
    
                If responseStr <> "OK" Then L("Server Response: " & responseStr)
                response.Close()
    
            End If
    
        Catch ex As Exception : L("Exception: " & ex.message.tostring)
        End Try
    
    End Sub
    
    Sub L(ByVal LogEntry As String)
        If convert.toboolean(hs.getvar("scriptdebugmode")) Then hs.writelog("ThingSpeak", LogEntry)
    End Sub
    
    Function BuildDataString(ByVal DeviceList() As Integer) As String
    
        Try
            Dim k As Byte = 1
            Dim sb As New StringBuilder
    
            For Each devReference As Integer In DeviceList
                'presume that it is done on a sequential basis
                sb.Append("field" & k & "=")
                sb.Append(hs.devicevalueex(devReference)) 'should check the device exists
                sb.Append("&")
                k += 1
            Next
    
            sb.Remove(sb.Length - 1, 1)
            Return sb.ToString
    
        Catch ex As Exception
            L("BuildDataString Exception: " & ex.message.tostring)
            Return "error"
        End Try
    
    End Function

    Comment


      #3
      Thank you, really appreciate it.

      Seems pretty involved for a newbie coder,
      but gives me a good guideline.

      It is too bad there isn't a plugin or interface for newbies or lesser code talented where you would populate bunch of ref ids in some sort of table, choose your endpoint url, and select your push time interval.
      I was messing around with https://www.hurl.it/ to test the remote service, it would be nice if an interface like that was built into a plugin.

      anyway, I digress...

      cheers.

      Comment


        #4
        Originally posted by Amigo View Post
        Thank you, really appreciate it.

        Seems pretty involved for a newbie coder,
        but gives me a good guideline.

        It is too bad there isn't a plugin or interface for newbies or lesser code talented where you would populate bunch of ref ids in some sort of table, choose your endpoint url, and select your push time interval.
        I was messing around with https://www.hurl.it/ to test the remote service, it would be nice if an interface like that was built into a plugin.

        anyway, I digress...

        cheers.
        I think half the battle would be that there is zero standard for all of these cloud services, some have API keys that go in the headers, some in the URL, some want JSON, some want XML, some want plain text, some need encoding etc so you are just as well to have a separate script for it. That script more complex than simply throwing data (it accepts the channel as the parameter so you can pick it, then depending on the channel depends on the device values it uploads) at it but probably getting towards the simplest it could be.

        Comment


          #5
          I completely agree.
          I think one has to pick a couple of dashboard/cloud services that one likes and focus on their interface.

          I have a small project that I need to get off the ground fairly quick, let me know if you want to/interested in some freelance work.

          cheers,
          Amigo

          Comment


            #6
            Using the RPi2-Zee S2 allow also for use of Perl and Python scripting. I do that today for my tiny in the attic Maxim DS9097 1-wire network. I combined both HS3 stuff and just basic Linux OS stuff for my 1-wire temperature and humidity sensors. Just recently here also installed a combination RTC / 1-wire network using a tiny DS-1307 in a small tabletop computer with an RTC and no battery (RTC1). It is just a bit of bit banging stuff. Easy to do a sym link from RTC1 to RTC.

            You can do the same with the RPi2 running Linux and the blending of Homeseer 3 events, variables, scripts, plugins and base stuff of the OS.

            It is all documented and there are many ways to do this. Relating to cloud services projects many of the roots of this stuff is related to RPi2 / Aduino projects.

            This stuff like my weather stations (one running on an RPi2) just push a CSV file over to a host site which makes sense out of it.
            Last edited by Pete; July 2, 2016, 03:12 PM.
            - Pete

            Auto mator
            Homeseer 3 Pro - 3.0.0.548 (Linux) - Ubuntu 18.04/W7e 64 bit Intel Haswell CPU 16Gb
            Homeseer Zee2 (Lite) - 3.0.0.548 (Linux) - Ubuntu 18.04/W7e - CherryTrail x5-Z8350 BeeLink 4Gb BT3 Pro
            HS4 Lite - Ubuntu 22.04 / Lenovo Tiny M900 / 32Gb Ram

            HS4 Pro - V4.1.18.1 - Ubuntu 22.04 / Lenova Tiny M900 / 32Gb Ram
            HSTouch on Intel tabletop tablets (Jogglers) - Asus AIO - Windows 11

            X10, UPB, Zigbee, ZWave and Wifi MQTT automation-Tasmota-Espurna. OmniPro 2, Russound zoned audio, Alexa, Cheaper RFID, W800 and Home Assistant

            Comment


              #7
              That is great info, thank you.
              I have to down the rabbit hole and check it out.

              cheers.

              Comment

              Working...
              X