Hi ,I am using Sim 800l and a sd card to store phone number i have a sketch that compiles with no errors.
I can see the number in Serial monitor, but i dont get a sms, if i hard code the number in the sketch, i get an sms. any help would be appreciated
.
#include <Sim800l.h>
#include <SoftwareSerial.h> //is necesary for the library!!
Sim800l Sim800l; //to declare the library
char* text;
char* number;
bool error; //to catch the response of sendSms
#include <SPI.h>
#include <SD.h>
File myFile;
void setup() {
Sim800l.begin(); // initializate the library.
Serial.begin(9600);
Serial.print("Initializing SD card...");
if (!SD.begin(10)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
// re-open the file for reading:
myFile = SD.open("test.txt");
// read from the file until there's nothing else in it:
while (myFile.available()) {
Serial.write(myFile.read());
}
}
void loop() {
myFile = SD.open("test.txt");
// read from the file until there's nothing else in it:
while (myFile.available()) {
text="ivan"; //text for the message.
number= myFile.read(); //change to a valid number.
error=Sim800l.sendSms(number,text);
Serial.flush();
delay(5500);
}
}
Thanks Robin2. You hit the nail on the head. It only see's the first digit in the loop but it setup it displays the whole number. The question is now why and what am i doing wrong.
Ivanfd1:
The question is now why and what am i doing wrong.
The WHY is simple. myFile.read() just gets one charcter.
You need to collect all the characters that make up the number. Without knowing how you have the data in the file I can't give specific advice. Maybe there is a character that identifies the end of the number. Then you could do something like this
const byte maxChars = 16; // assumes no number will be more than 15 chars change if needed
char number[maxChars];
char endMaarker = '\n'; // set this to match your data
byte numCount;
for (numCount = 0; numCount < maxChars - 1) {
char nextChar = myFile.read();
if (nextChar != -1) { // nothing to read gives -1
if (nextChar == endMarker) {
break;
}
else {
number[numCount] = nextChar;
}
}
}
number[numCount] = '\0' // add the cstring terminator
Serial.println(number); // see what we got
(By the way, not tested so may contain silly errors)
Thank you Robin2, Im using the SDfat libary example Readwite, The example say write " Test,1,2,3", I complied the example then removed the sd card open it on the pc Opened, in notepad, edited to cell number "0123456789"[eg]. I have been searching the forums for a clue, found many trends that leads to dead ends. im going to try you example now, and post replay when finished,
Once thank you for assisting
Hi Robin2
changed after that get nothing
any advise
thanks
[code
#include <EEPROM.h>
#include <Sim800l.h>
#include <SoftwareSerial.h> //is necesary for the library!!
Sim800l Sim800l; //to declare the library
char* text;
char* number;
bool error; //to catch the response of sendSms
int addr = 0;
byte val;
#include <SPI.h>
#include <SD.h>
File myFile;
void setup() {
Sim800l.begin();
Serial.begin(9600);
if (!SD.begin(10)) {
// Serial.println("initialization failed!");
return;
}
myFile = SD.open("Test.TXT");
while (myFile.available()) {
// Serial.write(myFile.read());
}
const byte maxChars = 16; // assumes no number will be more than 15 chars change if needed
char number[maxChars];
char endMarker = '\n'; // set this to match your data
byte numCount;
for (numCount = 0; numCount < maxChars - 1;) {
char nextChar = myFile.read();
if (nextChar != -1) { // nothing to read gives -1
if (nextChar == endMarker) {
break;
}
else {
number[numCount] = nextChar;
}
}
}
number[numCount] = '\0'; // add the cstring terminator
Serial.println(number); // see what we got
}
void loop() {
}
]
Try this version. I have marked 2 lines with CHANGED. If you have while(myFile.available() ) but no code in the WHILE loop it will never terminate. If you use the WHILE to read the data in the file you will be at the end of the file before my code gets a look in.
Also note how I have tidied up the layout to make it much easier to see the different blocks of code. Use the AutoFormat tool.
#include <EEPROM.h>
#include <Sim800l.h>
#include <SoftwareSerial.h> //is necesary for the library!!
Sim800l Sim800l; //to declare the library
char* text;
char* number;
bool error; //to catch the response of sendSms
int addr = 0;
byte val;
#include <SPI.h>
#include <SD.h>
File myFile;
void setup() {
Sim800l.begin();
Serial.begin(9600);
if (!SD.begin(10)) {
// Serial.println("initialization failed!");
return;
}
myFile = SD.open("Test.TXT");
// while (myFile.available()) { // CHANGED
// Serial.write(myFile.read());
// } // CHANGED
const byte maxChars = 16; // assumes no number will be more than 15 chars change if needed
char number[maxChars];
char endMarker = '\n'; // set this to match your data
byte numCount;
for (numCount = 0; numCount < maxChars - 1;) {
char nextChar = myFile.read();
if (nextChar != -1) { // nothing to read gives -1
if (nextChar == endMarker) {
break;
}
else {
number[numCount] = nextChar;
}
}
}
number[numCount] = '\0'; // add the cstring terminator
Serial.println(number); // see what we got
}
void loop() {
}
Hi Robin2, Sorry for being a pain, This is what i got with my original code see attavment. now reviesed code i get nothing, i copied you code exactly into sketch book.
advice pleace
Thank you
Always post the latest version of your program - without that we are blind.
I just noticed that the program in your Original Post uses the SD Card library but the program in your Reply #8 uses the EEPROM library - why the change? The EEPROM library does not work like the SD Card library
This is just an unnecessary confusion when you are trying to sort out a problem.
Hi Robin2 The eeprom libary i add to see if i could write the number to eeprom and the use the "eeprom get " to get number to use as the number the gsm uses to send, but then reliased that what is on the monitor is not getting saved any way.
Hi Robin2, I have tried different ways to try and get your solution to work. May be it the way the number is writen in the file? But then what i dont understand is with original code the number displays on Serial monitor, With your solution i dont get any read out except a ? in Serial monotor. Any advise please
There is no point telling me that without also posting the latest versions of the programs that represent the different ways. I can't see your workbench from here.