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()
     {

    }
  • What kind of variable? And what library has the SimpleWriteln method? – Majenko Feb 16 '17 at 11:20
  • im using SIM900.h. for example var1 = *100# and var2 = *122# i want to applied it like that. – Med. A. Feb 16 '17 at 11:27
  • gsm.SimpleWriteln is different from serial.print in many ways, including syntax. – Med. A. Feb 16 '17 at 13:03
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 *.

|improve this answer|||||
  • 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

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