2 Script

Version 12.2 by Leo Wei on 2022/07/09 17:41

1 General Script Demo

1.1 Address Operation:Write/Read data from address A to B

For example:transfer D2 to D0

1624245865976-320.png

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

1624249623612-177.png

1.3 Set 100 to D0--D19

1624249693457-742.png

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.

1645535936750-316.png

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

1.5 Telegram notification

This example shows how to use the Bot API to send message into Telegram group or channel. When monitoring bit "@HDX" changes, it will trigger and send the message. Please replace with your own Token and chat id.

local tempBit = 0
local tempWord = 0

local botToken = "5504549693:AAEy6a5G-sOF3CINONxMNABeYnoS4ABVlfg"
local chatID = "-641959124"--The chat id from Channel or Group

local https = require("https")
local json = require("json")

-- Send http.get request and return response result
function getHttpsUrl(url)
   local body = {}
   local bodyJson = json.encode(body)
   local header = {}
    header["content-type"] = "application/json"
local result_table, code, headers, status = https.request(url, bodyJson)
print("code:"..code)
if code~= 200 then
 return
else
 return body
end
end

function sendAlarm(telegramBotToken, message, telegramChatID)
   local url = "https://api.telegram.org/bot"..telegramBotToken.."/sendMessage?text="..message.."&chat_id="..telegramChatID
   --local url = 'http://v-box.net'
   --local url = 'https://www.google.com/'
   print("Get the link:"..url)
    getHttpsUrl(url)
end


function AlarmNotificate.main()
   local bitValue = addr_getbit("@HDX");
   local message = ''
   print("b=="..bitValue)
   if bitValue == 1 and bitValue ~= tempBit then
        message = 'Alarm triggered, the monitoring point test value is '.. bitValue
        sendAlarm(botToken, message, chatID)
       print("Notification pushed of triggering alarm,"..bitValue)
   elseif bitValue == 0 and bitValue ~= tempBit then
        message = 'Alarm dismissed, the monitoring point test value is '.. bitValue
        sendAlarm(botToken, message, chatID)
       print("Notification pushed of dismissing alarm,"..bitValue)
   end
    tempBit = bitValue----Prevent monitoring values from continuous being sent to the platform
   
   local wordValue = addr_getword("@HDW10")
   print("w=="..wordValue)
   --dosomething
   if wordValue >= 100 and wordValue ~= tempWord and tempWord <= 100 then
        message = 'Word alarm triggered, the word value is '.. wordValue
        sendAlarm(botToken, message, chatID)
       print("Notification pushed of triggering alarm,"..wordValue)
   elseif wordValue < 100 and wordValue ~= tempWord and tempWord >= 100 then
        message = 'Word alarm dismissed, the word value is '.. wordValue
        sendAlarm(botToken, message, chatID)
       print("Notification pushed of dismissing alarm,"..wordValue)
   end
    tempWord = wordValue----Prevent monitoring values from continuous being sent to the platform
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

2.2 V-Box connect with Azure platform

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

 

2.3 How to configure the Huawei platform?(✎Note: Huawei IOT DA function is only in China area.If you want this function,you need to use chinese mobile to register)

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

1624433478954-859.png

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"

1624433531968-337.png

5.Device

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

1624434757597-117.png

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.

1624436421499-613.png

1624437798012-126.png

6. Connection authentication (use MQTT.fx tool to access the IoT platform)

(1)Open mqttClientIdGenerator tool Java(TM) Platform SE binary

Download

1624437573798-815.png

