-
Hi @Gordon, 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.
Uncaught Error: This socket is closed. at line 1 col 58 ...e(g(c.DISCONNECT<<4)+"\x00"),this.client.end(),this.client=!... ^ in function "disconnect" called from line 1 col 52 a.ctimo=void 0;a.emit("disconnected");a.disconnect()
I will try to post up the code soon.
-
-
I tried adding
Serial2.removeAllListeners()
and tested, it does not work.
I tried initializing therequire("ESP8266WiFi_0v25").connect
only once and tested, it does not work.But all the scenarios, if i make a new HTTP connection instead of
client.connect()
(not making any MQTT calls), i'm getting the response and the socket is not closed.I strongly believe that there is something to do with
client.connect()
, especially it happens only when i run/close the HTTP server first and try to connect to the MQTT. -
Thanks @PaddeK, i just tried to use the callback, but unfortunately there is no callback it seems.
-
var client = require("MQTT").create('IP ADDRESS', options /*optional*/); .... function setup () { wifi = require("ESP8266WiFi_0v25").connect(Serial2, function(err) { // reset the n/w before the connection wifi.reset(function(err) { throwError(err); // SSID, Access Point PWD, Email id, Token Details, Session Token var apSSID = typeof f.read(0) !== 'undefined' ? E.toString(f.read(0)) : '', apPWD = typeof f.read(1) !== 'undefined' ? E.toString(f.read(1)) : ''; if (apSSID) { wifi.connect(apSSID, apPWD, function(err) { console.log('Device is successfully connected to the WiFi.'); // MQTT starts here client.connect(); .... } else { // creating the AP, running the HTTP server code // after getting the WiFi creds and saving that to the ROM, apServer.close(); setup(); } }
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.
Does it give any clue?
Does it need to do anything with the AP or Station mode of the Wifi module? -
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
apServer.close() ...... require("http").get("http://pur3.co.uk/hello.txt", function(res) { res.on('data', function(data) { console.log("HTTP> "+data); }); res.on('close', function(data) { console.log("Connection closed"); }); });
-
@PaddeK But the MQTT makes a connection during
client.connect();
and not during
var client = require("MQTT").create(server, options /*optional*/);
Right? In that case, client connection is happening after the close() call.
-
-
-
Hi @Gordon 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,
apServer = require("http").createServer(hsRouter).listen(80);
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.
var client = require("MQTT").create(server, options /*optional*/); .... // some code apServer.close() .... // some code client.connect();
I get the error message from MQTT client saying that the connection is closed.
in function called from system Uncaught Error: This socket is closed. at line 1 col 56 ...ite(b(a.DISCONNECT<<4)+'\0'),this.client.end(),this.client=!... ^ in function "disconnect" called from line 1 col 52 c.ctimo=void 0,c.emit('disconnected'),c.disconnect(); ^
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,
require("http").get("http://pur3.co.uk/hello.txt", function(res) { res.on('data', function(data) { console.log("HTTP> "+data); }); res.on('close', function(data) { console.log("Connection closed"); }); });
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.
-
Thank you! @Gordon Let me give a try.
-
Hi @Gordon and all,
I've an Espruino Pico. Is it possible for the MQTT client to connect to the MQTT broker over WebSocket protocol? -
@Gordon Thank you!
-
Thank you! @ClearMemory041063 I will try that.
-
-
-
-
Has anyone used PubNub API with Espruino Pico? Please let me know how to include the PubNub npm module or require the core JS file. Thanks in advance.
I followed http://forum.espruino.com/conversations/266254/#comment12223235 and
require('https://cdn.pubnub.com/sdk/javascript/pubnub.4.16.1.min.js');
But it shows the error as 'You have more open brackets than close brackets. Please see the hints in the editor window'.
-
Thanks, @Gordon
Now that fixes the firmware corruption. But still get the memory issue for 4K code.Can you please tell me, how/why did it get "81600 bytes" when there is only a few bytes of code?
-
-
function onInit() { digitalWrite(LED1, 1); } save();
Even saving the above code throws the below lines,
Erasing Flash..... Writing..... Compressed 81600 bytes to 2705 Checking... Done! Running onInit()...
How/Why did it get "81600 bytes" when there is only a few bytes of code? Am i missing something that happens internally?
-
Yes, give it a go. Basically normal save() will compress the code that gets written, but because save on send is trying to execute straight from flash it can't compress anything
I did enable and corrupted my firmware, it took 2 hours to figure out why wasn't the IDE detecting the Espruino Pico :). Finally i flashed the firmware and it started detecting it.
I brought down the file size to approx. 40KB, but the when i tried to write the code to Pico, it always says,
Erasing Flash..... Writing.......................... Compressed 81600 bytes to 23744 Checking... Done! Running onInit()...
Any idea, why doesn't it read as "40000 bytes to ...." ?
-
@Gordon Thanks for the quick response.
I don't have any SSL keys/certs in the code. I think, we don't need them for the retrieval of HTTPS doc. Right?
Yes, i've approx. 80KB code that gets compressed into approx. 20KB while writing into the Pico. How much should the code size be to make it work?
'Save on send' options says '.... not as memory efficient', Do you really want me to enable this?
-
I think, http://forum.espruino.com/conversations/302991/ is similar to the issue discussed here. Did we get any solution?
@Gordon I've posted some main parts of my code base. Hope this helps!