The Flexs Q4 is an open device with support for a wide array of protocols allowing easy and flexible interfacing with almost any platform or environment.
Each method is outlined below in detail.
The HTTP API allows for reading input values, setting relay output states and modifying all configuration settings such as analog input gain, logic rules, etc.
READ ANALOG INPUT CH1 (REGISTER 1) Value
READANALOG INPUT CH8 (REGISTER 8) Value
READ RELAY #2 (Register 10) Output Status
SET LOAD SWICH #2 (Register 10) to 1 (ON)
SET LOAD SWICH #2 (Register 10) to 0 (OFF)
The Flexs Q4 uses ‘BASIC AUTH’ authentication, if you are using a password on your device these headers must be added to your request, if you are making the requests in your web browser it should automatically prompt for a username and password
SNMP V1 is supported only for reading analog input values and relay output states. SNMP is compatible with a wide array of opensource monitoring, data logging and visualization software including Cacti, Zabbix and more!
The SNMP community is modified on the ‘Configuration’ tab and optionally can be set blank to disable the snmp service.
To get the voltage on input channel 2 (register #2) the following command can be used.
snmpget -v1 -c “public” 22.214.171.124 126.96.36.199.4.1.4128.2
iso.188.8.131.52.1.4128.1 = STRING: “12.9867”
To get the status of relay output 1 (register #9) the following command can be used.
snmpget -v1 -c “public” 184.108.40.206 220.127.116.11.4.1.4128.9
iso.18.104.22.168.1.4128.9 = STRING: “1”
Data can be streamed via UDP from the Flexs Q4 device when enabled on the ‘Configuration’ tab, a valid endpoint URL is required which can include an IP Address or hostname.
Data is streamed to the specified endpoint in a packed struct of the following composition. Standard Little Indian, 32Bit IEE754 Float
uint64_t uid; // 64bit unsigned integer, uuid of device
char hash;// SHA256 hash of data + password + uid
float data; //register data
If you are using a language other than ‘C’ or ‘C++’ the bytes come in with the following structure:
Bytes 0-7: Unsigned 64 bit integer containing Device UUID
Bytes 8-31: Byte array containing SHA256 hash of data + password + uuid
Bytes 32-35: 32bit single precision float representation of Register 0’s Value
Bytes 36-39: 32bit single precision float representation of Register 1 (Analog Input Ch 1) ‘s value
… +126 More Registers
The Flexs Q4 also listens for UDP datagrams on port 8001 which can be used to send commands to the Flexs Q4 for relay control.
Since outgoing udp stream packets originate from port 8001, a listening server can reply with a command after receiving a stream data packet, thus removing the need for port forwarding on the end device.
The format for a UDP Set Register Command Packet is detailed below
unsigned char hash; // First write the device password to this array, then compute a sha256 bit hash of this entire structure and place the result inside this array
uint32_t reg; // register we are setting
float value; // Value to set register to
uint32_t timestamp; // 32Bit Unix Epoch Timestamp
When the Flexs Q4 receives a set register command it will create a checksum based on the same algorithm and compare against the received checksum, this prohibits unsecured access and insures that the values present in the array were not manipulated, the timestamp is also compared with the flexs Q4’s time and must be within 100 seconds or the command will be ignored.
An example C++ listener / control service is available free of charge upon request.
Analog Input values, relay output states and other data can be sent to a server as a post request, this method allows you to easily process the data with PHP, .NET, CGI Scripting or other server side scripting languages.
Requests are made to the streaming endpoint url specified on the configuration page, an IPv4 address or hostname can be used.
Data is sent in the JSON format with a unique device identifier and an array containing the values of each of the registers.
EXAMPLE POST DATA:
Example PHP Listener script which logs the value of analog input channel 1 (register 1) to a text file on the server named log.txt, logging to MYSQL or other database types could easily be accomplished from this point
$json = json_decode ( file_get_contents(“php://input”));
$fh = fopen(“log.txt”, ‘a’) or die(“can’t open file”);
fwrite($fh, $json->registers . “\n”);