1 General Script Demo
1.1 Address Operation:Write/Read data from address A to B
For example:transfer D2 to D0

Depend on diffferent format of data.V-Box use different script functions.
for example. addr_setshort(addr,num) Function: Write 16-bit signed decimal address
addr_getshort(addr) Function:Read 16-bit signed decimal address
addr_getword(string addr)Function: Read 16-bit unsigned decimal address
More script function are in the second section of “V-BOX Script Interface Manual”
1.2 Arithmetic

1.3 set 100 to D0--D19

1.4 short message
When the alarm condition is reached: temp1 > 5 & temp2 >10 & temp3 < 20(lasts more than 5 seconds) , then send an "alarm trigger" sms.
When the alarm condition is released,then send an "alarm release" sms.

Script is as below:
function sms.main()
------send condition------
local temp1 = addr_getword("@Temperature1")
local temp2 = addr_getword("@Temperature2")
local temp3 = addr_getword("@Temperature3")
local timer = addr_getword("@Timer")
local tag = addr_getbit("@Tag")
------lasting time------
if temp1 > 5 and temp2 > 10 and temp3 < 20 then
timer = timer + 1
addr_setword("@Timer",timer)
else
timer = 0
addr_setword("@Timer",timer)
end
------send sms & output Y0------
if timer > 5 then
if tag == 0 then
send_sms_ira("19859254700","alarm trigger")
addr_setbit("@Tag",1)
end
elseif tag == 1 then
send_sms_ira("19859254700","alarm release")
addr_setbit("@Tag",0)
end
end
2 V-Box connect with third part server
V-Box have two mode.One is for V-Net,User need to use WECON server to store data.We call this V-NET platform.
1.Europe server:eu.v-box.net
2.Asean server:asean.v-box.net
Second is for OpenCloud mode.It means V-Box data will transfer to third part server and do not want to store data to WECON server.We call OpenCloud paltform
OpenCloud platform is used in configuring the script.Then V-Box can connect with third part server.
Both mode can support script to connect with third part server.the difference:
1.If you want to store in WECON server ,please use V-NET.
2.If your server requires SSL certificate to log in,please use OpenCloud.Because only OpenCloud platform can support to upload certificate
2.1 V-Box connect with customer server:grouprobotinfo.com
This demo does not use SSL certification. Script is as below
Demo1:
-- Meta class
--main
function mq.main()
if not mq.m then
local err = ""
mq.m, err = mqtt.create("tcp://grouprobotinfo.com:1883", "ClienID") -- create connection
if mq.m then
mq.config = {
username = "",-- ID
password = "",-- password
netway = 1, -- Ethernet connection, WIFI=1
-- keepalive = 100, -- Optional, set the connection heartbeat interval for 100 seconds.
-- cleansession = 0, -- Optional, keep session
}
mq.m:on("message", function(topic, msg) -- Register for receiving message callbacks
local str = string.format("%s:%s", topic, msg)
-- print("mqtt msg:", str) -- Print out the received topics and content
end
)
mq.m:on("offline", function (cause) -- Register for lost connection callbacks
-- addr_setstring("@xxx", "cause"..(cause or " got nil"))
end)
mq.m:on("arrived", function() -- Registration for sending messages to callbacks
print("msg arrived")
end)
else
print("mqtt create failed:", err) -- Create object failed
end
else
if mq.m:isconnected() then -- If online, post a message
local phaseStatus ="unknow"
if addr_getbit("@Standby")== 1 then
phaseStatus = "Standby"
elseif addr_getbit("@Pre-Freeze")==1 then
phaseStatus= "Pre-Freeze"
elseif addr_getbit("@Prepare")==1 then
phaseStatus ="Prepare"
elseif addr_getbit("@Primary Dry")==1 then
phaseStatus = "Primary dry"
elseif addr_getbit("@Secondary Dry")==1 then
phaseStatus = "Secondary Dry"
end
-- print(addr_getbit("@Primary Dry"))
-------------------------------------------------------------------------------------------------------------------------
local activating ="unknow"
if addr_getbit("@Compressor")==1 then
activating = ",".."Compressor"
end
if addr_getbit("@Silicone Pump")==1 then
activating = activating..",".."Silicone Pump"
end
if addr_getbit("@Vacuum Pump")==1 then
activating = activating..",".."Vacuum Pump"
end
if addr_getbit("@Root Pump")==1 then
activating = activating..",".."Root Pump"
end
if addr_getbit("@Heater")==1 then
activating = activating..",".."Heater"
end
if addr_getbit("@Valve Silicone")==1 then
activating = activating..",".."Valve Silicone"
end
if addr_getbit("@Valve Ice Condenser")==1 then
activating = activating..",".."Valve Ice Condenser"
end
if addr_getbit("@Valve Vacuum Pump")==1 then
activating = activating..",".."Valve Vacuum Pump"
end
local pr_activating =string.sub(activating,2)
-- print(pr_activating)
local status_text ="unknow"
if addr_getbit("@Status Run")==1 then
status_text = "RUNNING"
else
status_text = "STOP"
end
-------------------------------------------------------------------------------------------------------------------------
local js = {type="status",
mc_name ="FD300",
status=status_text,
elapsed_time={
hour=addr_getword("@Elapsed Time (Hour)"),
min=addr_getword("@Elapsed Time (Minute)"),
sec=addr_getword("@Elapsed Time (Second)")
},
phase = phaseStatus,
step = addr_getword("@Step"),
activating_output = pr_activating,
sv=addr_getshort("@SV Silicone")/10,
pv=addr_getshort("@PV Silicone")/10,
product1=addr_getshort("@Product 1")/10,
product2=addr_getshort("@Product 2")/10,
product3=addr_getshort("@Product 3")/10,
product4=addr_getshort("@Product 4")/10,
ice1=addr_getshort("@Ice condenser 1")/10,
ice2=addr_getshort("@Ice condenser 2")/10,
vacuum=addr_getfloat("@Vacuum")
}
local jsAlarm = { HPC = addr_getbit("@B_25395#W0.00"),
ODPC = addr_getbit("@B_25395#W0.01"),
MTPC=addr_getbit("@B_25395#W0.02"),
HTT = addr_getbit("@B_25395#W1.03"),
CPC = addr_getbit("@B_25395#W0.08"),
CPSP =addr_getbit("@B_25395#W1.00"),
CPVP =addr_getbit("@B_25395#W0.10"),
CPRP =addr_getbit("@B_25395#W0.11"),
HP =addr_getbit("@B_25395#W1.01"),
PP= addr_getbit("@B_25395#W1.02"),
PO=addr_getbit("@B_25395#W0.07"),
FSE=addr_getbit("@B_25395#W2.04"),
AVVSVV=addr_getbit("@B_25395#W1.12"),
ICHT=addr_getbit("@B_25395#W3.06")
}
-- ("@B_25395#CIO1.02")
mq.m:publish("mqtt-v-box-epsilon-fd300", json.encode(js) , 0, 0)
mq.m:publish("mqtt-v-box-epsilon-alarm-fd300", json.encode(jsAlarm) , 0, 0)
else
local stat, err = mq.m:connect(mq.config) -- connection
if stat == nil then --Determine whether to connect
print("mqtt connect failed:", err)
return -- Connection failed, return directly
end
mq.m:subscribe("mqtt-v-box-epsilon", 0)-- Subscribe to topics
end
-- mq.m:unsubscribe("stc/test")
-- mq.m:disconnect() -- close matt
-- mq.m:close() -- close clase
end
end
In this demo,V-Box connects with Azure by SSL certification.
Video link: https://youtu.be/cdI6rIQcpMY?list=PL_Bpnb2RgaksCic9HCcVAZhU9sYwCRKzW
Tool Download link: https://wecon-disk.oss-ap-southeast-1.aliyuncs.com/Download/WIKI/V-BOX/Demo/Azure/Azure%20tool.zip
Script is as below
--https://support.huaweicloud.com/qs-IoT/iot_05_0005.html mqtt.fx monitor to connect azure iot
sprint = print
--Get custom configuration parameters (vbox custom information)
--local CUSTOM = bns_get_config("bind")
--local DS_ID = CUSTOM.DSID or "60a71ccbbbe12002c08f3a1a_WECON"
--Cloud mode interface to obtain the MQTT information configured by the cloud platform: (5 returns, namely the server address, client ID, connection table, last word table, certificate table)
local MQTT_URL, MQTT_CLIENTID, MQTT_CFG, MQTT_LWT, MQTT_CART = mqtt.setup_cfg()
--MQTT_CFG.username = '60a71ccbbbe12002c08f3a1a_WECON'
--MQTT_CFG.password='wecon123'
--MQTT_CLIENTID = '60a71ccbbbe12002c08f3a1a_WECON_0_0_2021052110usernxame:60a71ccbbbe12002c08f3a1a_WECONpassword:a0a951581855aa8e0262129da6cf1b43f2c0ecfac4fa56117fc5a20c90be169a'
--publish to topics
local pub_RE_TOPIC = string.format('devices/wecon_02/messages/events/')
--Subscribe topics
local Subscribe_RE_TOPIC1 = string.format('devices/wecon_02/messages/devicebound/#')
--variable
local last_time = 0
--Timing main function
function Azure.main()
sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " Azureiot.main start")
if g_mq then
if g_mq:isconnected() then
send_Data()
else
if os.time() - last_time > 20 then
last_time = os.time()
mymqtt_connect()
end
end
else
mymqtt_init()
end
sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " Azureiot.main end")
end
-- Initialize MQTT
function mymqtt_init()
sprint(string.format("mqtt init mqtt_url:%s mqtt_clientid:%s", MQTT_URL, MQTT_CLIENTID))
g_mq, err = mqtt.create(MQTT_URL, MQTT_CLIENTID) -- Create the object and declare it as a global variable
if g_mq then
g_mq:on("message", mymqtt_msg_callback) -- Register to receive message callbacks
sprint("mqtt init success")
else
sprint("mqtt init failed:", err)
end
end
-- Connect to MQTT server
function mymqtt_connect()
sprint("mqtt connecting...")
local stat, err = g_mq:connect(MQTT_CFG,MQTT_LWT, MQTT_CART)
if stat == nil then
sprint("mqtt connect failed:", err)
return
else
sprint("mqtt connected")
end
g_mq:subscribe(Subscribe_RE_TOPIC1, 0)
end
-- Receive MQTT message callback function
function mymqtt_msg_callback(topic, msg)
print("topic:",topic)
print("revdata:",msg)
-- local revData = json.decode(msg)
-- if topic == Subscribe_RE_TOPIC1 then --Process topic information subscribed from the cloud
-- if string.match(topic,Subscribe_RE_TOPIC1) then
-- print("topi11:",topic)
setValue(revData)
-- end
end
--Process the received data
--function setValue(revData)
-- if revData ~=nil then
-- for i,v in pairs(revData) do
-- print("Data received:",i,v)
-- end
-- end
--end
--Get real-time data
function getData()
local jdata = {}
local addr = bns_get_alldata()
print(json.encode(addr))
for i,v in pairs(addr) do
if v[2] == 1 then
jdata[v[3]] = v[4]
end
end
return jdata
end
--send data
function send_Data()
local pub_data = {100
-- services={{
--serviceId ='Temperature',
-- properties={
-- value = 55
-- },
-- }}
}
sprint(json.encode(pub_data))
print("..........",pub_RE_TOPIC)
return g_mq:publish(pub_RE_TOPIC, json.encode(pub_data), 0, 0)
end
1.Register a account: https://www.huaweicloud.com/intl/en-us/s/JUlPVERNJQ
2.log in the Huawei IOTDA
https://console.huaweicloud.com/iotdm/?region=cn-north-4&locale=en-us#/dm-portal/home
3.Create product

