No announcement yet.

Sending HTTPS commands to Particle Photon

  • Filter
  • Time
  • Show
Clear All
new posts

    Sending HTTPS commands to Particle Photon

    hi all,

    converting from a vera to HS3 finally, and wanted to get peoples advice on the best way to send commands to my particle photon. Basically I need to send SSL commands to send and get data.

    Lets start with the easy one, the code below would send a message to my photon. in vera i would do this via Luup:
    local socket = require('socket')
    local https = require('ssl.https')
    local ltn12 = require('ltn12')

    https.TIMEOUT = 5

    local body, code, headers, status = https.request("{device}/led","arg=9,255,255,0&access_token={token})

    return true

    very simple, it would basically POST via SSL to my photon.

    What would be the best way to do something like this via scripting in HS3?

    Take a look at my example here which should get you going;


      Perfect. I ended up with this code:

      Const LT As String = "Particle"
      Const DeviceID As String = "deviceID"
      Const AccessToken As String = "AccessToken"

      Sub Main(Parm As Object)

      Dim URL As String = "" & DeviceID & "/led" 'led is the name of our access point
      Dim responsebytes() As Byte
      Dim commandToSend As String = "9,255,255,0"

      Using Wclient As New Net.WebClient
      Dim headerlist As New Specialized.NameValueCollection
      headerlist.Add("access_token", AccessToken) 'Send the access token
      headerlist.Add("params", commandToSend) 'to match the entry command in the spark code
      responsebytes = Wclient.UploadValues(URL, "POST", headerlist)
      hs.writelog(LT, "Reply: " & System.Text.Encoding.ASCII.GetString(responsebytes))
      End Using

      Catch ex As Exception : hs.writelog(LT, "Exception: " & ex.Message.ToString)
      End Try
      End Sub

      and I get this in the log:
      May-30 12:26:42 PM Particle Reply: {"id":"devideID","last_app":"","connected":true,"return_valu e":1}



        No longer working

        This worked for quite sometime, but during the last update on Homeseer for me it stopped.

        when i run the script i now get

        Exception: Error getting response stream (Write: The authentication or decryption has failed.): SendFailure

        and i really dont know enough to know why.

        If i run my command via curl on my pc everything works so i know my token/device_id/events etc are all ok.

        any ideas on what to check?

        also, does anyone have an example calling curl from a vb script? i could do that just as easy as webclient
        Last edited by jventerprises; July 13, 2018, 12:34 PM.


          using curl and particle functions

          well, i figured out how to replace the webclient which no longer works with curl, and have posted what i did to help others.

          first, i have a particle device that accepts a function called led. it has 4 arguments: led, red, green, blue. these get passed to the particle function as a string like this: led,red,green, blue

          i used
          • putty to get into homeseer
          • winSCP to transfer files back and forth
          • dos2unix to remove all the hidden windows formatting since i wrote on my PC

          i created script called and placed in into /usr/local/HomeSeer/scripts.


          echo $PARAM

          curl[id]/led -d arg=$PARAM --data-urlencode access_token=[token]

          i added that directory to the path
          export PATH=$PATH:/usr/local/HomeSeer/scripts)

          i made sure the script was executable:
          chmod +x

          i checked that it works by typing on the command line
          ./ 10 255 128 64

          now create an event in Homeseer and select RUN ANOTHER PROGRAM OR PROCESS not (RUN A SCRIPT), select your script and add you params under the advanced tab. params here should be seperated by spaces, not commas.

          and you are done!