<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[SMS Using M5Core + U137 SIM7080G CAT-M&#x2F;NB-IoT+GNSS Unit]]></title><description><![CDATA[<p dir="auto">Hi All,<br />
I am able to send and receive SMS messages with the named hardware but have an issue. The message obtained by device in receivedmsg contains my phone number, date and time and then the actual message. I cannot figure out an easy way to just get the actual message so I can use in IF statement. The code is listed below. Works great but need to parse out the message only. Other code for other controllers I have do not work with this hardware.<br />
This is what is in receivedMsg --&gt; +myphonenumber",,"25/04/23,15:09:25-28"<br />
Relay1on</p>
<p dir="auto">Any ideas?</p>
<p dir="auto">#include &lt;iostream&gt;<br />
#include &lt;sstream&gt;<br />
#include &lt;string&gt;<br />
#include "M5Stack.h"<br />
#include "M5GFX.h"<br />
#include "M5_SIM7080G.h"</p>
<p dir="auto">M5GFX display;<br />
M5Canvas canvas(&amp;display);</p>
<p dir="auto">M5_SIM7080G device;</p>
<p dir="auto">void log(String str) {<br />
Serial.println(str);<br />
canvas.fillSprite(TFT_BLACK); // Clear the canvas<br />
canvas.setCursor(0, 0);       // Reset cursor<br />
canvas.print(str);            // Print the new message<br />
canvas.pushSprite(0, 0);      // Push updated sprite to the display<br />
}</p>
<p dir="auto">void setup()<br />
{<br />
M5.begin();<br />
display.begin();</p>
<pre><code>if (display.isEPD())
{
    display.setEpdMode(epd_mode_t::epd_fastest);
    display.invertDisplay(true);
    display.clear(TFT_BLACK);
}
if (display.width() &lt; display.height())
{
    display.setRotation(display.getRotation() ^ 1);
}

canvas.setColorDepth(1);
canvas.createSprite(display.width(), display.height());
canvas.setTextSize((float)canvas.width() / 160);
canvas.setTextScroll(false);

/* Init SIM7080G */
device.Init(&amp;Serial2, 16, 17);

/* Reboot SIM7080G */
log("Rebooting SIM7080G...");
while (device.send_and_getMsg("AT+CREBOOT\r\n").indexOf("OK") == -1) {
    delay(1000);
}
log("Reboot successful!");

/* Set SMS text mode */
log("Setting SMS text mode...");
while (device.send_and_getMsg("AT+CMGF=1\r\n").indexOf("OK") == -1) {
    delay(1000);
}
log("SMS mode ready.");
</code></pre>
<p dir="auto">}</p>
<p dir="auto">void loop()<br />
{<br />
log("Checking for messages");</p>
<pre><code>String smsList = device.send_and_getMsg("AT+CMGL=\"REC UNREAD\"\r\n"); // Fetch unread SMS
if (smsList.indexOf("+CMGL") != -1) {
    int msgStart = smsList.indexOf("\",\"");
    int msgEnd = smsList.lastIndexOf("\r\n");
    if (msgStart != -1 &amp;&amp; msgEnd != -1) {
        String receivedMsg = smsList.substring(msgStart + 3, msgEnd); // Extract message content
        log(receivedMsg); // Display the received message
        delay(10000);
</code></pre>
<p dir="auto">/*<br />
if (receivedMsg.equals("desiredMessage")) {<br />
// Do something specific<br />
System.out.println("Action triggered for 'desiredMessage'");<br />
}<br />
*/</p>
<pre><code>        /* Respond to the received SMS */
        String recipient = "+myphonenumbe";
        String response = "Acknowledged: " + receivedMsg;
        log("Sending response...");
        device.send_and_getMsg("AT+CMGS=\"" + recipient + "\"\r"); // Set recipient
        delay(100); // Wait for the prompt
        device.send_and_getMsg(response + "\x1A"); // Send response (Ctrl+Z to finalize)
        log("Response sent!");
    }

    /* Delete the processed message */
    device.send_and_getMsg("AT+CMGD=1,4\r\n"); // Delete all messages to avoid duplicates
}

delay(1000); // Short delay between operations
</code></pre>
<p dir="auto">}</p>
]]></description><link>https://community.m5stack.com/topic/7517/sms-using-m5core-u137-sim7080g-cat-m-nb-iot-gnss-unit</link><generator>RSS for Node</generator><lastBuildDate>Mon, 04 May 2026 17:15:30 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/7517.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 23 Apr 2025 22:14:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to SMS Using M5Core + U137 SIM7080G CAT-M&#x2F;NB-IoT+GNSS Unit on Thu, 24 Apr 2025 16:37:24 GMT]]></title><description><![CDATA[<p dir="auto">That was painful but figured it out.<br />
Must be better ways but this works where lastWord will be the exact SMS message sent.</p>
<p dir="auto">log(receivedMsg); // Display the received message</p>
<pre><code>  receivedMsg.trim(); // Remove any trailing or leading whitespace, including newlines

  // Find the last newline character or any other delimiter expected)
  int lastNewlineIndex = receivedMsg.lastIndexOf('"');

  // Extract the substring after the last newline character
  String lastWord = receivedMsg.substring(lastNewlineIndex + 1);

  lastWord.replace("\n", "");
  lastWord.replace("OK", "");
  lastWord.replace("\r", ""); // Removes all carriage return characters
</code></pre>
]]></description><link>https://community.m5stack.com/post/28961</link><guid isPermaLink="true">https://community.m5stack.com/post/28961</guid><dc:creator><![CDATA[lenswerks]]></dc:creator><pubDate>Thu, 24 Apr 2025 16:37:24 GMT</pubDate></item><item><title><![CDATA[Reply to SMS Using M5Core + U137 SIM7080G CAT-M&#x2F;NB-IoT+GNSS Unit on Thu, 24 Apr 2025 11:03:57 GMT]]></title><description><![CDATA[<p dir="auto">The string when sending Relay1on is<br />
+myphonenumber",,"25/04/23,15:09:25-28"<br />
Relay1on</p>
<p dir="auto">Note that Relay1on is on next line.</p>
<p dir="auto">I want to stack a 4RELAY module and be able to control it with SMS messages.<br />
Thanks.</p>
]]></description><link>https://community.m5stack.com/post/28957</link><guid isPermaLink="true">https://community.m5stack.com/post/28957</guid><dc:creator><![CDATA[lenswerks]]></dc:creator><pubDate>Thu, 24 Apr 2025 11:03:57 GMT</pubDate></item><item><title><![CDATA[Reply to SMS Using M5Core + U137 SIM7080G CAT-M&#x2F;NB-IoT+GNSS Unit on Thu, 24 Apr 2025 08:35:08 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/lenswerks" aria-label="Profile: lenswerks">@<bdi>lenswerks</bdi></a> what is exact string you getting in receivedMsg?</p>
<p dir="auto">you could split string to sub messages based on (") or (,)</p>
]]></description><link>https://community.m5stack.com/post/28953</link><guid isPermaLink="true">https://community.m5stack.com/post/28953</guid><dc:creator><![CDATA[robski]]></dc:creator><pubDate>Thu, 24 Apr 2025 08:35:08 GMT</pubDate></item></channel></rss>