B4R Question GSM MODULE PROBLEM

tango

Active Member
Licensed User
Longtime User
hi friendsl ,
there is a ino code and itis working.
but another code writen by B4R and it is not working.
please say me what problem...

------------------------------------------------
*/

// pin definition
#define PWRKEY 4
#define EMERG 5
#define GSM_ON 6


String GSM_string = "\r\n\n\nTest Protocol: GSM-easy!\r\n------------------------\r\n";

//----------------------------------------------------------------------------------------------------------------------------------------------------
void setup()
{
Serial.begin(9600); // 9600 Baud data rate
Serial.print("\r\nStart Test Sequence: GSM-easy!\r\n(Please wait ... appr.45s)\r\n------------------------------\r\n");
}

//----------------------------------------------------------------------------------------------------------------------------------------------------
void loop()
{
//---------------------------------------------------------------------------------------------------------------
// let's power up the shield
// ATTENTION: you MUST set your own SIM pin!

digitalWrite(GSM_ON, HIGH); // GSM_ON = HIGH --> switch on + Serial Line enable

// Init sequence, see "M95_HardwareDesign_V1.2.pdf", page 30ff.
// in any case: force a reset!
digitalWrite(PWRKEY, LOW); // PWRKEY = HIGH
digitalWrite(EMERG, HIGH); // EMERG_OFF = LOW
delay(50); // wait for 50ms
digitalWrite(PWRKEY, LOW); // PWRKEY = HIGH
digitalWrite(EMERG, LOW); // EMERG_OFF = HIGH
delay(2100); // wait for 2100ms
digitalWrite(PWRKEY, HIGH); // PWRKEY = LOW
delay(1100); // wait for 1100ms
digitalWrite(PWRKEY, LOW); // PWRKEY = HIGH
// Start and Autobauding sequence ("M95_AT_Commands_V1.0.pdf", page 35)
delay(3000); // wait for 3000ms

//---------------------------------------------------------------------------------------------------------------
// let's register in the GSM network with the correct SIM pin!
// ATTENTION: you MUST set your own SIM pin!
GSM_string += "Send the first AT:\r\n";
Serial.print("AT\r"); // send the first "AT" for fixing autobauding
WaitAndRead(1000); // wait for 10 seconds

GSM_string += "Set Manufacturers defaults:\r\n";
Serial.print("AT&F0\r"); // Manufacturers defaults
WaitAndRead(100); // wait for 1 second
//---------------------------------------------------------------------------------------------------------------
// let's register in the GSM network with the correct SIM pin!
// ATTENTION: you MUST set your own SIM pin! "1357" is an example only!

GSM_string += "Query SIM status:\r\n";
Serial.print("AT+CPIN?\r"); // query SIM status
WaitAndRead(100); // wait for 1 second

GSM_string += "Enter SIM pin:\r\n";
Serial.print("AT+CPIN=1357\r"); // enter pin (SIM)
WaitAndRead(100); // wait for 1 second
delay(20000); // wait 20s. of registration in the GSM network
//---------------------------------------------------------------------------------------------------------------
// ok, the ME should be registered in the GSM network ... now let's find out all the info and stati of the module

GSM_string += "Query register state of GSM network (20 seconds later!):\r\n";
Serial.print("AT+CREG?\r"); // Query register state of GSM network
WaitAndRead(100); // wait for 1 second

GSM_string += "Query register state of GPRS network:\r\n";
Serial.print("AT+CGREG?\r"); // Query register state of GPRS network
WaitAndRead(100); // wait for 1 second

GSM_string += "Query the IMEI:\r\n";
Serial.print("AT+GSN\r"); // Query the IMEI
WaitAndRead(100); // wait for 1 second

GSM_string += "Query the RF signal strength:\r\n";
Serial.print("AT+CSQ\r"); // Query the RF signal strength
WaitAndRead(100); // wait for 1 second

GSM_string += "Query the current selected operator:\r\n";
Serial.print("AT+COPS?\r"); // Query the current selected operator
WaitAndRead(100); // wait for 1 second

//---------------------------------------------------------------------------------------------------------------
// power-off the ME to avoid any error messages, caused of the Serial.print commands for the monitor

digitalWrite(GSM_ON, LOW); // GSM_ON = LOW --> switch off + Serial Line disable
Serial.print(GSM_string);
Serial.println("--- E N D ---");

while(1);
}

//----------------------------------------------------------------------------------------------------------------------------------------------------
// read function for the serial line
// Parameter: timeout in steps of 10ms
void WaitAndRead(int timeout)
{
for (int i = 0; i < timeout; i++)
{
delay(10);
while (Serial.available() > 0)
{
char inChar = Serial.read();
GSM_string += inChar;
}
}

GSM_string += "----------\r\n";
}
//--------------------------------------------- B4R CODES-------------------------------------------------------------------------------------------------------
#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Private timer1 As Timer
Public Serial1 As Serial
Private PWRKEY As Pin
Private EMERG As Pin
Private GSM_ON As Pin
Private serial As SoftwareSerial
Private bc As ByteConverter
Private astream As AsyncStreams
Private EOL() As Byte = Array As Byte(13)
Private busy As Boolean
Private messageToSend(160) As Byte
Private SMSSlot(4) As Byte
Private retryEmptyMessages As Byte
End Sub

Private Sub AppStart
Serial1.Initialize(19200)
Log("AppStart")
PWRKEY.Initialize(4, PWRKEY.MODE_OUTPUT)
EMERG.Initialize(5, EMERG.MODE_OUTPUT)
GSM_ON.Initialize(6, GSM_ON.MODE_OUTPUT)
serial.Initialize(9600, 0, 1)
astream.Initialize(serial.Stream, "astream_NewData", Null)

GSM_ON.digitalWrite(False)
PWRKEY.digitalWrite(False)
EMERG.digitalWrite(False)

Delay(10000)

GSM_ON.digitalWrite(False)

PWRKEY.digitalWrite(True)
EMERG.digitalWrite(False)
Log("x")
Delay(5000)
Log("y")
PWRKEY.digitalWrite(True)
EMERG.digitalWrite(True)
Delay(21000)
PWRKEY.digitalWrite(False)
Delay(11000)
PWRKEY.digitalWrite(True)

Delay(30000)
timer1.Initialize("timer1_Tick",20000)


End Sub
Sub AStream_NewData (Buffer() As Byte)
Log("-----------------------")
Log(bc.StringFromBytes(Buffer))
timer1.Enabled=True
End Sub
Private Sub timer1_Tick
Log("----timer---")
astream.Write("AT").Write(EOL)
timer1.Enabled=False
End Sub
 

Cableguy

Expert
Licensed User
Longtime User
Please, please, please use the code tags or insert code function of the forum!
Your post is near to unreadable!

To my best recall, B4R still doesn't have a gsm lib!
 
Upvote 0

tango

Active Member
Licensed User
Longtime User
this .ino file is work correctly .
but b4r not work .
where is my problem?
 

Attachments

  • gsm_easy__test.zip
    2.7 KB · Views: 355
  • B4Rgsm.zip
    972 bytes · Views: 379
Upvote 0
Top