Tags: 
Lua tutorials

This NETIO AN01 Application Note describes the first steps to simple programming of NETIO 4x (4 / 4All / 4C) smart socket devices with Lua scripts. In this tutorial, two sockets are switched on/off alternately. 

Do you have any questions?

 

Supported devices:  NETIO 4AllNETIO PowerPDU 4CNETIO 4

 

Connecting NETIO power socket to LAN

  • Connect NETIO smart sockets to your LAN with a network (Ethernet) cable.
  • From the NETIO products website (https://www.netio-products.com/en/download), download and install the NETIO Discover software for discovering your device in the network.
  • Start NETIO Discover, click Find devices and wait until your device is found as in the picture.

Start NETIO Discover, click Find devices and wait until your device is found as in the picture.

 

  • Click the IP address (192.168.0.26 in this example) and open the web interface of the device.
     

Note:
If there is no DHCP server in your LAN, follow the procedure in the QIG (Quick Installation Guide). 

  •  Click the IP address (192.168.0.26 in this example) and open the web interface of the device.

 

Default login and password: admin / admin.

 

Switching a programmable socket NETIO on/off in the web interface

After logging in to the web interface, click the Outputs tab (see the picture).
Socket No. 1 (output_1) can be turned off or on by clicking the icon highlighted in red. 

  • The socket can be controlled in parallel using the NETIO Mobile App
  • All sockets can be controlled with buttons 1 to 4 at the NETIO device. To switch an output on or off, hold the button for at least 2 seconds.
  • After logging in to the web interface, click the Outputs tab. Socket No. 1 (output_1) can be turned off or on by clicking the icon highlighted in red.

 

  • The sockets can be controlled in parallel using any of the enabled M2M API protocols
  • The sockets can be also controlled by Lua scripts that run in parallel. 

 

The Log shows which method has caused the given socket to turn on/off. 

 

Changing the default password to networked power socket NETIO

  • For security reasons, we recommend to change the default admin password. The username must be “admin” but the password can be changed. 
  • Change the password in the Users section of the web interface. Click Save Changes to confirm.

For security reasons, we recommend to change the default admin password

 

Creating a Lua script - first steps with Lua      

Custom scripts are entered in the web interface of NETIO power sockets


Lua is a simple programming language. Custom Lua scripts can run directly in the NETIO 4x (4 / 4All / 4C) smart sockets device. Custom scripts are entered in the web interface. Various ready-made scripts are available as AN (Application Notes) at the NETIO products website. 

 

For a list of functions, see our Wiki: https://wiki.netio-products.com/

 

Simple flasher in Lua programming language

  • In the Actions section, a Lua code can be pasted (or typed) into the corresponding window.
  • Give the script a name (Flasher) and a description (Switching outlets 1 and 2)
  • Choose a Trigger – an event that starts the script. For this example, select System started up. This Lua script is started after the device is powered up (approximately 40 seconds after applying power).
  • Leave Schedule to Always. If using another schedule, script would be triggered only when schedule is active.
  • Copy and paste the following code:

 


------------Section 1------------
local output1 = 1 -- select output1 number (1 - 4)
local output2 = 2 -- select output2 number (1 - 4)
local interval = 10 -- select the interval between switching (seconds)
---------End of Section 1---------

local state = 0
local function switch()
  state = not state
  devices.system.SetOut{output=output1, value=state}
  devices.system.SetOut{output=output2, value=not state}
  delay(interval,switch)
end
switch()


  • Make sure that Enabled is checked.
  • Click Create Rule to create the script.

 Click Create Rule to create the script.

 

  • A green “OK” mark should appear next to the script name and the script should be added to the list at the left-hand side.

 A green “OK” mark should appear next to the script name and the script should be added to the list at the left-hand side.

 

  • In the script header, you can configure which sockets (Power Outputs) out of the four should flash alternately. 
  • You can also set the time delay. 
  • After restarting the NETIO device, the script starts running and periodically switches the chosen sockets on and off alternately. To stop a running script, uncheck Enabled, save changes and restart the NETIO device.

 

Setting the variables used in power sockets NETIO

  • The code contains 3 variables that can be used to change the sockets and the time delay.
  • The variables can be changed in the code header (Section 1).
  • output1
    • Sets first socket to flash
    • For example, to set the socket No. 2: output1=2
  • output2
    • Sets the other socket to flash
    • For example, to set the socket No. 4: output2=4
  • interval
    • Sets the time delay between changing the state (in seconds).
    • For example, to switch every 5 seconds: interval=5
  • If we wanted to switch sockets 1 and 4 every 10 seconds, the variables would be set as follows:

 If we wanted to switch sockets 1 and 4 every 10 seconds, the variables would be set as follows:

 


Supported FW versions:

3.0.0 and later (Firmware archive)

More about Lua:

https://wiki.netio-products.com


 

 

This Application Note is compatible with:

Smart power socket NETIO

 

NETIO 4

NETIO 4 is smart power socket (smart power strip) with four 230V/8A sockets, connected to LAN and WiFi. Each of the four power sockets can be individually switched on/off using various M2M API protocols. NETIO 4 is a unique product designed for IT, industry, smart homes, multimedia installations and other applications. Use the product whenever you need 230V sockets controlled by a mobile app, by a computer program (via M2M API) or by a custom script (Lua), and featuring a timer (Scheduler) or auto reboot functionality (IP WatchDog). 

More about NETIO 4

 

Smart power socket NETIO 4All

 

NETIO 4All

NETIO 4All is a PDU module featuring four 230V/8A power sockets with consumption metering for each socket as well as LAN and WiFi connectivity. Each of the four sockets can be individually switched on/off over the Web or using various M2M API protocols. Electricity consumption (A, W, kWh) can be measured at each power socket. NETIO 4All smart sockets are designed for remote measurement and control of electrical sockets. Use the product whenever you need 230V sockets controlled by a mobile app, by a computer program (via M2M API) or by a custom script (Lua) that runs directly in the NETIO 4All smart socket device.

More about NETIO 4All

 
NETIO PowerPDU 4C is small PDU with power measurement and IEC-320 outputs

 

NETIO PowerPDU 4C

NETIO PowerPDU 4C is a small 110/230V PDU (Power Distribution Unit). Each of the four IEC-320 C13 outlets can be independently controlled (On / Off / Reset / Toggle). Electrical parameters (A, W, kWh, TPF, V, Hz) are measured with high accuracy at each outlet. The device features two LAN ports (and a built-in Ethernet switch) for connecting to a LAN. Each power output supports ZCS (Zero Current Switching) to protect the connected equipment.

More about NETIO PowerPDU 4C

 

FAQ

Expand all

When I want to save a script I get a red error message: “Action code is invalid. Please find the errors, fix them, and save the changes.” What should I do?

Most likely there was a mistake when copying and pasting the code. Try to copy and paste the code again, and check that everything is set according to the instructions.

What happens if I change the state of a socket with a button or the mobile app while a script is running?

The script continues to run and sets the socket to the appropriate state during the next iteration.

How can I stop a running script?

Disable the activation of the script upon device power-up (uncheck Enabled in the script configuration) and save the changes. The script continues to run; however, when you restart the NETIO device now, the script does not start again.

How can I change the switching (blinking) interval?

Use the interval variable. See “Setting the variables”.

The “admin” account cannot be renamed or deleted.

The “admin” account is a default built-in account that cannot be renamed. However, it is possible (and we recommend) to change its password.

Ask for a price or technical parameters

For device testing use name/password demo/demo