Current Lua downloadable firmware will be posted here

User avatar
By klamgade
#55649 Hey!! I am able to publish a data of different sensors (like temperature value and motion detection as zero or one) one at a time on a specific topic ( topic/temp/motion) using Lua code and subscribe in on my android app however i am not able to publish it simultaneously on same topic or sub-topic. Some ideas or examples would be great.
Below are some major bits of Lua code used.

Code: Select all orgID = "quickstart" -- IoT Foundation organization ID
broker = "test.mosquitto.org"   --orgID..".messaging.internetofthings.ibmcloud.com" -- IP or hostname of IoTF service
mqttPort = 1883 -- MQTT port (default 1883: non-secure)
userID = "" -- blank for quickstart
userPWD = "" -- blank for quickstart
macID = "18fe34e1b007" -- unique Device ID or Ethernet Mac Address <==== Modify this!
clientID = ":esp8266:18fe34e1b007" -- Client ID
count = 0 -- Test number of mqtt_do cycles
mqttState = 0 -- State control
topic = "topic/temp/motion"
led = 4
--gpio.mode(led,gpio.OUTPUT)
--dht sensor settings------------------------------
 pin = 1
-- PIR initialization section
pir = 2
x= 0 -- variable for sending motion detection information in "0 or 1"

function DHT_do()
status, temp, humi, temp_dec, humi_dec = dht.read(pin)
--gpio.write(led, gpio.LOW)
end


Code: Select all function mqtt_do()
 count = count + 1 -- tmr.alarm counter
------------------------------------------- pir conditional code
if gpio.read(pir) ~= last_state then
        last_state = gpio.read(pir)
        if last_state == 1 then
        print("ON")
        x = 1
        gpio.write(led,gpio.HIGH)
        else
        print("OFF")
        x = 0
       gpio.write(led,gpio.LOW)


Code: Select allm:publish(topic,x, 0, 0,
 function(conn)
  print(x)
  print("temp_data:"..temp)