on the simulator works on device no

this app deals with mqtt communication with secure ssl connection, everything is ok on the simulator, it connects to the mqtt broker and exchanges data while when simulating on a real device the app crashes with a black screen . portion of code and project annex
inviato.rar (1.5 MB)

code:


– title.lua


local composer = require( “composer” )
local scene = composer.newScene()
local mqtt = require (‘mqtt.init’)
–local mqttp = require ‘paho.mqtt’

local socket = require (“socket”)
–**************
local http = require(‘socket.http’)
local ltn12 = require(‘ltn12’)

–local crypto = require “crypto”
–**************

–require(“ssl”)
local json = require “json”
local bitlib = require( “plugin.bit” )
local ssl = require( “plugin.openssl” )
–local plugin_luasec_ssl = require(‘plugin_luasec_ssl’)

lua_openssl_version, lua_version, openssl_version = openssl.version()
print( "lua-openssl version: " … lua_openssl_version, lua_version, openssl_version )

– forward declaration
local background
local function vaiSuCanc()
composer.gotoScene( “cancella”, “slideLeft”, 200 )
end
local function vaiSuImpo()
composer.gotoScene( “impo”, “slideLeft”, 200 )
end
local function vaiSuDisp()
composer.gotoScene( “aggiungi”, “slideLeft”, 200 )
end
local function vaiSuInit()
composer.gotoScene( “init” )
end
function scene:create( event )
local sceneGroup = self.view

-- Called when the scene's view does not exist.
-- 
-- INSERT code here to initialize the scene
-- e.g. add display objects to 'sceneGroup', add touch listeners, etc.

-- display a background image
local background = display.newRect(0,0,360, 640) --background = display.newImageRect( sceneGroup, "img/schermoBlu.png", display.contentWidth, display.contentHeight )

background:setFillColor(0.3,0.3,0.3)
background.x = display.contentCenterX – sfondo da 0 alla massima copertura
background.y = display.contentCenterY – uguale per Y

