MaJerle/lwcell
About
A lightweight host AT library for cellular modems.
Developer ToolsWhat you can do
- Written in C (C11), compatible with stdint.h data types
- Supports SIM800/SIM900 (2G) and SIM7070G (NB-IoT LTE) modules
- Provided examples for ARM Cortex-M or Win32 platforms
- Allows different configurations to optimize user requirements
Measured star growth
- in 24h
- +1
- in 7 days
- +1
- in 15 days
- +1
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
OriginalLwCELL — Lightweight cellular modem AT parser for embedded systems
LwCELL is a lightweight, platform independent library that adds cellular connectivity to any microcontroller by talking to a modem over UART using AT commands. It currently targets SIMCOM modules: SIM800/SIM900 (2G) and SIM7070G (NB-IoT LTE). Written in C11, it gives the host a clean API for SMS, voice calls, phonebook, USSD, TCP/UDP connections and MQTT. Its main targets are embedded devices like ARM Cortex-M, AVR and PIC, but it works under Windows, Linux and macOS too.
📖 Documentation · Changelog · Releases
Features
- Written in C (C11), compatible with
stdint.hdata types - Supports
SIM800/SIM900 (2G)andSIM7070G (NB-IoT LTE)modules - Platform independent and very easy to port
- Provided examples for ARM Cortex-M or Win32 platforms
- Allows different configurations to optimize user requirements
- Supports operating-system implementations with advanced inter-thread communication
- Currently only OS mode is supported
- 2 different threads handling user data and received data
- First (producer) thread (collects user commands from user threads and starts the command processing)
- Second (process) thread reads the data from GSM device and does the job accordingly
- Allows sequential API for connections in client mode
- Full SMS API to send, read, delete and list messages
- Voice call API to start, answer and hang up calls
- Phonebook API to add, edit, delete, read, list and search entries
- Supports USSD code execution
- Includes several applications built on top of the library:
- MQTT client for MQTT connection
- User friendly MIT license
Quick start
#include <stdio.h>
#include "lwcell/lwcell.h"
#include "lwcell/lwcell_network_api.h"
/* Global event callback */
static lwcellr_t
prv_lwcell_evt(lwcell_evt_t* evt) {
switch (lwcell_evt_get_type(evt)) {
case LWCELL_EVT_SMS_RECV: printf("New SMS received\r\n"); break;
default: break;
}
return lwcellOK;
}
/* Application thread */
void
app_thread(void const* arg) {
(void)arg;
/* Initialize library, blocking mode */
lwcell_init(prv_lwcell_evt, 1);
lwcell_sim_pin_enter("1234", NULL, NULL, 1); /* Only if the SIM card is PIN protected */
/* Send SMS */
lwcell_sms_enable(NULL, NULL, 1);
lwcell_sms_send("+0123456789", "Hello from LwCELL", NULL, NULL, 1);
/* Attach to the network for data connections */
lwcell_network_set_credentials("internet", "", ""); /* Your operator's APN */
if (lwcell_network_request_attach() == lwcellOK) {
/* Use the netconn API or MQTT client */
}
}
SMS and network functions require LWCELL_CFG_SMS, LWCELL_CFG_NETWORK and LWCELL_CFG_CONN to be enabled in the configuration.
Complete examples for Win32 and STM32 are in examples, with shared application code in snippets.
Porting
LwCELL needs two platform-specific parts:
- Low-level driver: sends AT commands to the modem and passes received data to the library, typically over UART with DMA
- System functions: threads, mutexes, semaphores and message queues of your operating system
Ready-made implementations are in lwcell/src/system: low-level drivers for STM32, ESP32 and Win32, and system ports for CMSIS-OS, FreeRTOS, ThreadX and Win32. See the documentation for details.
Configuration
Enabled modules (SMS, calls, phonebook, network, netconn, MQTT, ...), buffer sizes and timeouts are configured in the lwcell_opts.h file.
Copy lwcell/src/include/lwcell/lwcell_opts_template.h to your project, rename it to lwcell_opts.h,
and override the defaults listed in lwcell_opt.h.
See Getting started in the documentation for details.
Add to your project
CMake
set(LWCELL_OPTS_FILE ${CMAKE_CURRENT_LIST_DIR}/lwcell_opts.h) # Optional, default options are used otherwise
set(LWCELL_SYS_PORT "cmsis_os") # One of: cmsis_os, freeRTOS, threadx, win32
add_subdirectory(path/to/lwcell/lwcell)
target_link_libraries(${PROJECT_NAME} PRIVATE lwcell lwcell_api lwcell_apps)
lwcell_api adds the netconn and network API, and lwcell_apps adds the applications (MQTT client). Both can be left out if not needed.
Add a low-level driver from lwcell/src/system/, or your own, to your project sources.
Optional compiler options and definitions can be set with LWCELL_COMPILE_OPTIONS and LWCELL_COMPILE_DEFINITIONS, see lwcell/library.cmake.
Any other build system
- Copy the
lwcellfolder to your project - Add
lwcell/src/includeand the system port folderlwcell/src/include/system/port/<port>to the include path - Add the source files from
lwcell/src/lwcell/to the build, and optionallylwcell/src/api/andlwcell/src/apps/ - Add a low-level driver and a system port from
lwcell/src/system/, or write your own - Create
lwcell_opts.hin a folder on the include path (see Configuration)
Contribute
Fresh contributions are always welcome. Simple instructions to proceed:
- Fork Github repository
- Follow C style & coding rules and use
clang-formatto format the code - Create a pull request to
developbranch with new features or bug fixes
Alternatively you may:
- Report a bug
- Ask for a feature request
License
LwCELL is released under the MIT license.
Explore related projects
Loading…