Announcement

Collapse
No announcement yet.

Sending HTTPS commands to Particle Photon

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

  • jventerprises
    replied
    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 jons_curl.sh and placed in into /usr/local/HomeSeer/scripts.
    #!/bin/bash

    led=$1
    red=$2
    green=$3
    blue=$4

    PARAM=$1","$2","$3","$4
    echo $PARAM

    curl https://api.particle.io/v1/devices/[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 jons_script.sh

    i checked that it works by typing on the command line
    ./jons_curl.sh 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!

    Leave a comment:


  • jventerprises
    replied
    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.

    Leave a comment:


  • jventerprises
    replied
    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)

    Try
    Dim URL As String = "https://api.particle.io/v1/devices/" & 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}


    thanks!

    Leave a comment:


  • mrhappy
    replied
    Take a look at my example here which should get you going; https://forums.homeseer.com/showthread.php?t=175638

    Leave a comment:


  • jventerprises
    started a topic Sending HTTPS commands to Particle Photon

    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("https://api.particle.io/v1/devices/{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?
Working...
X