GSM PROGRAM COMPILE ERROR

Thread Starter

AJIN NADH

Joined Dec 18, 2014
84
Dear Team,

I TRY TO COMPILE THE FOLLOWING ARDUINO PROGRAM BUT ITS SHOWING ERROR( ATTACHED).

Code:
#include <EEPROM.h>// libraries
#include <GSM.h>
byte value;
// initialize the library instance
GSM gsmAccess; // include a 'true' parameter for debug enabled
GSM_SMS sms;
void setup()
{

  Serial.begin(9600);
  Serial.println("GSM initialized");
  pinMode(4,OUTPUT);
}

void loop()
{
  char k[20];
  char txtMsg[200];
  Serial.print("Enter a mobile number: ");
  char remoteNumber[20];  // telephone number to send sms
  for(int i=0;i<20;i++)
  {
  k[I]=readSerial(remoteNumber);
  Serial.println(remoteNumber);
  }
  for(int i=0;i<200;i++)
    {
    txtMsg[I]=sms.read();
    }
    numberfunction(k[20],txtMsg);
    sms.flush();
    Serial.println("MESSAGE DELETED");
  }


/*
  Read input serial
*/
int readSerial(char result[])
{
  int i = 0;
  while(1)
  {
    while (Serial.available() > 0)
    {
      char inChar = Serial.read();
      for(int i=0;i<20;i++)
      {
        result[I] = inChar;
        return(result[I]);
      }
    }
  }
}



void numberfunction(int Number ,char sms[200])
  {
    int address = 0;
    if(sms=="REG")
    {
       for (int i = 0; i < 512; i++)
    EEPROM.write(i, 0);
    value = EEPROM.read(Number);
    EEPROM.write(address,value);
  Serial.print(address);
  Serial.print("\t");
  Serial.print(value, DEC);
  Serial.println();
  address = address + 1;
  if (address == 512)
  address = 0;
  delay(500);
} 
else if(sms!="REG")
{
  if(value==Number)
  {
relay(sms);
} }
  }
  void relay(char sms[200])
{
if (sms=="ON")
{
  digitalWrite( 4, HIGH );
}
if(sms=="OFF")

{
  digitalWrite( 4, HIGH );
}
}
I WAS TRYING TO READ THE SENDER MOBILE NUMBER AND THE SMS CONTENT,
AND THESE VALUES ARE PASSED TO FUNCTION,PLS FIND THE ATTACHED ERROR


PLS HELP ME ......................................:(:(:(:(


Regards,
Ajin Nadh

Moderators note: Please use code tags for pieces of code
 

Attachments

Last edited by a moderator:

Motanache

Joined Mar 2, 2015
481
<<I WAS TRYING TO READ THE SENDER MOBILE NUMBER AND THE SMS CONTENT,>>

That's not hard.

Good to monitor a serial line from phone to microcontroller.

In Hyperterminal you tried to practice AT commands?

Decoding PDU will be more difficult, but there are online applications that make it.
 

djsfantasi

Joined Apr 11, 2010
5,956
A few errors I found.

  • You define the function "readserial" as an int, but try to assign it to a char variable. It won't like that.
  • What does sms.read return? It appears to return an int and you try to assign it to a char array
  • You also are trying to assign a char to a char pointer (in the line "result = inChar;")
Interestingly, I did not receive any errors specific to the GSM library. However, the ones I noted could confuse the libraries.

Overall, you are confused with the various data types, and attempt to assign incompatible variables/functions.

These are the errors I received when compiling your program:
Code:
Arduino: 1.5.6-r2 (Windows 7), Board: "Arduino Uno"

sketch_mar07a.ino: In function 'void loop()':
sketch_mar07a:24: error: incompatible types in assignment of 'int' to 'char [20]'
sketch_mar07a:29: error: incompatible types in assignment of 'int' to 'char [200]'
sketch_mar07a.ino: In function 'int readSerial(char*)':
sketch_mar07a:50: error: invalid conversion from 'char' to 'char*'
sketch_mar07a:51: error: invalid conversion from 'char*' to 'int'

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
By the way, your attachment was so small as to be nearly unreadable. Normally, we complain about attachments being too big, but we should be able to read what you post.
 

Thread Starter

AJIN NADH

Joined Dec 18, 2014
84
Hi,

I rewrite the program as like, Can anybody check that it will work properly,

Code:
#include <EEPROM.h>

#include <SoftwareSerial.h>

#include <OneWire.h>

#include <DallasTemperature.h>

#include <Wire.h>

const int exterior_light = 6;

int button = A0;

char inchar;

char message[160];

int val = 0;

int  param;

char *tel_nr = "\" +0123456789 \"";


SoftwareSerial SIM900(2, 3);


#define ONE_WIRE_BUS A2


OneWire oneWire(ONE_WIRE_BUS);


DallasTemperature sensors(&oneWire);


void setup()

{

pinMode(exterior_light, OUTPUT);

digitalWrite(exterior_light,LOW);

SIM900.begin(19200);


delay(3000); 

SIM900.print("AT+CMGF=1\r");

delay(100);

SIM900.print("AT+CNMI=2,2,0,0,0\r");

delay(1000);

}


void sendSMS(char *message, char *number)

{


SIM900.print("AT+CMGF=1\r\n");

delay(100);

SIM900.print("AT + CMGS =");

SIM900.println(number);

delay(100);

SIM900.println(message);  // messageul care trebuie trimis, direct cu terminatorul dupa el

delay(100);

SIM900.println((char)0x1A);  // CTRL+Z

delay(100);

SIM900.println();

delay(5000); 

if(message!="REG")

{

int addr = 0;

int value = EEPROM.read(addr);

if(value==*number)

{

if (message=="ON")

{

digitalWrite( 4, HIGH );

}

if(message=="OFF")


{

digitalWrite( 4, LOW );



}

}}

else if(message=="REG")

{

for (int i = 0; i < 512; i++)

{

EEPROM.write(i, 0);

}

int addr = 0;

EEPROM.write(addr, int (number));

int value = EEPROM.read(addr);

addr = addr + 1;

if (addr == 512)

addr = 0;

delay(100);

}



}

void loop()

{

unsigned int wADC;

double t;



ADMUX = (_BV(REFS1) | _BV(REFS0) | _BV(MUX3));

ADCSRA |= _BV(ADEN);


delay(50);


ADCSRA |= _BV(ADSC);


while (bit_is_set(ADCSRA,ADSC));


wADC = ADCW;



t = (wADC - 324.31 ) / 1.22;

delay(500);

char command[255] = {0};

while (SIM900.available() > 0)

{

char ch = SIM900.read();

sprintf(command, "%s%c", command, ch);

sendSMS(message, tel_nr);

}

}
Regards,
Ajin nadh

Moderators note: Please use code tags for pieces of code
 
Last edited by a moderator:
Top