Device simulation
wutu opened this issue · 4 comments
Hello, Very nice software!
I am testing communication and if I understood correctly. Should be sufficient post mosquitto_pub -r -t /outbox/testdev/lwt -m 'stillAlive' -k 5 --will-topic /outbox/pimatic/lwt --will-payload 'died' --will-retain
.
Add devices to a Crouton, start connect and obtaining get on inbox topic.
I will send mosquitto_pub -t '/outbox/testdev/deviceInfo' -m '{"deviceInfo": {"name": "testdev", "endPoints": {"barDoor": {"title": "Bar Main Door", "card-type": "crouton-simple-text", "units": "people entered",}}, "description": "IOT devices", "status": "good"}}'
.
The device is not added. I missed something?
Everything you have said seems correct. When the device is added on Crouton, Crouton subscribes to "/outbox/"+device_name+"/deviceInfo"
and expects a reply from the device after sending "get" to "/inbox/"+device_name+"/deviceInfo"
. If you are sending the json after clicking Add Device
then it should work.
Just to check, the name of the device you are using to add to Crouton is "testdev"?
Also I assume that you connecting Crouton to your local mqtt broker? (simple thing but just checking)
Ah, I think I got it. The json you are passing isn't valid. There is an extra comma after "units":"people entered"
. Try this instead:
mosquitto_pub -t '/outbox/testdev/deviceInfo' -m '{"deviceInfo": {"name": "testdev", "endPoints": {"barDoor": {"title": "Bar Main Door", "card-type": "crouton-simple-text", "units": "people entered"}}, "description": "IOT devices", "status": "good"}}'
Let me know if that doesn't work
Thank you for answer. Yes, I have this error, but I tried other messages without error.
To maintain the connection I had to comment out as follows:
https://github.com/edfungus/Crouton/blob/master/public/app/framework/crouton-connect-mqtt/crouton-connect-mqtt.pug#L215-L219
Crouton otherwise performs an immediate unsubscribe.
Yes, I see now. I was not familiar with the mosquitto_pub
command. So if I have the MQTT spec correct, the lwt is set per client on the broker but not published. The broker publishes your lwt message on your device's behalf once the keep alive runs out without response from your device.
The purpose of the lwt is a way of telling the lwt topic subscribers that a device has disconnected. A device can't do that if it is disconnected so the broker handles the publishing.
So if you publish the lwt message, Crouton will think that the device has disconnected. Try setting the lwt to the broker but not publishing it. The broker will send the lwt for you when your device disconnects