4.Product name,manufacturer,device type and industry,set according to your own needs.
Protocol: MQTT
Data Type: JSON
After finishing configuration,please click "OK"

5.Device
After product register,continue to configure "individual register".Click "Device"-->"individual register"

Notes for registering device:
Product: Previous product registration.
Node ID, Device Name: set according to your own needs.
Secret: need to be configured, will be used when connecting later
After configuration, click OK to generate a device ID and password, which will be used for device access later.


6. Connection authentication (use MQTT.fx tool to access the IoT platform)
(1)Open mqttClientIdGenerator tool Java(TM) Platform SE binary
Download

(2)Fill in the device ID and secret (deviceid and secret generated when registering the device) to generate connection message
Client ID, user name, password

(3) Download certificate file"North-Beijing4"
https://support.huaweicloud.com/en-us/devg-iothub/iot_02_1004.html


7.Run MQTTfx tool to connect with Huawei
Download link: http://mqttfx.jensd.de/index.php/download
(1)Click on the setting ICON

(2)Fill in IIOT MQTT device access address, and configure authentication parameters.
First: It is the server and port connected to Huawei IOT, which can be viewed through the overview of the interface.

Domain name:iot-mqtts.cn-north-4.myhuaweicloud.com
Port: 8883
Client ID: check step 6

