SIM800l #1318
-
I want to program the sim800l, but it didn't work. I was able to connect to the sim800l module with device.io.Serial, but I can't get the information I want, for example, I want to send a message, and when I send commands like this: this.#serialWrite("AT+CMGF=1"); // Configuring TEXT mode
// this.#serialWrite("AT+CSCS=\"HEX\"");
this.#serialWrite("AT+CSMP=49,167,0,8");
this.#serialWrite("AT+CMGS=\"+0000\"");
this.#serialWrite("Hi from moddable"); //text content
this.#serialWrite(26); This way it displays the serial in the onReadable function, but I expect the response to be OK or ERROR, in Arduino everything works great, so the module is ok, but here I couldn't get the correct response: AT+CMGF=1AT+CSMP=49,167,0,8AT+CMGS="+00000" Hello from moddable Full code : import Timer from "timer"
import TextDecoder from "text/decoder"
class SIM800 {
#config = {}
#serial = null
constructor (config = {}) {
this.#config = {
...config
}
this.#serial = new device.io.Serial({
...device.Serial.default,
port: 2,
baud: 9600,
receive : 16,
transmit: 17,
...config?.serial,
format : "buffer",
flowControl: "hardware",
target : this,
onReadable: this.#serialReadable
});
this.#serialWrite("AT+CMGF=1"); // Configuring TEXT mode
// this.#serialWrite("AT+CSCS=\"HEX\"");
this.#serialWrite("AT+CSMP=49,167,0,8");
this.#serialWrite("AT+CMGS=\"+0000\"");
this.#serialWrite("Hi from moddable"); //text content
this.#serialWrite(26);
}
#serialReadable (count) {
if ( count ) {
const read = this.read()
if ( read && read.byteLength ) {
const decoder = new TextDecoder
const string = decoder.decode(read, {stream: true})
if ( typeof string === "string" ) {
trace(`\nSIM800l : ${JSON.stringify(string)}`)
}
}
}
}
#serialWrite (cmd = "") {
Timer.delay(500)
this.#serial.write(ArrayBuffer.fromString(cmd))
}
}
export default SIM800
Maybe this arduino code will be more helpful for guidance : #include <Arduino.h>
//#include <SoftwareSerial.h> // Remove if using HardwareSerial
#define RX_PIN 16
#define TX_PIN 17
#define BAUDRATE 9600
HardwareSerial mySerial(2); // ESP32 Example
void setup()
{
//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
//Begin serial communication with Arduino and SIM800L
mySerial.begin(9600);
Serial.println("Initializing...");
delay(1000);
mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
updateSerial();
mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
updateSerial();
//mySerial.println("AT+CSCS=\"HEX\"");
//updateSerial();
mySerial.println("AT+CSMP=49,167,0,8");
updateSerial();
mySerial.println("AT+CMGS=\"+0000\""); //country code, phone number to sms
updateSerial();
mySerial.print("Hi"); //text content
updateSerial();
mySerial.write(26);
}
void loop(){}
void updateSerial()
{
delay(500);
while (Serial.available())
{
mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
}
while(mySerial.available())
{
Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
I tried to use this serial model but it didn't work because it doesn't work with the new version of Moddable SDK and it gives a lot of errors. Please check and update. https://github.com/Moddable-OpenSource/moddable/tree/public/contributed/serial |
Beta Was this translation helpful? Give feedback.
The Arduino example uses
println
which, I believe, adds a line feed at the end of the transmission. Your#serialWrite
function useswrite()
which does not add a line feed. You probably need to do something like this:Also, this may not do what you intend:
Your code will call
ArrayBuffer.fromString
which will output the characters "2" and "6". If you intend to output an ASCII 26, then you could do: