Skicka SMS. 18F27K42 och 4GLTE2 click board

PIC, AVR, Arduino, Raspberry Pi, Basic Stamp, PLC mm.
Användarvisningsbild
newbadboy
Inlägg: 2478
Blev medlem: 16 september 2006, 19:16:28
Ort: Landskrona
Kontakt:

Skicka SMS. 18F27K42 och 4GLTE2 click board

Inlägg av newbadboy »

Har jobbat innan med SIM800 GSM modem och behöver nu gå över till 4G. Införskaffade en modul 4G LTE2 som baseras på Lara R6001 chippet. men det vet verkar mycket mer omständigt samt så lyckas jag inte hitta ngt enklare exempel som inte är för komplext att sätta sig in. :(

Kollat en massa på exempelkod från MikroE till just detta kort men jag kommer verkligen ingenvart. Behöver även migrera det till MPlab och inte det heller går bra kort sagt.
Funderar nästan på om man kan skriva egen drivare genom att försöka navigera runt i dessa datablad. Det verkar vara AT kommandon typ.

Har alltid igång i min design med UART etc. Det är alltså "bara" sms funktionen som saknas

Jag vill åstadkomma
1 Sätta upp modulen med allt det innebär
2 Sätta upp mottagarnr samt medelande text
2 Skicka ett sms

Finns det bra exempel som jag inte lyckats hitta? Eller to.m ngn här på EF som använt liknande modul?

MikroE LTE2 Click
https://www.mikroe.com/4g-lte-2-click-voice

MikroE LTE2 click schematic
https://download.mikroe.com/documents/a ... ematic.PDF

AT commands
https://download.mikroe.com/documents/d ... mmands.pdf

Datasheet
https://download.mikroe.com/documents/d ... asheet.pdf
Användarvisningsbild
Klas-Kenny
Inlägg: 11695
Blev medlem: 17 maj 2010, 19:06:14
Ort: Växjö/Alvesta

Re: Skicka SMS. 18F27K42 och 4GLTE2 click board

Inlägg av Klas-Kenny »

Detta exempel verkar ju relativt simpelt.
https://libstock.mikroe.com/projects/vi ... oice-click

Borde inte vara allt för mödosamt att porta till MPLAB.
Användarvisningsbild
newbadboy
Inlägg: 2478
Blev medlem: 16 september 2006, 19:16:28
Ort: Landskrona
Kontakt:

Re: Skicka SMS. 18F27K42 och 4GLTE2 click board

Inlägg av newbadboy »

Det är faktiskt den jag försökt gå genom 😥.

Beror säkert mest på mina kunskaper.
Användarvisningsbild
Klas-Kenny
Inlägg: 11695
Blev medlem: 17 maj 2010, 19:06:14
Ort: Växjö/Alvesta

Re: Skicka SMS. 18F27K42 och 4GLTE2 click board

Inlägg av Klas-Kenny »

Något specifikt som strular med det?

Börja med c4glte2voice.c, verkar i princip vara skrivning/läsning av in/utgångar plus UART som du behöver byta ut där. Och några delay-funktioner.
Användarvisningsbild
newbadboy
Inlägg: 2478
Blev medlem: 16 september 2006, 19:16:28
Ort: Landskrona
Kontakt:

Re: Skicka SMS. 18F27K42 och 4GLTE2 click board

Inlägg av newbadboy »

Ska ge det chans igen kanske jag kan lösa det med hjälp från EF.
Användarvisningsbild
newbadboy
Inlägg: 2478
Blev medlem: 16 september 2006, 19:16:28
Ort: Landskrona
Kontakt:

Re: Skicka SMS. 18F27K42 och 4GLTE2 click board

Inlägg av newbadboy »

Provade faktiskt en fuling då en kollega tipsat som jag skulle prova.

ChattGPT.

ställde frågan såhär

i want c code for initialsing module and sending sms with mikroE module 4G LTE 2 Click - voice which has LARA-R6001 from u-blox

fick svaret

To initialize the MikroE 4G LTE 2 Click module (which uses the LARA-R6001 module from u-blox) and send an SMS in C, you’ll need to interact with the module through AT commands via a UART or SPI interface, depending on how the module is connected to your system. Below is a general framework for how to write the code to initialize the module and send an SMS.

Key steps:

Initialize the UART or SPI interface (based on your hardware setup).
Send AT commands to the module to initialize it (e.g., setting up the module, checking network registration).
Send the AT command to send an SMS.
Below is an example of C code that could be used on an embedded system (like using an STM32, Arduino, or other microcontroller) to interact with the MikroE LTE module:

Kod: Markera allt

#include <stdio.h>
#include <string.h>
#include "uart.h"  // Assuming you have a UART driver library for your platform

// AT Command timeout in milliseconds
#define AT_COMMAND_TIMEOUT 2000

// Send AT command function
int sendATCommand(char *cmd, char *response, int timeout) {
    uart_write(cmd);  // Write the AT command to the module
    uart_write("\r\n");
    
    int bytesRead = uart_read(response, 256, timeout);  // Read the response from the module
    if (bytesRead > 0) {
        return 1;  // Success
    } else {
        return 0;  // Timeout or failure
    }
}

// Function to initialize the 4G LTE module
int init4GLTEModule() {
    char response[256];

    // Reset the module
    if (!sendATCommand("AT+CSQ", response, AT_COMMAND_TIMEOUT)) {
        printf("Error: No response from the module\n");
        return 0;
    }
    
    // Check the module version (optional, to verify communication)
    if (!sendATCommand("ATI", response, AT_COMMAND_TIMEOUT)) {
        printf("Error: Failed to get module information\n");
        return 0;
    }
    printf("Module Info: %s\n", response);
    
    // Set SMS mode to text mode
    if (!sendATCommand("AT+CMGF=1", response, AT_COMMAND_TIMEOUT)) {
        printf("Error: Failed to set SMS text mode\n");
        return 0;
    }
    
    // Check network registration
    if (!sendATCommand("AT+CREG?", response, AT_COMMAND_TIMEOUT)) {
        printf("Error: No network registration\n");
        return 0;
    }
    
    return 1;  // Module initialized successfully
}

// Function to send an SMS
int sendSMS(const char *phoneNumber, const char *message) {
    char command[256];
    char response[256];
    
    // AT command to send an SMS
    snprintf(command, sizeof(command), "AT+CMGS=\"%s\"", phoneNumber);
    
    // Send the AT command to the module
    if (!sendATCommand(command, response, AT_COMMAND_TIMEOUT)) {
        printf("Error: Failed to send SMS command\n");
        return 0;
    }

    // Send the message text
    uart_write(message);
    uart_write("\r\n");

    // Send the end of message (Ctrl+Z, 0x1A in ASCII)
    uart_write("\x1A");
    
    // Wait for the response from the module
    if (!sendATCommand("", response, AT_COMMAND_TIMEOUT)) {
        printf("Error: Failed to send SMS\n");
        return 0;
    }

    printf("SMS sent successfully\n");
    return 1;
}

int main() {
    // Initialize UART communication
    uart_init(9600);  // Assuming 9600 baud rate for the UART communication

    // Initialize the 4G LTE module
    if (!init4GLTEModule()) {
        printf("Error: LTE Module initialization failed\n");
        return -1;
    }
    
    // Send SMS
    const char *phoneNumber = "+1234567890";  // Replace with the recipient's phone number
    const char *message = "Hello from 4G LTE module!";
    if (!sendSMS(phoneNumber, message)) {
        printf("Error: SMS sending failed\n");
        return -1;
    }
    
    return 0;
}
Skriv svar