Advertisement
microrobotics

Ai Thinker A9G GSM GPS Board

Mar 31st, 2023
3,526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.80 KB | None | 0 0
  1. /*
  2. The Ai Thinker A9G GSM/GPS board is a versatile module that can be programmed using C language and the Ai Thinker A9G SDK. This example demonstrates how to send an SMS using the A9G module. It assumes that you have the Ai Thinker A9G SDK installed and configured for your development environment.
  3.  
  4. In this example, the A9G module sends an SMS with the content "Hello from A9G!" to the specified phone number. The sms_callback function is called when the SMS sending is completed, and the result is printed to the debug UART.
  5.  
  6. Before you can compile and upload this code to your A9G module, you will need to configure your development environment and the Ai Thinker A9G SDK. Follow the instructions in the Ai Thinker A9G SDK documentation to set up your development environment and create a new project. Then, add the main.c file to your project and compile it.
  7.  
  8. After successfully compiling the code, upload the generated firmware to your Ai Thinker A9G module using a USB-to-Serial converter and the firmware upload tool provided by Ai Thinker. Consult the A9G module's documentation for the specific steps to upload the firmware to your module.
  9.  
  10. Once the firmware is uploaded, the A9G module will automatically run the code. Ensure that the SIM card is inserted and correctly configured with the appropriate APN settings. The module will then send an SMS to the specified phone number with the message "Hello from A9G!".
  11. */
  12.  
  13. #include "api.h"
  14. #include "api_sms.h"
  15. #include "api_hal_uart.h"
  16. #include "gps.h"
  17.  
  18. static void sms_callback(s32 result, u8 *buffer, u32 buf_len, void *userdata)
  19. {
  20.     Trace(1, "SMS send result:%d", result);
  21. }
  22.  
  23. void MainTask(void *pData)
  24. {
  25.     API_Event_t *event = NULL;
  26.  
  27.     // Initialize UART1 for debugging
  28.     UART_Config_t uartConfig = {
  29.         .baudrate = UART_BAUD_RATE_115200,
  30.         .dataBits = UART_DATA_BITS_8,
  31.         .stopBits = UART_STOP_BITS_1,
  32.         .parity = UART_PARITY_NONE,
  33.         .rxCallback = NULL,
  34.     };
  35.     UART_Init(UART1, uartConfig);
  36.  
  37.     // Wait for the A9G to register to the network
  38.     while (!INFO_GetSIMCardInfo(NULL))
  39.     {
  40.         OS_Sleep(1000);
  41.     }
  42.  
  43.     // Send SMS
  44.     u8 phone_number[] = "1234567890"; // Replace with your phone number
  45.     u8 sms_content[] = "Hello from A9G!";
  46.  
  47.     SMS_SendMessage(phone_number, sms_content, strlen(sms_content), sms_callback, NULL);
  48.  
  49.     while (1)
  50.     {
  51.         if (OS_WaitEvent(mainTaskHandle, (void **)&event, OS_TIME_OUT_WAIT_FOREVER))
  52.         {
  53.             EventDispatch(event);
  54.             OS_Free(event->pParam1);
  55.             OS_Free(event->pParam2);
  56.             OS_Free(event);
  57.         }
  58.     }
  59. }
  60.  
  61. void A9_main()
  62. {
  63.     mainTaskHandle = OS_CreateTask(MainTask,
  64.                                    NULL, NULL, MAIN_TASK_STACK_SIZE, MAIN_TASK_PRIORITY, 0, 0, MAIN_TASK_NAME);
  65.     OS_Run();
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement