Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serial1.on('data', function(data) { ... }) never called #1203

Closed
aoudiamoncef opened this issue Jul 24, 2017 · 21 comments
Closed

Serial1.on('data', function(data) { ... }) never called #1203

aoudiamoncef opened this issue Jul 24, 2017 · 21 comments
Labels
ESP8266 This is only a problem on ESP8266 devices

Comments

@aoudiamoncef
Copy link

Hello,
I send command over SPI and get the response via Serial.

I work fine with console, but i can't get response data to be processed.

I tried to setup ( with disconnected usb, i tried to get the value of data with http server ) Serial.on ... but it's never called, i used examples and i respected instructions in official documentation.

@gfwilliams
Copy link
Member

I guess this is on ESP8266? Did you do what I'd suggested in the last bug that you filed about this?

Use LoopbackA.setConsole() - you can't use Serial1.on('data', while the console is also on Serial1.

@gfwilliams gfwilliams added the ESP8266 This is only a problem on ESP8266 devices label Jul 24, 2017
@aoudiamoncef
Copy link
Author

When i use LoopbackA.setConsole()

var LED = whatever_a_led_is_connected_to;
Serial1.setup(115200);
Serial1.on('data', function (data) { LED.toggle(); });
Serial1.print("Hello World");
LoopbackA.setConsole();
i got this error:
Flash map 4MB:512/512, manuf 0xe0 chip 0x4016

Hello WorldERROR: Prompt not detected - upload failed. Trying to recover...

@gfwilliams
Copy link
Member

Yes. That's because - as I explained on the previous bug you filed, the console is now moved away, so the IDE cannot send or receive data to it: #1199

However you can ignore that message, and everything should work.

@aoudiamoncef
Copy link
Author

but i tried to get data from the handler and it's not work:
var dataFromHandler=""; //global var

dataFromHandler = data;//inside the handler

and i tried to display the content of the variable over http server, it always show "", never change.

If i change the variable in my code , it's displayed correctly, so the problem is not my http server but there is no data got from the handler.

@gfwilliams
Copy link
Member

How are you wiring everything up?

Because remember the RX pin is already connected to the USB adaptor - so if you stick something else on that pin then the signals will be 'fighting'.

@aoudiamoncef
Copy link
Author

My wiring is little bit complicated:
i have ESP8266 and Arduino Uno.

SPI connection: to send command from ESP8266 to Arduino Uno
4 pins connected (SPI bus) GND;

UART connection: to receive response from Arduino Uno
1Pin connected Rx(ESP8266) to Tx(Arduino Uno)

both devices are powered by USB cables connected to my PC.

Thanks

@gfwilliams
Copy link
Member

But your ESP8266 has a USB connection as well? Which is also (perhaps internally) connected to the RX pin?

@gfwilliams
Copy link
Member

What if you disconnect the Arduino uno from TX, and then upload the same code you had before, randomly type in the IDE, and then check from the HTTP server? You'll probably see data

@aoudiamoncef
Copy link
Author

if i add LoopbackA.setConsole(); my device is down

@gfwilliams
Copy link
Member

It should still be working - it's just that you can't communicate with it!

Just upload this code:

Serial1.on('data', function (data) { Serial1.print("Char\r\n"); });
LoopbackA.setConsole();

The Web IDE will complain, but try pressing some keys. 'Char' should be displayed every time you press a key.

@aoudiamoncef
Copy link
Author

aoudiamoncef commented Jul 24, 2017

This code works, may be i have conflict with SPI ? or http server ? because if i add LoopbackA.setConsole(); my device is down ( no wifi detected on ESP8266 ) else i remove this line , all works fine but can't get data from handler:

Serial1.on('data', function (data) { dataSerial='c';//just for test });

@gfwilliams
Copy link
Member

Maybe someone else can help with this? @MaBecker ?

I have no idea why wifi would stop working if you do setConsole.

Just one point though: If you're using SPI correctly you should be able to have two way communications and should have no need to use the UART as well. It might solve a lot of problems for you...

@aoudiamoncef
Copy link
Author

aoudiamoncef commented Jul 24, 2017

I tried to use just SPI, but i have a big deal because Espruino don't supporte Slave mode, so i can't send data from Arduino.

This is the result what i expected ( work fine without setConsole but no way to get data only display it)

command function was :

function initGas(arg){ var data2 ="{\"command\":\"HELP\",\"sensor\":\"MQ135\",\"gas\":\"CO2\"}\n"; SPI1.write(data2); }

`Flash map 4MB:512/512, manuf 0xe0 chip 0x4016

=undefined
Visit http://192.168.43.95 in your web browser.

{"MQ131":["O3"],"MQ135":["NH3","CO2"],"MULTI":["NH3","CO","NO2","C3H8","C4H10","CH4","H2","C2H5OH"]}

setConsole crash my http server on wifi.

@MaBecker
Copy link
Contributor

Hi @Sparow199,

not sure what your trying to build.

Setup Wifi and connect to a AP, use WEBIDE form you PC to connect over TCP/IP
Settings->Communication-> Connect over TCPIP

Now your Serials are free :)

I guess you would reach much more people if you post such things to the Espruino Forum.

@aoudiamoncef
Copy link
Author

aoudiamoncef commented Jul 24, 2017

@MaBecker , what is the default IP address ? , should i upload the code example or it's built in ? ( i have already an http server in my code )

@MaBecker
Copy link
Contributor

For AccesPoint it is 192.168.4.1 and Station IP is set via dhcp.

@aoudiamoncef
Copy link
Author

@MaBecker @gfwilliams thank you very much, i got what i need, using WiFi instead USB resolve Serial1.on handler probleme, i'm able to get data from it now.

Adding LoopbackA.setConsole(); crash the device, i don't know why ?

@MaBecker
Copy link
Contributor

Adding LoopbackA.setConsole(); crash the device, i don't know why ?

not on my side - feel free to close this issue :)

@manavakela1996
Copy link

# This code is not working for me. I tried below code...and tried many ways but not receiving on RX but TX works fine.
on Espruino v1.99 @gfwilliams

var status=0;
function swap() {
status = !status;
digitalWrite(NodeMCU.D0, status);
}
function onInit()
{
Serial1.setup(9600);
Serial1.on('data', function (data) { swap(); });
LoopbackA.setConsole();
}
//onInit();

@wilberforce
Copy link
Member

@manavakela1996

Sorry - github is not the place for these kind of questions. issues here's are for the C code that runs. Espruino.

Post your question here in the esp8266 section of the forum.

http://forum.espruino.com/microcosms/925/

Thanks

@manavakela1996
Copy link

ok but if you or any other can solve, It should great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ESP8266 This is only a problem on ESP8266 devices
Projects
None yet
Development

No branches or pull requests

5 participants