An example of a script that you can write directly in the editor in the web interface. It runs once a second and, when the boiler temperature reaches 70 degrees, starts switching on and off the device connected to the first port of the PCF8575 expander, and also writes about it to the UART and to the browser console
if TankTemp > 70 then
if exp_digitalRead(1) == 0 then
exp_digitalWrite(1,1)
print("Включено")
else
exp_digitalWrite(1,0)
print("Выключено")
end
end
An example of a script that gets a value from an analog level sensor on the LUA_PIN input (34 for the DEVKIT board) and controls the water pump (for example, to pump wash into the boiler). If the signal is in the range from 1000 to 2000, it turns the pump on; at a zero signal it turns it off. The script is written right in the browser and is available for execution immediately after saving. Pin 4 is WATER_PUMP_PIN of the DEVKIT board; for other boards, substitute your own number.
start_pump = getObject("start_pump", "NUMERIC") + 0 --get the numeric value from a previously saved object and convert it to a number
sensor = analogRead() --read the analog value of LUA_PIN (reserved for Lua)
--sensor = 1500
if sensor >= 1000 and sensor <= 2000 and start_pump == 0 then
setObject("start_pump", 1) --save the value in an object in Samovar memory so that it can be used in the next script run cycle
digitalWrite(4,1) --set a high level on pin 4
print("Start pump") --[=[write to the COM port. You can also use the sendMsg("Msg", Level) command. If Level = -1, the message is output to the COM port and to the browser console, which is handy for debugging. If Level is 0, 1 or 2, the message is sent as a system message]=]
--sendMsg("Start pump",-1)
elseif sensor == 0 then
setObject("start_pump", 0) --save the value in an object in Samovar memory so that it can be used in the next script run cycle
if (start_pump == 1) then
digitalWrite(4,0) --set a low level on pin 4
print("Finish pump")
end
end
Ready-made scripts that are uploaded to Samovar together with the web interface:
rectificat.lua – filling the boiler with a pump by a level sensor or by a water flow sensor (the volume and sensor thresholds are set at the beginning of the file).
dist.lua – distillation split into three containers: it remembers the boiler temperature at the start of boiling and, when it rises by a given setpoint (or when the ABV drops), switches the servo to the next container, lowering the power if desired.
cheese.lua – a script template for the L line of a cheesemaking program.
btn_<mode>_button1.lua "Start" («Начать») and btn_<mode>_button2.lua "Stop" («Остановить») – turning the one-second cycle on and off for each mode.
More examples are in the Lua_script folder of the
Samovar repository on GitHub: fermentation temperature control (beer_mash.lua), water pump speed control with buttons, distillation with concentration (dist_degidrate.lua), sending readings to an external web service over HTTP (http_request_telegram.lua), holding pre-flooding by a pressure sensor, and scripts for the NBK.