(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

1624437756866-251.png

(3) Download certificate file"North-Beijing4"

https://support.huaweicloud.com/en-us/devg-iothub/iot_02_1004.html

1624438225398-363.png

1624438260025-610.png

7.Run MQTTfx tool to connect with Huawei

Download link: http://mqttfx.jensd.de/index.php/download

(1)Click on the setting ICON

1624438821280-974.png

(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.

1624439086268-985.png

Domain name:iot-mqtts.cn-north-4.myhuaweicloud.com

Port: 8883

Client ID: check step 6

1624439672168-492.png

(3)Upload SSL certificate file,check step 6

Select folder java-->DigiCertGlobalRootCA.crt.pem and click OK or apply button

1624439912938-659.png

(4)Connect and test publish and subscribe

1624440014872-688.png

1624440026937-386.png

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

1624440404119-815.png

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

1624447157493-672.png

1624447209982-715.png

(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

1624440647663-632.png

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

1624440793982-974.png

1624440883015-105.png

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

1624441052296-108.png

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

1624441186851-536.png

2.4 V-Box connect with Huawei platform

In this demo,V-Box connects with Huawei by SSL certification.

1.Create a project access for Huawei IOT

2.configure MQTT configuration

1624506363847-661.png

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 

1624506710354-406.png

1624506666650-161.png

2.5 V-Box connect with AWS platform

Log in AWS

Login aws account and click“Connect an IoT device”

image-20220709165402-1.png

image-20220709165402-2.png

Create policy

Click “Secure”--->“Policies”--->“Create policy”--->Click “Create”

image-20220709165402-3.png

Name the policy--->Click “JSON”--->Copy the following content--->Click “Create”

image-20220709165402-5.png

image-20220709165402-4.png

{

  "Version": "2012-10-17",

  "Statement": [

    {

      "Effect": "Allow",

      "Action": [

        "iot:Connect",

        "iot:Publish",

        "iot:Subscribe",

        "iot:Receive",

        "greengrass:Discover"

      ],

      "Resource": "*"

    }

  ]

}
  1. Create things

Click “Manage”--->“Things”--->“Create things”--->“Create single thing”

 
 image-20220709165402-6.png
 
 image-20220709165402-7.png
 
 image-20220709165402-8.png

Name the thing--->Click “Next”

Select the way to create certificate

 
 image-20220709165402-9.png

Select policy

 
 image-20220709165402-10.png
 
 image-20220709165402-11.png
  1. Test with MQTT.fx tool

Click “View Setting” to get the “Broker Adress”

 
 image-20220709165402-12.png
 
 image-20220709165402-13.png
 
 image-20220709165402-14.png

Create one connection in MQTT.fx tool, set broker port as 8883.

Upload the CA File, Client Certificate File, Client Key File

 
 image-20220709165402-15.png

Publish message to topic “TEST”

 
 image-20220709165402-16.png
 
 image-20220709165402-17.png

Click”Test”--->”MQTT test client”--->”Subscrible to a topic”, to get message publish from MQTT.fx tool.

And we can also send message form AWS platform to MQTT.fx tool.

 
 image-20220709165402-18.png
  1. Configurate in CloudTool

Copy the same setting in MQTT.fx to MQTT configuration

 
 image-20220709165402-19.png

 Add a lua script and copy the lua demo into it.

 
 image-20220709165402-20.png

sprint = print

--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()

--publish to topics

local pub_RE_TOPIC = string.format('TEST')

--Subscribe topics

local Subscribe_RE_TOPIC1 = string.format('TEST')

--variable

local last_time = 0

--Timing main function

function aws.main()

   sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " aws.main start")

   if g_mq then

        if g_mq:isconnected() then

            send_Data()

        else

            if os.time() - last_time > 5 then

                last_time = os.time()

                mymqtt_connect()

            end

        end

    else

        mymqtt_init()

    end

    sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " aws.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(TEST, 0)

end

-- Receive MQTT message callback function

function mymqtt_msg_callback(topic, msg)

    print("topic:",topic)

    print("revdata:",msg)

    local revData = json.decode(msg)

    print (revData)

 if topic == Subscribe_RE_TOPIC1 then --Process topic information subscribed from the cloud

if string.match(topic,Subscribe_RE_TOPIC1) then

    --if revData ~= nil then

        for k,v in pairs (revData) do

            print("printing revdata after kv here")

            print (k,v)

        end

        print ("current state is",fanstate)

    --end

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 =

    {

123

}

sprint(json.encode(pub_data))

print("..........",pub_RE_TOPIC)

    return g_mq:publish(pub_RE_TOPIC, json.encode(pub_data), 0, 0)

end

Get message in AWS

 
 image-20220709165402-21.png