From 0808d5db69e5b04e72c48ba654f51c6d59c593e3 Mon Sep 17 00:00:00 2001 From: Bart Van Der Meerssche Date: Wed, 27 Apr 2011 21:08:01 +0200 Subject: [PATCH] [httpclient] turn globe led on after each successful REST call (200 and 204 status) --- mote/v2/openwrt/files/etc/rc.local | 4 ++++ .../luci/libs/httpclient/luasrc/httpclient.lua | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/mote/v2/openwrt/files/etc/rc.local b/mote/v2/openwrt/files/etc/rc.local index 584da98..3630e0c 100644 --- a/mote/v2/openwrt/files/etc/rc.local +++ b/mote/v2/openwrt/files/etc/rc.local @@ -1,6 +1,10 @@ # Put your custom commands here that should be executed once # the system init finished. By default this file does nothing. +# set the globe led pin (=GPIO 5) direction to output +gpioctl dirout 5 +# turn the globe led pin off (inverted logic) +gpioctl set 5 # set the wifi led pin (=GPIO 7) direction to output gpioctl dirout 7 diff --git a/mote/v2/openwrt/package/luci/libs/httpclient/luasrc/httpclient.lua b/mote/v2/openwrt/package/luci/libs/httpclient/luasrc/httpclient.lua index 163978e..e369791 100644 --- a/mote/v2/openwrt/package/luci/libs/httpclient/luasrc/httpclient.lua +++ b/mote/v2/openwrt/package/luci/libs/httpclient/luasrc/httpclient.lua @@ -20,6 +20,7 @@ local util = require "luci.util" local table = require "table" local coroutine = require "coroutine" local string = require "string" +local os = require "os" local http = require "luci.http.protocol" local date = require "luci.http.protocol.date" @@ -106,19 +107,35 @@ end function create_persistent() return coroutine.wrap(function(uri, options) + local function globe_on() + os.execute("gpioctl clear 5 > /dev/null") + end + + local function globe_off() + os.execute("gpioctl set 5 > /dev/null") + end + local status, response, buffer, sock while true do local output = {} + + globe_off() status, response, buffer, sock = request_raw(uri, options, sock) if not status then uri, options = coroutine.yield(nil, response, buffer) elseif status ~= 200 and status ~= 206 then + if status == 204 then + globe_on() + end + uri, options = coroutine.yield(nil, status, response) else + globe_on() + local content_length = tonumber(response.headers["Content-Length"]) local bytes_read = 0