-
-
I found this issue :
https://github.com/espruino/Espruino/issues/830I inject this instruction : LoopbackA.setConsole(), via mqtt protocol to the device,
then the serial data is coming to the server app. -
Hello @MaBe,
The problem of using software serial is the success rate of serial data. It is very low, only 30%, we get the proper data, although using a low baud rate at 4800. While using the hardware serial, we get more than 90% success rate. So, I discontinue using software serial.
-
-
Hello @MaBe,
Yes, I have tried using software serial, but the serial data is not reliable, although I set the baud-rate at 4800. And, after one or 3 hours, the ESP8266 will crash.
Using hardware serial, the data is more reliable. However, after disconnection over tcp/ip,
there is no data coming from the device, as seen in a server application.
I use MQTT protocol to send data from device to the server.Regards,
Maman -
Hello..
I attach a serial device to the Serial1 on ESP8266.
To retain the connection of the serial device, I put a code offunction onInit() { Serial1.setConsole(); }
at the begining of the program.
However, data from the serial device can't be obtained.
But, if we connect the ESP8266 using TCP in espruino web IDE, then
the data from the serial device has appeared.Is there any instruction that can activate the serial device connection ?
Regards,
Maman -
Hello @allObjects,
What is espruino version do you use ?
Previously, I used espruino_2v00.17 on ESP-07. It was periodically crashed.
Changed to espruino_1v99, using the same script code, it is no problem. -
-
Hello @MaBe,
Now, I am trying to use software serial to communicate with MODBUS energy meter.
The RS485 MODBUS protocol required 1 stop bit, 8 databits, 1 even parity and 1 stop bit.
So, need 11 bits in total.The software serial can send the command to the meter, however, get error data from the meter.
If I change to use hardware serial, using the same code, the ESP can receive data, properly.
The error data is consistent. The first byte is should be 0x01 (00000001), but we get 0x80
(10000000). The second byte should be 0x03, in serial monitor I get data as follows :
10000000 00000001 10000010
first byte second byte third byte, respectively.
It seem that the second byte is shifted to the right.Is there any hint to correct the bytes ?
Thanks,
-
-
Sorry, just now, I updated the espruino code to the latest one.
It is working perfectly. This is my test code :var status=0; function swap() { status = !status; digitalWrite(D2, status); } var Serial3 = new Serial(); Serial3.setup(9600, {rx:D4,tx:D5}); //Serial1.setup(9600); Serial3.on('data', function (data) { console.log(data); swap(); }); var buf1 = new ArrayBuffer(); buf1 = [0x01, 0x03, 0x00, 0x00, 0x00, 0x05, 0x85, 0xC9]; var count = 0; setInterval(function() { if (count > 7) { count = 0; } console.log("send data", count); Serial3.write(buf1); count += 1; }, 2000);
However, if we increase the baud-rate to 115200, the ESP will be crashed.
But, for my application, it is Ok. For displaying the data to the LED matrix display, that required highspeed UART at 115200, I will use hardware serial.Thanks for your help, @MaBe
-
yes. Yesterday, I updated the source.
We also tested for sending data from ESP to PC, we found that the PC get the wrong data, at any baudrate. So, for receiving, the software serial is ok for up to 9600, while for sending data is failed.
My code is tested on hardware serial (Serial1), it is no problem for sending or receiving.
We need two serials on my ESP-12, one is for getting data from sensor and the other for displaying the data to LED matrix display. -
Hello @MaBe,
I have tested your code on Wemos D1 Mini (ESP8266, ESP-12) using Espruino 2.00,
var status=0; function swap() { status = !status; digitalWrite(D2, status); } var Serial3 = new Serial(); Serial3.setup(9600, {rx:D4,tx:D5}); Serial3.on('data', function (data) { console.log(data); swap(); });
Serial3 is assigned as software serial.
If we send one-by-one character, I can see the console log is Ok. Perfectly working.
If we send for example "test" string, then in the console.log will be displayed "t" and "est".However, if we increase the baudrate to 115200, software-serial will get the wrong data.
Thanks @MaBe
-
Hello @Wilberforce,
Yes, I am using esp8266 (wemos d1 mini).
I have put the program on "save on send" option.
The script should be small in size as followsI2C1.setup({scl:D5,sda:D4, bitrate:100000}); var PID = require('pid-controller'); var bme = require("BME280").connect(I2C1); var WIFI_NAME = "xxx"; var WIFI_OPTIONS = { password : "xxx" }; var MQTT_HOST = "192.168.0.156"; var PATH = "/mydevice/"; var LED = D13; var RELAY = D12; var BTN = D0; var mqtt; var wifi; var hum = 20, humSetpoint = 55; var Kp = 100, Ki = 0, Kd = 0; var ctr; var timeframe = 30000; var dacMin = 100; var dacMax = 3000; wifi = require("Wifi"); var nodeID = wifi.getIP().mac; nodeID = nodeID.replace(/:/g, ""); nodeID = nodeID.toUpperCase(); function updatePid() { hum = bme.getData().humidity; hum = hum.toFixed(1); hum = E.clip(hum, 10, 100); ctr.setInput(hum); if (ctr.compute()) { var dataDac = ctr.getOutput(); dataDac = E.clip(dataDac, dacMin, dacMax); I2C1.writeTo(0x60, [dataDac >> 8, dataDac]); setTimeout(function() { var adc = analogRead().toFixed(3); var bufText = "{\"H\":"+hum+",\"DAC\":"+dataDac+",\"ADC\":"+adc+"}"; console.log(bufText); mqtt.publish(PATH+"status",bufText); }, 3000); } } function setState(v) { RELAY.write(v); LED.write(!v); mqtt.publish(PATH+"status", v?1:0); } function mqttMessage(pub) { console.log("MQTT=> ",pub.topic,pub.message); if (pub.topic == PATH+"set") { setState(pub.message!=0); } if (pub.topic == PATH+"eval") { try { mqtt.publish(PATH+"response", eval(pub.message)); } catch(e) { mqtt.publish(PATH+"exception", e.toString()); } } } function mqttConnect() { mqtt = require("MQTT").connect({ host: MQTT_HOST, client_id : nodeID, }); mqtt.on('connected', function() { console.log("MQTT connected"); setTimeout(function() { mqtt.subscribe(PATH+"#"); }, 1000); }); mqtt.on('publish', mqttMessage); } function onInit() { ctr = new PID(hum, humSetpoint, Kp, Ki, Kd, 'direct'); ctr.setSampleTime(timeframe); ctr.setOutputLimits(dacMin, dacMax); ctr.setMode('auto'); digitalWrite(D16,0); console.log("Connecting WiFi"); setInterval(updatePid, timeframe); setInterval(function() { if (!mqtt) return; if (!mqtt.connected) { console.log("MQTT disconnected... reconnecting."); mqtt.connect(); } digitalWrite(D16, 1); setTimeout( function d16() { digitalWrite(D16,0); }, 300); }, 60*1000); wifi = require("Wifi"); wifi.on('connected',function() { console.log("Connected to WiFi"); }); wifi.on('disconnected',function() { console.log("Disconnected from WiFi"); }); wifi.setHostname("MYDEVICE"); wifi.stopAP(); wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(ap){ console.log("Successful connect."); }); // wait, and connect MQTT setTimeout(function() { console.log("MQTT connecting"); mqttConnect(); }, 10000); }
and bellow is the error message
____ _ | __|___ ___ ___ _ _|_|___ ___ | __|_ -| . | _| | | | | . | |____|___| _|_| |___|_|_|_|___| |_| espruino.com 1v99 (c) 2018 G.Williams Espruino is Open Source. Our work is supported only by sales of official boards and donations: http://espruino.com/Donate Flash map 4MB:1024/1024, manuf 0xc8 chip 0x4016 > =undefined Running onInit()... Connecting WiFi Successful connect. Connected to WiFi MQTT connecting ERROR: Error processing Serial data handler - removing it. Execution Interrupted during event processing. New interpreter error: CALLBACK,LOW_MEMORY,MEMORY >
-
Hello @ClearMemory041063, @Wilberforce
I am using pid-controller and mqtt modules for our project, now.
We use Wemos D1 Mini.
I am trying the example simulation of the github @Wilberforce, it is working, normally.
However, if we combine the pid-controller and mqtt modules, when we
try to connect to mqtt broker, there is an error.Execution Interrupted during event processing. New interpreter error: LOW_MEMORY,MEMORY
Is there any issue for compatibility of pid-controller and mqtt module ?
Regards,
Maman -
@hungryforcodes, @allObjects, thanks for the reply. I use ESP-07 from Ai. Now, I am developing lamp controller that can be remotely controlled by MQTT protocol. However, I want to use the previously mechanical switch to control the lamp, locally, in case the network failed. I connected directly the mechanical switch to pin D5 of esp8266 tied-up with 10K resistor to VCC. It seems that the problem is the mechanical switch. I have tested the code below :
print("Starting watch set test\n"); var testPin = D13; pinMode(testPin, "input"); var watchId = setWatch(function() { print("The callback function was called for a pin I/O change\n"); }, testPin, { repeat: true} ); print("A new watch was set up with id=" + watchId + "\n");
And the result is there are many callback function was called, and the ESp8266 was crashed.
then I put a small capacitor on the switch terminal, and add debounce at 100, then it is run well.
Thanks for your attention. -
I use D5 and D4 of ESP8266 to detect pin status using setWatch.
setWatch(function updateDIN1() {
// ...
}, D5, {repeat:true, edge:'both', debounce:100});If I connect D5 to normally GND, then the ESP8266 will detect many interrupt, and
ESP8266 can not continue to run the other script program.
However, If I connect D5 to VCC via pull-up resistor, then when I change the D5 to GND, then
I will get many interrupt, and ESP8266 to busy accepting interrupt from the setWatch..Is there anyone have this kind of problem ?
Regards,
Maman
Yes, sure.
I want to develop ESP-Now gateway, based on this work
https://github.com/HarringayMakerSpace/ESP-Now.
Using espnow, it is possible to develop battery-powered devices for sensors,
using less IP-address devices.
For the gateway, I use 2 ESP8266, one is for connection with the esp-now network,
and the other is for connection to the internet via wifi. For the first device, I use arduino IDE,
while for the second device, I use espruino.
Communication between devices is using UART. Now, both device is using hardware serial.
I use ESP-07.
Regards,
Maman