0

I'am trying to apply USSD operation with variable codes, for example this piece of code return my account balance:

             gsm.SimpleWriteln("AT+CUSD=1,\"*100#\""); 

i want to change "*100#" to variable so gsm.SimpleWrite uses what the variable contains. I want to find how to make it work like this:

             gsm.SimpleWriteln("AT+CUSD=1,\"Variable\"");

EDIT: here is my code to give you a better view. it return balance in serial monitor.

#include "SIM900.h"



  void setup() 
    {
   Serial.begin(9600);
    Serial.println("GSM Shield testing.");
       if (gsm.begin(9600))
            Serial.println("\nstatus=READY");
      else Serial.println("\nstatus=IDLE");

         gsm.SimpleWriteln("AT+CUSD=1,\"*100#\"");
      delay(10000);
             char msg[200];
             gsm.read(msg, 200);
            Serial.print("resp: ");
            Serial.println(msg);
 }
    void loop()
     {

    }
Med. A.
  • 5
  • 2

1 Answers1

0

I cannot find which "SIM900.h" library you are using - none of the ones I found have "SimpleWriteln" in them, so this is pure assumption about what functions and overloads may be available.

Just split your string into chunks, like you would with any serial device:

gsm.SimpleWrite("AT+CUSD=1,\"");
gsm.SimpleWrite(command);
gsm.SimpleWriteln("\"");

Where command is a suitable container for your data - say const char *.

Majenko
  • 103,876
  • 5
  • 75
  • 133
  • check the post i added the code, and i tried what u said, it returns error. Sim900.h lib located at: Arduino\libraries\SIM908IDE100. i think its with th default libs. – Med. A. Feb 16 '17 at 12:14
  • You must have installed that library. That means you must have downloaded it from somewhere. That means you must surely know where you downloaded it from. Unless you can tell us that we can't help you further. – Majenko Feb 16 '17 at 12:20
  • I think I have found a copy online, though I can't be sure. It looks like the library hasn't been well written - it doesn't support the F() macro (which is kind of stupid really). I shall remove those from my code example. – Majenko Feb 16 '17 at 12:22
  • any other suggestions to make a USSD operation? – Med. A. Feb 16 '17 at 12:33
  • Does my example not do what you want? – Majenko Feb 16 '17 at 12:53
  • it returns Error. which means wrong syntax in AT manuel – Med. A. Feb 16 '17 at 13:00
  • Did you mistakenly use SimpleWriteln instead of SimpleWrite ? – Majenko Feb 16 '17 at 13:01
  • it worked! thank you. i just define command as char* , like this. char *command – Med. A. Feb 16 '17 at 13:32