Author Topic: Directv - HTTP GET commands via LUUP  (Read 1361 times)

Offline sdholden

  • Sr. Newbie
  • *
  • Posts: 31
  • Karma: +2/-1
Directv - HTTP GET commands via LUUP
« on: October 13, 2016, 10:25:24 pm »
I'm trying to add basic commands for my directv DVR to a scene. I know what the exact commands should be and I've tested them from a basic web browser and they work fine. I've tried the examples from the wiki and there must be a syntax error somewhere as I can't even get the scene to save with these code examples. I've tried many many variations on the 2 examples below, but I've yet to succeed. Any ideas?

Invoke HTTP URL with GET request (Method 1)
  -- 5 Second timeout
  local status, result = luup.inet.wget("http://192.168.1.20:8080/remote/processKey?key=poweron&hold=keyPress", 5)

Invoke HTTP URL with GET request (Method 2)
Based on code by Jim/jgc94131
  require('ltn12')
  local http = require('socket.http')
 
  -- 5 Second timeout
  socket.http.TIMEOUT = 5
 
  local response_body = {}
  local request_body = ''
 
  local r, c, h = socket.http.request{
    url = 'http://192.168.1.20:8080/remote/processKey?key=poweron&hold=keyPress',
    method = "GET",
    port = 80,
    headers = {
      ["Content-Length"] = string.len(request_body),
      ["Content-Type"] = "application/x-www-form-urlencoded"
    },
    source = ltn12.source.string(request_body),
    sink = ltn12.sink.table(response_body)

Offline akbooer

  • Master Member
  • *******
  • Posts: 5277
  • Karma: +229/-67
  • "Less is more"
Re: Directv - HTTP GET commands via LUUP
« Reply #1 on: October 14, 2016, 02:53:33 am »
Your first example looks OK to me.

Your second one is a complete mish-mash with unnecessary bits of code and undefined variables.  If you want to try the http module then this should suffice.

Code: [Select]
local http = require "socket.http"
local result, status = http.request "whatever_url_you_want"

3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P.
Razberry, MySensors Arduino, HomeWave, AltUI, DataYours, openLuup, ZWay, ZeroBrane Studio.

Offline sdholden

  • Sr. Newbie
  • *
  • Posts: 31
  • Karma: +2/-1
Re: Directv - HTTP GET commands via LUUP
« Reply #2 on: October 14, 2016, 08:25:20 am »
Thank you. I agree with your assessment of the code. I reverted to those two code examples from here: https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&uact=8&ved=0ahUKEwiLk4SKpNrPAhXFSSYKHVmmBScQygQILzAB&url=http%3A%2F%2Fwiki.micasaverde.com%2Findex.php%2FLuup_Scenes_Events%23Invoke_HTTP_URL_with_GET_request_.28Method_1.29&usg=AFQjCNFR25gsREzmB2n6T7DbugnYIJJd0A&sig2=r7BwqYiktmEDx1K9Lk4RBA
after I couldn't make anything else work. Your suggestion was actually the very first thing I tried. I can power cycle my vera lite (UI7), create a new scene, select no devices, and tell it to run this luup code:

local http = require "socket.http"
local result, status = http.request "http://192.168.1.20:8080/remote/processKey?key=poweron&hold=keyPress"

When I hit finish, vera spins around, the scene never shows up in the list, Luup eventually restarts, and I get an error message that says "Failed to save system configuration". I can create other basic scenes without issue and all my existing scenes run just fine. The luup code tester runs the code snippet above without issue, but the command produces no results. I can create scenes with other luup code without issue and they work properly, but I have not been successful at all in getting a scene to even save properly with any sort of http get command via luup, so I've been assuming there's been a syntax error the whole time creating a compile issue. There's something I'm missing.


Offline akbooer

  • Master Member
  • *******
  • Posts: 5277
  • Karma: +229/-67
  • "Less is more"
Re: Directv - HTTP GET commands via LUUP
« Reply #3 on: October 14, 2016, 11:50:39 am »
Try those examples from the Lua Test page and see if they work interactively.

If you're having problems with scene code, this sounds like a known Vera bug in Lua code handling for some firmware versions.  I'm not up to date on the details of this, because I never update my firmware, having got it to a stable state, but looking around on the forum should tell you more.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P.
Razberry, MySensors Arduino, HomeWave, AltUI, DataYours, openLuup, ZWay, ZeroBrane Studio.

Offline sdholden

  • Sr. Newbie
  • *
  • Posts: 31
  • Karma: +2/-1
Re: Directv - HTTP GET commands via LUUP
« Reply #4 on: October 14, 2016, 11:11:49 pm »
I upgraded to the latest firmware (1.7.855) and immediately resolved the issue. A couple of others are now present unfortunately, but there was definitely a luup code problem with my previous firmware.

Offline LindsiWains

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-40
Directv HTTP GET commands via LUUP
« Reply #5 on: November 12, 2016, 09:57:40 am »
Ive searched ALL over, and i cannot find a stickied FAQ, or any FAQ for that matter on how to get this to work. Can someone make a FAQ and sticky it up please?

thanx,
anthony

Offline myhomeserver

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 873
  • Karma: +3/-5
  • http://www.MyZwave.net
    • MyZwave.net
Re: Directv - HTTP GET commands via LUUP
« Reply #6 on: December 06, 2017, 12:28:34 pm »
Here's what I use to control my DirecTV from a vera scene

Add this in the luup code of a scene if you want to Press Play (Play a paused show)and your DirecTV box is on the IP of 192.168.1.200

  local status, result = luup.inet.wget("http://192.168.1.200:8080/remote/processKey?key=play&hold=keyPress", 2)


Add this in the luup code of a scene if you want to Skip (commercial skip 1X) and your DirecTV box is on the IP of 192.168.1.200

  local status, result = luup.inet.wget("http://192.168.1.200:8080/remote/processKey?key=advance&hold=keyPress", 2)


For more detail see my blog post at http://www.myzwave.net/index.php/controlling-your-directv-with-vera-zwave-and-other-home-automation-platforms/

MyZWave.net - See Our Z-Wave product Reviews
(formerly MyHomeServer)