Offline
Newbie
Karma: 0
Posts: 28
|
 |
« on: February 22, 2013, 07:51:34 pm » |
this is my code #include <SoftwareSerial.h>
/* GSM Send Sketch for Arduino Initializes GSM Module and sends an SMS to recipient The circuit: *Arduino pin 0 (RX) - GSM Module (TX) *Arduino pin 1 (TX) - GSM Module (RX) SoftwareSerial RFID(10,11); char Rx_data[50]; unsigned char Rx_index = 0; int i = 0; char msg[160]; int sig; char number; void setup() { Serial.begin(38400); Serial1.begin(9600); RFID.begin(9600); initGSM(); send_msg(number, msg); }
void loop() { if(Serial1.available()){ char c=Serial1.read(); if(c==65){ number=Serial1.read();} else{} } } void send_msg(char *number, char *msg) { char at_cmgs_cmd[30] = {'\0'}; char msg1[160] = {'\0'}; char ctl_z = 0x1A;
sprintf(msg1, "%s%c", msg, ctl_z); sprintf(at_cmgs_cmd, "AT+CMGS=\"%s\"\r\n",number); sendGSM(at_cmgs_cmd); delay(100); delay(100); delay(100); sendGSM(msg1); delay(100); }
void sendGSM(char *string){ Serial.write(string); delay(90); }
void clearString(char *strArray) { int j; for (j = 100; j > 0; j--) strArray[j] = 0x00; }
void send_cmd(char *at_cmd, char clr){ char *stat = '\0'; while(!stat){ sendGSM(at_cmd); delay(90); readSerialString(Rx_data); stat = strstr(Rx_data, "OK"); } if (clr){ clearString(Rx_data); delay(200); stat = '\0'; } }
void initGSM(){ send_cmd("AT\r\n",1); // send_cmd("ATE0\r\n",1); // Turn off automatic echo of the GSM Module send_cmd("AT+CMGF=1\r\n",1); // Set message format to text mode //Sucess Serial.println("Success"); delay(1000); delay(1000); delay(1000); }
void readSerialString (char *strArray) { if(!Serial.available()) { return; } while(Serial.available()) { strArray[i] = Serial.read(); i++; } }
here's my error final.ino: In function 'void setup()': final:30: error: invalid conversion from 'char' to 'char*' final:30: error: initializing argument 1 of 'void send_msg(char*, char*)'
|
|
|
|
« Last Edit: February 22, 2013, 07:54:18 pm by Coding Badly »
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 6
Posts: 400
|
 |
« Reply #1 on: February 22, 2013, 08:17:24 pm » |
I'm not sure what you intend to do there neither of those variables has anything in them at that point.
But either way, number is declared as a char. The function expects a pointer to a char. An & in front of number will clear the error but probably won't work like you expect since the function is using it as a string. It would need a trailing NULL to work there.
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35566
Seattle, WA USA
|
 |
« Reply #2 on: February 22, 2013, 08:40:08 pm » |
but probably won't work like you expect since the function is using it as a string. No, it won't. number needs to be a string (an array). And, as Delta_G alluded to, both number and msg need to have values assigned. Sending an empty message to an undefined number is a waste of effort (and you will be charged).
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #3 on: February 23, 2013, 12:42:17 am » |
void loop() { if(Serial1.available()){ char c=Serial1.read(); if(c==65){ number=Serial1.read();} else{} } }
What is the "else" for? What is 65? You know you have one character available, but are reading two. Why?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 28
|
 |
« Reply #4 on: February 23, 2013, 01:22:29 am » |
here is the original code that i want to modify i want to change the number to a variable depending to the receive data from the pc as well as the message("hello") this code it is working ,what i need to do? char Rx_data[50]; unsigned char Rx_index = 0; int i = 0; char msg[160]; int sig;
void setup() { Serial.begin(38400); initGSM(); send_msg("09295791692", "Hello"); }
void loop() { //none }
void send_msg(char *number, char *msg) { char at_cmgs_cmd[30] = {'\0'}; char msg1[160] = {'\0'}; char ctl_z = 0x1A;
sprintf(msg1, "%s%c", msg, ctl_z); sprintf(at_cmgs_cmd, "AT+CMGS=\"%s\"\r\n",number); sendGSM(at_cmgs_cmd); delay(100); delay(100); delay(100); sendGSM(msg1); delay(100); }
void sendGSM(char *string){ Serial.write(string); delay(90); }
void clearString(char *strArray) { int j; for (j = 100; j > 0; j--) strArray[j] = 0x00; }
void send_cmd(char *at_cmd, char clr){ char *stat = '\0'; while(!stat){ sendGSM(at_cmd); delay(90); readSerialString(Rx_data); stat = strstr(Rx_data, "OK"); } if (clr){ clearString(Rx_data); delay(200); stat = '\0'; } }
void initGSM(){ send_cmd("AT\r\n",1); // send_cmd("ATE0\r\n",1); // Turn off automatic echo of the GSM Module send_cmd("AT+CMGF=1\r\n",1); // Set message format to text mode //Sucess Serial.println("Success"); delay(1000); delay(1000); delay(1000); }
void readSerialString (char *strArray) { if(!Serial.available()) { return; } while(Serial.available()) { strArray[i] = Serial.read(); i++; } }
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #5 on: February 23, 2013, 01:44:18 am » |
char *stat = '\0'; while(!stat){ ...
This is incredibly obscure. I suggest a rewrite.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 28
|
 |
« Reply #6 on: February 23, 2013, 01:57:09 am » |
IS IT possible?
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35566
Seattle, WA USA
|
 |
« Reply #7 on: February 23, 2013, 08:29:05 am » |
IS IT possible? Certainly. What is IT, though?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 28
|
 |
« Reply #8 on: February 24, 2013, 09:50:14 pm » |
is it possible to change the number to a variable depending to the receive data...
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35566
Seattle, WA USA
|
 |
« Reply #9 on: February 25, 2013, 04:12:27 am » |
is it possible to change the number to a variable depending to the receive data... This is like pulling teeth. Change what number to what variable? Almost anything is possible if you know what you are trying to do.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #10 on: February 25, 2013, 04:29:26 am » |
IS IT possible?
http://en.wikipedia.org/wiki/Knights_who_say_NiThe Knights happen to have a weakness in that a number of words, when spoken to them, has the same effect on them as their saying "Ni" has on others. The only one of these words that is revealed in the film is the word "it", which is picked up on when Arthur, upon being asked to cut down the mightiest tree in the forest with a herring, declares that "it can't be done." Ultimately, King Arthur and Sir Robin (who shows up with his own knights) both say "it" several times in conversation (unaware that "it" was the word that was causing the Knights' pain). However earlier in the very same scene the head Knight himself uses the word ("It is a good shrubbery.") suggesting that it only causes the knights pain when said by someone else.
|
|
|
|
|
Logged
|
|
|
|
|
|