Blynk on Udoo Neo running!

Reading this I found out that the backlash had to be escaped in order to be considered as a literal string because otherwise the parser treat it like a special character.

So now the script runs but I’m still not recieving any value on the app…

Are you confirming that data is even getting pulled back into the script, with CLI prints?

No, but I can confirm that the app works and is recieving the “os.time” on pin V2

EDIT:

I confirm, data is getting pulled back into the script with CLI prints!

For today I had enough, time to head to bed, at least one little step forward was made :confused:

EUREKA!

	#!/usr/bin/env lua

--[[
  This is the default example for Linux, Windows, OpenWrt
]]

local socket = require("socket")
local use_ssl, ssl = pcall(require, "ssl")

local Blynk = require("blynk.socket")
local Timer = require("timer")

assert(#arg >= 1, "Please specify Auth Token")
local auth = arg[1]

local blynk = Blynk.new(auth, {
  heartbeat = 10, -- default h-beat is 30
  --log = print,
})

local function connectBlynk()
  local host = "blynk-cloud.com"

  local sock = assert(socket.tcp())
  sock:setoption("tcp-nodelay", true)

  if use_ssl then
	print("Connecting Blynk (secure)...")
	sock:connect(host, 443)
	local opts = {
	  mode = "client",
	  protocol = "tlsv1"
	}
	sock = assert(ssl.wrap(sock, opts))
	sock:dohandshake()
  else
	print("Connecting Blynk...")
	sock:connect(host, 80)
  end

  -- tell Blynk to use this socket
  blynk:connect(sock)
end

function exec_out(cmd)
  local file = io.popen(cmd)
  if not file then return nil end
  local output = file:read('*all')
  file:close()
  -- print("Run: "..cmd.." -> "..output)
  return output
end

function read_file(path)
  local file = io.open(path, "rb")
  if not file then return nil end
  local content = file:read "*a"
  file:close()
  -- print("Read: "..path.." -> "..content)
  return content
end

function getArpClients()
  return tonumber(exec_out('cat /sys/bus/iio/devices/iio\\:device0/in_voltage0_raw'))
end

function getUptime()
  return tonumber(exec_out("cat /proc/uptime | awk '{print $1}'"))
end

-- callback to run when V1 changes
blynk:on("V1", function(param)
  print("V1:", tonumber(param[1]), tonumber(param[2]))
end)

-- callback to run when cloud requests V2 value
blynk:on("readV2", function(param)
  blynk:virtualWrite(2, os.time())
end)

-- create a timer to update widget property
local tmr1 = Timer:new{interval = 5000, func = function()
 blynk:virtualWrite(10, getArpClients())
 blynk:virtualWrite(11, string.format("%.1f h", getUptime()/60/60))
end}

connectBlynk()

while true do
  blynk:run()
  tmr1:run()
end

No more unsupported board!

1 Like

me too :joy:
and I ask myself why to use Lua :fearful:

Well, I am glad you understand whatever solved your issue :blush: If you can, would you mind explaining a little bit about what the solution was? Thanks.

1 Like

Yes, basically as I stated in previuos post

but then, as you can see by my CLI screenshot it wasn’t enough because it seemed that the command was passed correctly but not executed, so that took me a few head bangs and most of the day to figure out why, since copying and pasting manually from the output of the lua script returned the value properly, while executing it didn’t .

In few words reading this carefully and again and again brought me to the not so explicit way of passing the command even without escaping the special char (backlash).
Best solution is to enclose the string inside double square brackets so the parser treats it as non lua code (still can be code for other language, html page for example).

Now I only have to map the voltage that I’m receiving to the sensor depth range and ad few other math calculations before deploying everything in place.

Thanks for now.

Lawrence

1 Like

DONE!

2 Likes