– local buttonMenu = display.newImageRect(“img/menu.png”,50,50)
– buttonMenu:setFillColor(1,0,0) – Set the fill color to Red (These are normalized R,G
– buttonMenu.x = 35-- centerX
– buttonMenu.y = 35–centerY
local buttonMenu2 = display.newImageRect(“img/frecciaB.png”,30,30)
buttonMenu2:setFillColor(1,1,1) – Set the fill color to Red (These are normalized R,G
buttonMenu2.x = display.contentCenterX -120 --35-- centerX
buttonMenu2.y = display.contentCenterY -260 --35–centerY

	-- Add more text
local menuText = display.newText( " DOMO ELKOR", 10, 10, native.systemFont, 15 )
menuText.x = display.contentCenterX -0  --+ 35--display.contentWidth  -0
menuText.y = display.contentCenterY -260 
menuText:setFillColor(1,1,1)

local buttonImpo = display.newImageRect(“img/uomo+.png”,30,30)
buttonImpo:setFillColor(1,1,1) – Set the fill color to Red (These are normalized R,G
buttonImpo.x = display.contentCenterX +100-- centerX
buttonImpo.y = display.contentCenterY +220–centerY

-- Add more text
local impoText = display.newText( " Account", 0, 0, native.systemFont, 11 )
impoText.x =  display.contentCenterX +100 --display.contentCenterX + 35--display.contentWidth  -0
impoText.y =  display.contentCenterY +250 --display.contentCenterY -150--display.contentHeight - (display.contentHeight*0.1)	

impoText:setFillColor(1,1,1)

local buttonDisp = display.newImageRect(“img/piu.png”,30,30)
buttonDisp:setFillColor(1,1,1) – Set the fill color to Red (These are normalized R,G
buttonDisp.x = display.contentCenterX -0 – centerX
buttonDisp.y = display.contentCenterY +220–centerY

local buttonCanc = display.newImageRect(“img/meno.png”,25,25)
buttonCanc:setFillColor(1,1,1) – Set the fill color to Red (These are normalized R,G
buttonCanc.x = display.contentCenterX -100 – centerX
buttonCanc.y = display.contentCenterY +220–centerY

-- Add more text
local dispoText = display.newText( " Aggiungi", 10, 10, native.systemFont, 11 )
dispoText.x =  display.contentCenterX  -0 --display.contentCenterX + 35--display.contentWidth  -0
dispoText.y =  display.contentCenterY  +250 --display.contentCenterY -150--display.contentHeight - (display.contentHeight*0.1)
dispoText:setFillColor(1,1,1)  

local cancText = display.newText( " Cancella", 10, 10, native.systemFont, 11 )
cancText.x = display.contentCenterX -100 --display.contentCenterX + 35–display.contentWidth -0
cancText.y = display.contentCenterY +250 --display.contentCenterY -150–display.contentHeight - (display.contentHeight*0.1)
cancText:setFillColor(1,1,1)

-- all display objects must be inserted into group
sceneGroup:insert( background )
sceneGroup:insert( dispoText )

sceneGroup:insert( impoText )
sceneGroup:insert( buttonImpo )
sceneGroup:insert(buttonDisp)
sceneGroup:insert(menuText)
sceneGroup:insert(buttonMenu2)
sceneGroup:insert(cancText)
sceneGroup:insert(buttonCanc)

buttonImpo:addEventListener( “tap”, vaiSuImpo ) – vado sullo screen (scena) game.lua
buttonDisp:addEventListener( “tap”, vaiSuDisp )
buttonMenu2:addEventListener( “tap”, vaiSuInit )
buttonCanc:addEventListener( “tap”, vaiSuCanc )
end
–========== funzione sostituisce caratteri in stringa ===============
function replaceChar(pos, str, r)
return table.concat{str:sub(1,pos-1), r, str:sub(pos+1)}
end
–===================================================================
local function tx()
– create mqtt client
local client = mqtt.client{
– NOTE: this broker is not working sometimes; comment username = “…” below if you still want to use it
– uri = “test.mosquitto.org”,
uri = “mqtt.flespi.io”,
– NOTE: more about flespi tokens: https://flespi.com/kb/tokens-access-keys-to-flespi-platform
username = “stPwSVV73Eqw5LSv0iMXbc4EguS7JyuZR9lxU5uLxI5tiNM8ToTVqNpu85pFtJv9”,
clean = true,
}
print(“created MQTT client”, client)

client:on{
connect = function(connack)
if connack.rc ~= 0 then
print(“connection to broker failed:”, connack:reason_string(), connack)
return
end
print(“connected:”, connack) – successful connection

	-- subscribe to test topic and publish message after it
	assert(client:subscribe{ topic="luamqtt/#", qos=1, callback=function(suback)
		print("subscribed:", suback)

		-- publish test message
		print('publishing test message "hello" to "luamqtt/simpletest" topic...')
		assert(client:publish{
			topic = "luamqtt/simpletest",
			payload = "hello",
			qos = 1
		})
	end})
end,

message = function(msg)
	assert(client:acknowledge(msg))

	print("received:", msg)
	print("disconnecting...")
	assert(client:disconnect())
end,

error = function(err)
	print("MQTT client error:", err)
end,

}

print(“running ioloop for it”)
mqtt.run_ioloop(client)

print(“done, ioloop is stopped”)
end
–=====================================================================
function scene:show( event )
–sceneGroup = self.view
local phase = event.phase

if phase == "will" then
	-- Called when the scene is still off screen and is about to move on screen
elseif phase == "did" then
	-- Called when the scene is now on screen
	-- 
	-- INSERT code here to make the scene come alive
	-- e.g. start timers, begin animation, play audio, etc.
	
	--background.touch = onBackgroundTouch
	--background:addEventListener( "touch", background )
--###########################################################

tx()

--###########################################################

end

end

–[[
function ricevi(rx)
local payload = rx.payload
local lung = string.len(payload)
local payl = replaceChar(lung,payload," “)
payl = replaceChar(1,payload,” ")
print(“stampa segnale :”,payl)
end
–]]

function scene:hide( event )
–sceneGroup = self.view
local phase = event.phase

if event.phase == "will" then

	-- Called when the scene is on screen and is about to move off screen

	
elseif phase == "did" then
	-- Called when the scene is now off screen
--composer.removeScene( "menu" )

end	

end

function scene:destroy( event )
–local sceneGroup = self.view

-- Called prior to the removal of scene's "view" (sceneGroup)

end


– Listener setup
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )


return scene

I don’t think anyone is going to be able to read the code you posted and provide any help. The formatting is crazy, the code is way too long and your “it does not work” statement is very generic… no error message, etc.

Best suggestion I can offer is to connect your device to your computer and examine output via print statements and/or error codes. For Android, use adb logcat, and for iOS, use XCode.

making the log I receive these data, on the simulator everything works anyway, I don’t understand, thanks

I/Corona (20960): Platform: X16 / ARM Neon / 5.1 / Mali-T720 / OpenGL ES 3.1 / 2018.3326 / italiano | IT | it_IT | it
I/Corona (20960): scrivo key su dispo
I/Corona (20960): ::::::: indirizzo:::: /data/data/com.gmail.lab.sge.inviato/app_data/key.pem
I/Corona (20960): ::::::: indirizzo:::: /data/data/com.gmail.lab.sge.inviato/app_data/ca.crt
I/Corona (20960): lua-openssl version: 0.0.6 Lua 5.1 OpenSSL 1.0.2h 3 May 2016
I/Corona (20960): WARNING: Could not load class ‘mqtt.LuaLoader’
I/Corona (20960): ERROR: Runtime error
I/Corona (20960): /Users/jenkins/slaveroot/workspace/Templates/label/android/platform/resources/init.lua:913: module ‘mqtt’ not found:resource (mqtt.lu) does not exist in archive
I/Corona (20960): no field package.preload[‘mqtt’]
I/Corona (20960): no file ‘(null)/mqtt.lua’
I/Corona (20960): no file ‘(null)/mqtt.lua’
I/Corona (20960): no file ‘/data/app/com.gmail.lab.sge.inviato-1/lib/arm/libmqtt.so’
I/Corona (20960): no file ‘./mqtt.so’
I/Corona (20960): no file ‘(null)/mqtt.so’
I/Corona (20960): no file ‘/data/app/com.gmail.lab.sge.inviato-1/lib/arm/libmqtt.so’
I/Corona (20960): no file ‘./mqtt.so’
I/Corona (20960): no file ‘(null)/mqtt.so’
I/Corona (20960): stack traceback:
I/Corona (20960): [C]: in function ‘require’
I/Corona (20960): /Users/jenkins/slaveroot/workspace/Templates/label/android/platform/resources/init.lua:913: in function ‘require’
I/Corona (20960): C:\Users\info\Documents\Corona Projects\inviato\mqtt\client.lua:95: in function ‘__init’
I/Corona (20960): C:\Users\info\Documents\Corona Projects\inviato\mqtt\client.lua:1201: in function <C:\Users\info\Documents\Corona Projects\inviato\mqtt\client.lua:1199>
I/Corona (20960): (tail call): ?
I/Corona (20960): C:\Users\info\Documents\Corona Projects\inviato\connessione_mqtt_ssl.lua:128: in function ‘tx’
I/Corona (20960): C:\Use
I/Corona (20960): ERROR: Runtime error
I/Corona (20960): /Users/jenkins/slaveroot/workspace/Templates/label/android/platform/resources/init.lua:913: module ‘mqtt’ not found:resource (mqtt.lu) does not exist in archive
I/Corona (20960): no field package.preload[‘mqtt’]
I/Corona (20960): no file ‘(null)/mqtt.lua’
I/Corona (20960): no file ‘(null)/mqtt.lua’
I/Corona (20960): no file ‘/data/app/com.gmail.lab.sge.inviato-1/lib/arm/libmqtt.so’
I/Corona (20960): no file ‘./mqtt.so’
I/Corona (20960): no file ‘(null)/mqtt.so’
I/Corona (20960): no file ‘/data/app/com.gmail.lab.sge.inviato-1/lib/arm/libmqtt.so’
I/Corona (20960): no file ‘./mqtt.so’
I/Corona (20960): no file ‘(null)/mqtt.so’
I/Corona (20960): stack traceback:
I/Corona (20960): [C]: ?
I/Corona (20960): [C]: in function ‘require’
I/Corona (20960): /Users/jenkins/slaveroot/workspace/Templates/label/android/platform/resources/init.lua:913: in function ‘require’
I/Corona (20960): C:\Users\info\Documents\Corona Projects\inviato\mqtt\client.lua:95: in function ‘__init’
I/Corona (20960): C:\Users\info\Documents\Corona Projects\inviato\mqtt\client.lua:1201: in function <C:\Users\info\Documents\Corona Projects\inviato\mqtt\client.lua:1199>
I/Corona (20960): (tail call): ?
I/Corona (20960): C:\Users\info\Documents\Corona Projects\inviato\connessione_mqtt_ssl.lua:128: in function ‘tx’
I/Corona (20960): C:\Users\info\Documents\Corona Projects\inviato\connessione_mqtt_ssl.lua:195: in function ‘method’
I/Corona (20960): /Users/jenkins/slaveroot/workspace/Templates/label/android/platform/resources/init.lua:221: in function ‘dispatchEvent’
I/Corona (20960): /Users/jenkins/slaveroot/workspace/Templates/label/android/subrepos/composer/composer.lua:886: in function </Users/jenkins/slaveroot/workspace/Templates/label/android/subrepos/composer/composer.lua:865>
I/Corona (20960): (tail call): ?
I/Corona (20960): /Users/jenkins/slaveroot/workspace/Templates/label/android/subrepos/transition/transition.lua:599: in function ‘method’
I/Corona (20960): /Users/jenkins/slaveroot/workspace/Templates/label/android/platform/resources/init.lua:221: in function </Users/jenkins/slaveroot/workspace/Templates/label/android/platform/resources/init.lua:190>