Pages: [1]   Go Down
Author Topic: got error  (Read 543 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

this is my code

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
Code:
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 Offline
God Member
*****
Karma: 10
Posts: 646
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Brattain Member
*****
Karma: 547
Posts: 45982
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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 Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 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?
Code:

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
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Code:
  char *stat = '\0';
  while(!stat){
  ...

This is incredibly obscure. I suggest a rewrite.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

IS IT possible?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45982
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
IS IT possible?
Certainly.

What is IT, though?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

is it possible to change the number to a variable depending to the receive data...
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45982
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

IS IT possible?

http://en.wikipedia.org/wiki/Knights_who_say_Ni

Quote
The 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

Pages: [1]   Go Up
Jump to: