MQTT client and HTTP module don't work together? #4600
Replies: 1 comment
-
Posted at 2018-01-26 by PaddeK Hmm looks like the close() for the apServer closes the MQTT connection too. Posted at 2018-01-26 by sureshkm @PaddeK But the MQTT makes a connection during
and not during
Right? In that case, client connection is happening after the close() call. Posted at 2018-01-26 by @gfwilliams So you're saying that if you just run Can you try doing something like:
And see if that works ok? The calls to the ESP8266 will be asynchronous, so I guess it's possible that the driver isn't correctly delaying the creation of the new MQTT connection, and so is trying to re-use the apServer socket that hasn't yet closed? Posted at 2018-01-26 by sureshkm Sure, i will try. But if i make HTTP request in the place of MQTT connect, I'm getting the HTTP response back from the server. The following code works
Posted at 2018-01-26 by sureshkm
If you notice, whenever there is a cold start, i instantiate the ESP8266WiFi_0v25 twice in the flow and that is the case where it does not work. Every time after the cold start, it instantiates the ESP8266WiFi_0v25 once and it works fine. Posted at 2018-01-26 by @gfwilliams Ok, yes - I think one problem might be that you're calling Try only initialising it once. Or if you feel you really have to do it twice, use Also, you're trying to shut a socket and then immediately restart the ESP8266, before the command has even finished sending. Try tweaking your code to add a timeout as well:
Posted at 2018-01-26 by PaddeK If the http module is the one from nodejs the close function does have a callback parameter. -- Edit -- Posted at 2018-01-26 by sureshkm Thanks @PaddeK, i just tried to use the callback, but unfortunately there is no callback it seems. Posted at 2018-01-26 by sureshkm I tried adding But all the scenarios, if i make a new HTTP connection instead of I strongly believe that there is something to do with Posted at 2018-01-27 by sureshkm Ok, i figured out that this happens intermittently, so i'm trying to at least suppress the uncaught error, it does not work, but why? Isn't the try..catch supported?
Posted at 2018-01-29 by @gfwilliams There's no
Is it possible to post up a complete set of code that gives you the problem? Ideally as minimal as possible. I'm a bit confused since the error that's being reported in MQTT points to lines that don't actually exist in the MQTT module on Espruino.com: http://www.espruino.com/modules/MQTT.min.js Are you using your own version of the modules? Posted at 2018-01-31 by sureshkm Hi @gfwilliams, Thanks for looking into it. I've unchecked 'Modules uploaded as functions (BETA)' and 'Javascript compiler' from the config. I'm not sure if they make any difference. But i get the following error and that line is part of MQTT.min.js file.
I will try to post up the code soon. Posted at 2018-02-01 by @gfwilliams Ahh, ok - that looks more like the right file now - but still the same error :( If you could post up a complete file that has the problem then it'd really help to track it down though. Posted at 2018-02-01 by sureshkm @gfwilliams I've posted some main parts of my code base. Hope this helps!
Posted at 2018-02-02 by @gfwilliams I just tried this, and it works for me (after some messing around). I did have to manually use f.write and trigger it though since there was no HTML form - and it wouldn't have worked anyway because the password wasn't set. I do get the disconnect error if I specify an incorrect IP address for the MQTT server though, so I've committed a fix for that which should go live in a few hours. Looking at your code it seems that if you POSTed to anything that wasn't |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2018-01-25 by sureshkm
Hi @gfwilliams and others,
I've used Espruino Pico with ESP8266 on it. My device is trying to connect to the internet the similar way that the Amazon Echo or Google Home connects.
I collect the WiFi credentials using a web form that is served from the HTTP server that runs on Espruino Pico,
After collecting the WiFi credentials and storing them in the ROM, i close the server, connect to the internet and then finally connect to my MQTT broker that runs on Digital Ocean.
I get the error message from MQTT client saying that the connection is closed.
But the MQTT broker is running fine and i get to see that MQTT client could reach the broker server. Instead of MQTT client call, if i make the following call, it works,
I believe that there is something happening only after i run the HTTP server and close. Because if i retrieve the WiFi credentials from the memory instead of running the HTTP server and I'm able to connect to the MQTT broker successfully.
Please help me.. thanks.
Beta Was this translation helpful? Give feedback.
All reactions