Error code -8 (ADL_RET_ERR_BAD_STATE) is returned by adl_smsSend API in the following cases.
• When the initialization of the Wireless CPU is not complete
• When another SMS is being sent at that time.
For the first case, it’s recommended to execute this API in application only after WIND:4 is received.
In case the application has subscribed for the SIM event then it should be sent after event “SIM state of 3” (Full initialization complete).
For the second case (which seems to be the one faced by you), you need to be sure that there is no SMS being sent at the same time. If you are planaing to send several SMS in a short time, it’s recommended to use AT+CMMS command.
The behaviour could also occur because when an SMS is being sent another command should not be sent from the external application. This case could be prevented after implementing the following steps :
After “adl_smsSend ()” API is called, block all AT commands by doing a CMD Subscribe. This can be done using the following statement:
“adl_atCmdSubscribe ( “AT”, AT_Cmd_Handler, ADL_CMD_TYPE_ACT | ADL_CMD_TYPE_ROOT)”.
If any AT command is received, in the “adl_atCmdSubscribe ()” API callback handler, return “+CME ERROR: 515”. This informs the external application that the Open AT® Library is busy processing a command
After “ADL_SMS_EVENT_SENDING_OK” or “ADL_SMS_EVENT_SENDING_ERROR” event is received in the callback handler, perform “adl_atCmdUnSubscribe()” to unblock AT command from the external application.
This procedure prevents the error -8 (ADL_RET_ERR_BAD_STATE). It must also be noted that no command should be created (using adl_atCmdCreate () API) until the Wireless CPU has received an event pertaining to the SMS which is being sent. In other words, between steps 1 and 3, no command should be created using adl_atCmdCreate () API. This API should be used only after you receive an ADL_SMS_EVENT_SENDING_OK” or “ADL_SMS_EVENT_SENDING_ERROR” event in the callback handler.
Hope it helps