(3)Upload SSL certificate file,check step 6
Select folder java-->DigiCertGlobalRootCA.crt.pem and click OK or apply button

(4)Connect and test publish and subscribe


Huawei publish topic format: $oc/devices/{device_id}/sys/properties/report

Huawei subscribe topic format: $oc/devices/{device_id}/sys/commands/#


(5).How to configure to view the received data format intuitively, multiple products (Huawei) are required to configure the model. The specific steps are as follows:
①Select the corresponding product from Huawei products to view

②Custom model: used to display the service ID name of the configuration report.


③Add property, ID of monitoring point, and data format:

④After the configuration is complete, check the received data on the device

In this demo,V-Box connects with Huawei by SSL certification.
1.Create a project access for Huawei IOT
2.configure MQTT configuration

3.Create a script with the demo as below.
Script is as below
-- mqtt.fx simulated access to Huawei Cloud IoT platform refer to 2.4
sprint = print
--Get custom configuration parameters (gateway customization information)
local CUSTOM = bns_get_config("bind")
local DS_ID = CUSTOM.DSID or "5dfa0700df1ae506179afb9c_wecon"
--OpenCloud mode interface, obtain MQTT information configured on cloud platform: (5 returned, respectively server address, client ID, connection table, last word table, certificate table)
local MQTT_URL, MQTT_CLIENTID, MQTT_CFG, MQTT_LWT, MQTT_CART = mqtt.setup_cfg()
MQTT_CFG.username =DS_ID
MQTT_CFG.password='d030d92338fcc18cd10fabb3003a4a0f6620fa6822cd3c23b1d9bc790200c6e7'
MQTT_CLIENTID = '5dfa0700df1ae506179afb9c_wecon_0_0_2019121819'
--publish topic format:$oc/devices/{device id}/sys/properties/report
local pub_RE_TOPIC = string.format('$oc/devices/60a71ccbbbe12002c08f3a1a_WECON/sys/properties/report')
--variate
local last_time = 0
--Timing principal function
function hwyiot.main()
sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " hwyiot.main start")
if g_mq then
if g_mq:isconnected() then
send_Data()
else
if os.time() - last_time > 20 then
last_time = os.time()
mymqtt_connect()
end
end
else
mymqtt_init()
end
sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " hwyiot.main end")
end
-- initializationMQTT
function mymqtt_init()
sprint(string.format("mqtt init mqtt_url:%s mqtt_clientid:%s", MQTT_URL, MQTT_CLIENTID))
g_mq, err = mqtt.create(MQTT_URL, MQTT_CLIENTID) -- Create the object and declare it as a global variable
if g_mq then
g_mq:on("message", mymqtt_msg_callback) -- Register to receive message callbacks
sprint("mqtt init success")
else
sprint("mqtt init failed:", err)
end
end
-- Connect to the MQTT server
function mymqtt_connect()
sprint("mqtt connecting...")
local stat, err = g_mq:connect(MQTT_CFG,MQTT_LWT, MQTT_CART)
if stat == nil then
sprint("mqtt connect failed:", err)
return
else
sprint("mqtt connected")
end
--subscribe topic format:$oc/devices/{device_id}/sys/commands/#
g_mq:subscribe('$oc/devices/60a71ccbbbe12002c08f3a1a_WECON/sys/commands/#', 0)
end
-- Receive the message callback function
function mymqtt_msg_callback(topic, msg)
sprint("recv data!")
sprint("topic:msg", topic,msg)
print(msg)
local revData = json.decode(msg)
end
--Send data
function send_Data()
local pub_data = {
msgType = 'deviceReq',
data = {{
serviceId ='Battery',
serviceData={
batteryLevel = 55
}
}}
}
return g_mq:publish(pub_RE_TOPIC, json.encode(pub_data), 0, 0)
end
4.Download project access into V-Box to test in debug page


https://ftp.we-con.com.cn/Download/WIKI/V-BOX/Demo/AWS/AWS.zip