Skip to content

Instantly share code, notes, and snippets.

@abobija
Created April 2, 2019 13:24
Show Gist options
  • Save abobija/232ed51096a51e0b0bd531fdf1cf4545 to your computer and use it in GitHub Desktop.
Save abobija/232ed51096a51e0b0bd531fdf1cf4545 to your computer and use it in GitHub Desktop.
Application written in YouTube video https://bit.ly/2HSPF7n
local BLUE_LED = 2
gpio.config({ gpio = BLUE_LED, dir = gpio.IN_OUT })
gpio.write(BLUE_LED, 0)
local api = nil
local function init_api32()
if api == nil then
api = require('api32')
.create({
auth = {
user = 'master',
pwd = 'api32secret'
}
})
.on_post('/led', function(jreq)
if jreq ~= nil and jreq.State ~= nil then
gpio.write(BLUE_LED, jreq.State)
end
return {
Device = 'Blue LED',
State = gpio.read(BLUE_LED)
}
end)
end
end
wifi.mode(wifi.STATION)
wifi.sta.config({
ssid = 'Renault 1.9D',
pwd = 'renault19',
auto = false
})
wifi.sta.on('got_ip', init_api32)
wifi.start()
wifi.sta.connect()
using NApi32;
using System;
using System.Threading;
namespace Api32ClientApp
{
class Program
{
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.Green;
var client = new Api32Client("http://192.168.0.102")
.Authorize("master", "api32secret");
var state = true;
while(true)
{
Console.WriteLine("LED goes {0}...",
state ? "ON" : "OFF");
var ledReq = new LedRequest { State = state ? 1 : 0 };
var ledRes = client.DoPost<LedResponse>("/led", ledReq);
Thread.Sleep(500); // 0.5 sec
state = !state; // Invert the state
}
}
}
// Class for Led Controll Request
public class LedRequest
{
public int State { get; set; }
}
// Class for Led Controll Response
public class LedResponse
{
public string Device { get; set; }
public int State { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment