0

Greetings dear reader!

I have some trouble storing my IMEI code inside a variable. It always returns an error: "void value not ignored as it ought to be".

Since then I tried to write it to the serial line by just running the gsm.SimpleWriteln("AT+GSN"); AT command, but I am stuck at storing this displayed value inside a variable. Does anyone here know a way to store a serial value into a variable? I just want to send the IMEI code as an identifier to the cloud application...

Thanks in advance, your response is really appreciated.

The code:

#include "SIM900.h"
#include <SoftwareSerial.h>
//#include "inetGSM.h"
//#include "sms.h"
//#include "call.h"

//To change pins for Software Serial, use the two lines in GSM.cpp.

//GSM Shield for Arduino
//www.open-electronics.org
//this code is based on the example of Arduino Labs.

//Simple sketch to communicate with SIM900 through AT commands.

//InetGSM inet;
//CallGSM call;
//SMSGSM sms;

int numdata;
char inSerial[40];
int i=0;
boolean startUp = false;

void setup() {
  Serial.begin(9600);
  Serial.println("GSM Shield testing.");

  //Start configuration of shield with baudrate.
  //For http uses it is recommended to use 4800 or slower.
  if (gsm.begin(9600)) {
    Serial.println("\nstatus=READY");
    getIMEI();
  } else Serial.println("\nstatus=IDLE");
};

void loop() {
  //Read for new byte on serial hardware,
  //and write them on NewSoftSerial.
  serialhwread();
  //Read for new byte on NewSoftSerial.
  serialswread();
};

void serialhwread() {
  i=0;
  if (Serial.available() > 0) {
    while (Serial.available() > 0) {
      inSerial[i]=(Serial.read());
      delay(10);
      i++;
    }
    inSerial[i]='\0';
    if(!strcmp(inSerial,"/END")) {
      Serial.println("_");
      inSerial[0]=0x1a;
      inSerial[1]='\0';
      gsm.SimpleWriteln(inSerial);
    }
    //Send a saved AT command using serial port.
    if(!strcmp(inSerial,"TEST")) {
      Serial.println("SIGNAL QUALITY");
      gsm.SimpleWriteln("AT+CSQ");
    } else {
      Serial.println(inSerial);
      gsm.SimpleWriteln(inSerial);
    }
    inSerial[0]='\0';
  }
}

void serialswread() {
  gsm.SimpleRead();
}

void getIMEI() {
  long IMEI = gsm.SimpleWriteln("AT+GSN"); // IMEI code
  Serial.println(IMEI);
  return IMEI
}
3
  • Can you maybe share your code?
    – Majenko
    Commented Jan 17, 2016 at 17:22
  • Ofcourse but it is not complete yet, because I dont have a clue on what to do next;P Commented Jan 17, 2016 at 19:32
  • 1
    gsm does not name a type, probably because you did not create an gsm object. Something like: CallGSM gsm; should be at the top of your sketch (not in comment).
    – aaa
    Commented Feb 17, 2016 at 7:01

1 Answer 1

1

The SimpleWriteln() function just sends an instruction. It doesn't return anything. Once you have sent the instruction to retrieve the IMEI you then have to actually read the IMEI.

However, fortunately, there is a function that does it for you:

char imei[20];
gsm.getIMEI(imei);

The IMEI should now be in the C string imei. What you do with it then is up to you.

5
  • Many thanks man!, but i still get an error. Namely: " 'gsm' does not name a type :\ i looked through all the documentation and couldnt find in the GSM.h library any function that contains .getIMEI() any other advice on tackeling this problem? thanks apreciate the support;) Commented Jan 21, 2016 at 17:04
  • Well, you're using gsm.* throughout your program - but it looks like you didn't bother to define it (or it's defined by the library but you have the wrong library?)
    – Majenko
    Commented Jan 21, 2016 at 18:40
  • Yeah I think it is a library related problem to, because if I read the GSM library I don't see any word that contains the GSM.GetIMEI(). But I need this GSM library... so I can't easily swap them out. Do you have any advice on this? On how to make them both compatible within the same file? I'm really grateful that you help me with this, because I was really losing hope with this project;) Commented Jan 22, 2016 at 19:33
  • I was looking at the library linked to by the product page. Are you trying to use a different one? The other commands you use are in the library I was looking at...
    – Majenko
    Commented Jan 22, 2016 at 19:34
  • I'm using the one they specified, maybe I have an old version I will try to update it, and try to work with the one they currently have on there site;) I will come back on this topic thanks! Commented Jan 22, 2016 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.