<?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[M5Stick-&gt;SIM7080-&gt; MQTT-&gt;Thingspeak--&gt;Sample code]]></title><description><![CDATA[<p dir="auto">Dear all,<br />
Please let me share with you my sample code. Needs cleaning up, but it could be a good example for those that are interested in using the SIM7080 module.</p>
<p dir="auto">#include &lt;M5StickC.h&gt;<br />
#include "AXP192.h"<br />
#include "DHT12.h"<br />
#include &lt;Wire.h&gt;<br />
#include "Adafruit_Sensor.h"<br />
#include &lt;Adafruit_BMP280.h&gt;  // Dit is de pressure sensor. <a href="https://cdn-shop.adafruit.com/datasheets/BST-BMP280-DS001-11.pdf" target="_blank" rel="noopener noreferrer nofollow ugc">https://cdn-shop.adafruit.com/datasheets/BST-BMP280-DS001-11.pdf</a><br />
//#include "bmm150.h"<br />
//#include "bmm150_defs.h"<br />
//#include "M5_SIM7080G.h"</p>
<p dir="auto">DHT12 dht12;<br />
//BMM150 bmm = BMM150();<br />
//bmm150_mag_data value_offset;<br />
Adafruit_BMP280 bme;</p>
<p dir="auto">float tmp      = 0.0;<br />
float hum      = 0.0;<br />
float pressure = 0.0;<br />
float BatVoltage;</p>
<p dir="auto">String ClientId="<strong><strong>";<br />
String Username="</strong></strong>";<br />
String Password="****";<br />
String  ChannelId="*****";</p>
<p dir="auto">const int buffer_size=5000;<br />
char Receive_buffer[buffer_size];<br />
long time_taken;</p>
<p dir="auto">char date_time_char_array[50];<br />
char date_time_char_array_processed[50];<br />
const char allowed_char[]="0123456789/,:+-";</p>
<p dir="auto">typedef struct  {<br />
int Second;<br />
int Minute;<br />
int Hour;<br />
int Day;<br />
int Month;<br />
int Year;   // offset from 1970;<br />
int Timezone;<br />
}   Date_time_struct;</p>
<p dir="auto">Date_time_struct Thisday;<br />
bool DateTime_Error=false;<br />
char buf[10];</p>
<p dir="auto">uint8_t setup_flag = 1;</p>
<p dir="auto">const long SIMWaitTime=10000;<br />
const long Delay_between_commands=300;</p>
<p dir="auto">int RSSI;</p>
<p dir="auto">char* Pntr;<br />
char* Pntr_1;<br />
char* Pntr_2;</p>
<p dir="auto">char IP_buffer[20];       // hier komt het toegewezen IP adress in</p>
<p dir="auto">char itoa_buffer[10];<br />
#define max_float_digits 20  //7  // including NULL    let op, in retrieve data gebruik ik precision 4 ipv 2<br />
#define dtostrf_precision 4<br />
#define dtostrf_leader 15</p>
<p dir="auto">String Date_payload; //="&amp;created_at=2023-05-11 09:20:59";</p>
<p dir="auto">#define uS_TO_S_FACTOR 1000000  /* Conversion factor for micro seconds to seconds */</p>
<p dir="auto">bool Wakeup_Other_Cause;<br />
bool Wakeup_Through_Button;<br />
bool Wakeup_Through_Time;<br />
int Sleep_Period=10;</p>
<p dir="auto">int Sleep_Period_After_Error=10;</p>
<p dir="auto">int Error_Code;</p>
<p dir="auto">//#define BMM150_CHIP_ID_ADDR 0x76</p>
<p dir="auto">void setup() {<br />
// put your setup code here, to run once:<br />
M5.begin(false,true,true);<br />
Serial.begin(115200);<br />
delay(300);</p>
<p dir="auto">M5.Axp.SetLDO2(false);<br />
M5.Axp.SetLDO3(false);</p>
<p dir="auto">Wire.end();<br />
//delay(300);<br />
Wire.begin(0,26);<br />
Serial.println();<br />
Serial.println();<br />
Serial.println();<br />
Serial.println();</p>
<p dir="auto">print_wakeup_reason();</p>
<p dir="auto">esp_sleep_wakeup_cause_t wakeup_reason;<br />
wakeup_reason = esp_sleep_get_wakeup_cause();<br />
Wakeup_Other_Cause=false;<br />
Wakeup_Through_Button=false;<br />
Wakeup_Through_Time=false;</p>
<pre><code> switch(wakeup_reason)
   {
     case ESP_SLEEP_WAKEUP_EXT0 :  Wakeup_Through_Button=true;break;
     case ESP_SLEEP_WAKEUP_EXT1 :  break;  // nu toch de server
     case ESP_SLEEP_WAKEUP_TIMER : Wakeup_Through_Time=true;break;
     case ESP_SLEEP_WAKEUP_TOUCHPAD : break;
     case ESP_SLEEP_WAKEUP_ULP :break;
     default : Wakeup_Other_Cause=true; break;
</code></pre>
<p dir="auto">}</p>
<p dir="auto"><a href="//M5.Lcd.setRotation" target="_blank" rel="noopener noreferrer nofollow ugc">//M5.Lcd.setRotation</a>(3);<br />
<a href="//M5.Lcd.fillScreen" target="_blank" rel="noopener noreferrer nofollow ugc">//M5.Lcd.fillScreen</a>(BLACK);<br />
<a href="//M5.Lcd.setCursor" target="_blank" rel="noopener noreferrer nofollow ugc">//M5.Lcd.setCursor</a>(0, 0, 2);<br />
<a href="//M5.Lcd.println" target="_blank" rel="noopener noreferrer nofollow ugc">//M5.Lcd.println</a>("ENV TEST");<br />
//pinMode(M5_BUTTON_HOME, INPUT);</p>
<p dir="auto">Serial.println("Init doing");<br />
/*<br />
if(bmm.initialize() == BMM150_E_ID_NOT_CONFORM) {<br />
Serial.println("Chip ID can not read!");<br />
while(1);<br />
} else {<br />
Serial.println("Initialize done!");<br />
}<br />
*/</p>
<p dir="auto">if (!bme.begin(0x76)){<br />
Serial.println("Could not find a valid BMP280 sensor, check wiring!");<br />
while (1);<br />
}</p>
<p dir="auto">tmp = dht12.readTemperature();<br />
hum = dht12.readHumidity();<br />
pressure = bme.readPressure();<br />
BatVoltage=M5.Axp.GetBatVoltage();</p>
<p dir="auto">Serial.println(tmp);<br />
Serial.println(hum);<br />
Serial.println(pressure);<br />
Serial.println(BatVoltage);</p>
<p dir="auto">//while (1) {delay(300);}</p>
<p dir="auto">Serial2.begin(115200, SERIAL_8N1,33,32);   // M5 Stick Port B</p>
<p dir="auto">Serial2.print("AT+IPR=115200\r");        //<br />
Read_Response_WaitFor("OK",SIMWaitTime);<br />
delay(Delay_between_commands);</p>
<p dir="auto">Serial2.print("AT+CREBOOT\r");        //<br />
Read_Response_WaitFor("OK",30000);<br />
delay(Delay_between_commands);<br />
//Read_Response_OK(3000);<br />
Serial.println(Receive_buffer);</p>
<p dir="auto">Serial2.print("ATZ\r");        // Request TA Serial Number Identification(IMEI)<br />
Read_Response_WaitFor("OK",SIMWaitTime);<br />
delay(Delay_between_commands);<br />
//Read_Response_OK(3000);<br />
Serial.println(Receive_buffer);</p>
<p dir="auto">Serial2.print("AT+GSN\r");        // Request TA Serial Number Identification(IMEI)<br />
Read_Response_WaitFor("OK",SIMWaitTime);<br />
delay(Delay_between_commands);<br />
//Read_Response_OK(3000);<br />
Serial.println(Receive_buffer);</p>
<p dir="auto">int max_trials=5;<br />
Error_Code=0;</p>
<p dir="auto">while (1) {</p>
<p dir="auto"><a href="//Serial.print" target="_blank" rel="noopener noreferrer nofollow ugc">//Serial.print</a>("*********************************        Trail : ");<br />
<a href="//Serial.println" target="_blank" rel="noopener noreferrer nofollow ugc">//Serial.println</a>(max_trials);</p>
<p dir="auto">//**************************************************               READ SMS</p>
<p dir="auto">/*<br />
Signal Strength	General Results<br />
-50 to -79 dBm	Considered great signal (4 to 5 bars)<br />
-80 to -89 dBm	Considered good signal (3 to 4 bars)<br />
-90 to -99 dBm	Considered average signal (2 to 3 bars)<br />
-100 to -109 dBm	Considered poor signal (1 to 2 bars)<br />
-110 to -120 dBm	Considered very poor signal (0 to 1 bar)</p>
<p dir="auto">*/</p>
<p dir="auto">Serial2.print("AT+CSQ\r");  // Clock returns *PSUTTZ: 23/04/14,11:56:48","+08",1 time zone in quarters of an hour<br />
Read_Response(2000); //Read_Response_WaitFor("OK",SIMWaitTime);<br />
//Read_Response_OK(2000);<br />
Serial.println(Receive_buffer);</p>
<p dir="auto">RSSI=0;<br />
Pntr=strstr(Receive_buffer,"+CSQ:");<br />
if (Pntr!=NULL)<br />
{<br />
Pntr_1=strtok(Pntr,":,");<br />
if (Pntr_1!=NULL);<br />
{<br />
Pntr_1=strtok(NULL,":,");<br />
if (Pntr_1!=NULL)<br />
{<br />
<a href="//Serial.println" target="_blank" rel="noopener noreferrer nofollow ugc">//Serial.println</a>(Pntr_1);<br />
RSSI=atoi(Pntr_1);<br />
switch (RSSI) {<br />
case 0: RSSI=-115;break;<br />
case 1: RSSI=-111;break;<br />
case 99 : RSSI=99;break;<br />
default : RSSI=-112+RSSI;break;</p>
<pre><code>             }

          }
    }

}
</code></pre>
<p dir="auto">Serial.print("Rssi : ");<br />
Serial.println(RSSI);</p>
<p dir="auto">if (RSSI==0 or RSSI==99)<br />
{<br />
Serial.println();<br />
Serial.println();<br />
Serial.println("*********************************************     NO SIGNAL");<br />
Serial.println("*********************************************     Going to sleep");<br />
Serial.println();<br />
Serial.println();<br />
Error_Code=1;<br />
break;</p>
<pre><code>   //esp_sleep_enable_timer_wakeup(60 * uS_TO_S_FACTOR);
   //esp_deep_sleep_start();
}
</code></pre>
<p dir="auto">Serial2.print("AT+CLTS=1\r");        // Get local timestamp<br />
Read_Response_WaitFor("OK",SIMWaitTime);<br />
<a href="//Serial.println" target="_blank" rel="noopener noreferrer nofollow ugc">//Serial.println</a>(Receive_buffer);<br />
delay(Delay_between_commands);</p>
<p dir="auto">Serial2.print("AT+CCLK?\r");<br />
Read_Response_WaitFor("OK",SIMWaitTime);<br />
<a href="//Serial.println" target="_blank" rel="noopener noreferrer nofollow ugc">//Serial.println</a>(Receive_buffer);<br />
delay(Delay_between_commands);</p>
<p dir="auto">if (Process_DateandTime(false)) {Error_Code=4;}</p>
<p dir="auto">//AT+CSSLCFG="SSLVERSIO N",&lt;ctxindex&gt;,&lt;sslversion&gt;</p>
<p dir="auto">Serial2.print("AT+CSSLCFG="SSLVERSION",0,3\r");<br />
Read_Response_WaitFor("OK",SIMWaitTime);<br />
Serial.println(Receive_buffer);<br />
delay(Delay_between_commands);</p>
<p dir="auto">Serial2.print("AT+CNACT=0,1\r");<br />
Read_Response_WaitFor("OK",SIMWaitTime);<br />
Serial.println(Receive_buffer);<br />
delay(Delay_between_commands);</p>
<p dir="auto">Serial2.print("AT+CNACT?\r");<br />
Read_Response_WaitFor("OK",SIMWaitTime);<br />
Serial.println(Receive_buffer);<br />
delay(Delay_between_commands);</p>
<pre><code>if (!GET_IP_Address ()) 
   {
      Serial.println("No IP address");
      Serial.println("Program stalled");
      Error_Code=2;
      break;
      //while (1) {delay(300);}
  }
</code></pre>
<p dir="auto">Serial2.print("AT+SMCONF="URL","<a href="http://mqtt3.thingspeak.com" target="_blank" rel="noopener noreferrer nofollow ugc">mqtt3.thingspeak.com</a>","1883"\r");<br />
Read_Response_WaitFor("OK",SIMWaitTime);<br />
Serial.println(Receive_buffer);<br />
delay(Delay_between_commands);</p>
<p dir="auto">Serial2.print("AT+SMCONF="KEEPTIME",60\r");<br />
Read_Response_WaitFor("OK",SIMWaitTime);<br />
Serial.println(Receive_buffer);<br />
delay(Delay_between_commands);</p>
<p dir="auto">Serial2.print("AT+SMCONF="CLEANSS",1\r");<br />
Read_Response_WaitFor("OK",SIMWaitTime);<br />
Serial.println(Receive_buffer);<br />
delay(Delay_between_commands);</p>
<p dir="auto">Serial2.print("AT+SMCONF="QOS",0\r");<br />
Read_Response_WaitFor("OK",SIMWaitTime);<br />
Serial.println(Receive_buffer);<br />
delay(Delay_between_commands);</p>
<p dir="auto">Serial2.print("AT+SMCONF="TOPIC","My Topic"\r");<br />
Read_Response_WaitFor("OK",SIMWaitTime);<br />
Serial.println(Receive_buffer);<br />
delay(Delay_between_commands);</p>
<p dir="auto">Serial2.print("AT+SMCONF="MESSAGE","My Message"\r");<br />
Read_Response_WaitFor("OK",SIMWaitTime);<br />
Serial.println(Receive_buffer);<br />
delay(Delay_between_commands);</p>
<p dir="auto">Serial2.print("AT+SMCONF="RETAIN",0\r");<br />
Read_Response_WaitFor("OK",SIMWaitTime);<br />
Serial.println(Receive_buffer);<br />
delay(Delay_between_commands);</p>
<p dir="auto">Serial2.print("AT+SMCONF="SUBHEX",0\r");<br />
Read_Response_WaitFor("OK",SIMWaitTime);<br />
Serial.println(Receive_buffer);<br />
delay(Delay_between_commands);</p>
<p dir="auto">Serial.println("AT+SMCONF="CLIENTID",""+ClientId+""\r");<br />
Serial2.print("AT+SMCONF="CLIENTID",""+ClientId+""\r");</p>
<p dir="auto">Read_Response_WaitFor("OK",SIMWaitTime);<br />
Serial.println(Receive_buffer);<br />
delay(Delay_between_commands);</p>
<p dir="auto">Serial.println("AT+SMCONF="USERNAME",""+Username+""\r");<br />
Serial2.print("AT+SMCONF="USERNAME",""+Username+""\r");<br />
Read_Response_WaitFor("OK",SIMWaitTime);<br />
Serial.println(Receive_buffer);<br />
delay(Delay_between_commands);</p>
<p dir="auto">Serial.println("AT+SMCONF="PASSWORD",""+ Password+ ""\r");<br />
Serial2.print("AT+SMCONF="PASSWORD",""+ Password+ ""\r");<br />
Read_Response_WaitFor("OK",SIMWaitTime);<br />
Serial.println(Receive_buffer);<br />
delay(Delay_between_commands);</p>
<p dir="auto">Serial2.print("AT+SMCONN\r");<br />
Read_Response_WaitFor("OK",SIMWaitTime);<br />
Serial.println(Receive_buffer);<br />
delay(Delay_between_commands);</p>
<p dir="auto">if(strstr(Receive_buffer,"ERROR") != NULL)<br />
{<br />
Serial.println("SMCONN ERROR " );<br />
Error_Code=3;<br />
break;<br />
}<br />
else<br />
{<br />
Serial.println("We have a MQTT connection");<br />
// Format<br />
// <a href="https://nl.mathworks.com/help/thingspeak/publishtoachannelfeed.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://nl.mathworks.com/help/thingspeak/publishtoachannelfeed.html</a><br />
// created_at=2014-12-31 23:59:59</p>
<p dir="auto">/*<br />
In the Payload pane, use the following settings:</p>
<p dir="auto">Topic: channels/33301/publish<br />
Payload: field1=45&amp;field2=60&amp;status=MQTTPUBLISH<br />
This PUBLISH message publishes a value of 45 to field1 and 60 to field2 of channel 33301, along with a status message MQTTPUBLISH.</p>
<p dir="auto">lengte van de payload nog<br />
*/<br />
//String Date_payload="&amp;created_at=2023-05-11 09:20:59";<br />
String payload;</p>
<pre><code>        payload="field1="+String(int(pressure))+"&amp;field2="+String(int(tmp))+"&amp;field3="+String(int(hum))+"&amp;field4="+String(int(BatVoltage*100))+Date_payload;
        String Mqtt_Message;

        int Payload_Length;
        Payload_Length=payload.length();
        Serial.print(payload);
        Serial.print ("   ");
        Serial.println(Payload_Length);
        //Mqtt_Message="AT+SMPUB=\"channels/888617/publish\","+String(Payload_Length)+",1,1\r";

        Mqtt_Message="AT+SMPUB=\"channels/"+ ChannelId+"/publish\","+String(Payload_Length)+",1,1\r";
        Serial.println(Mqtt_Message);
        Serial2.print(Mqtt_Message);
        //Serial2.print("AT+SMPUB=\"channels/888617/publish/fields/field1\",1,1,1\r");   // lengte moet goed zijn      
        Read_Response_WaitFor("OK",SIMWaitTime);
        Serial.println(Receive_buffer);
        delay(Delay_between_commands); 
        String Str;
        //pressure=12;
        Serial.println(pressure);
        Str=String(int(pressure/100))+"\r";
        Serial.println(Str);
        //Serial2.print("9\r");
        Serial2.print(payload);
        //Serial2.print(Str);        
        Read_Response_WaitFor("OK",SIMWaitTime);
        Serial.println(Receive_buffer);
        delay(Delay_between_commands); 
        break;
    }
</code></pre>
<p dir="auto">} //end while</p>
<p dir="auto">Serial.print("Done with error code : ");<br />
Serial.println(Error_Code);</p>
<p dir="auto">if (Error_Code==0)<br />
{<br />
esp_sleep_enable_timer_wakeup(Sleep_Period * uS_TO_S_FACTOR);<br />
esp_deep_sleep_start();<br />
}<br />
else<br />
{<br />
esp_sleep_enable_timer_wakeup(Sleep_Period_After_Error * uS_TO_S_FACTOR);<br />
esp_deep_sleep_start();<br />
}</p>
<p dir="auto">while (1) {delay(300);}</p>
<p dir="auto">} // end of setup</p>
<p dir="auto">void loop()<br />
{</p>
<p dir="auto">}</p>
<p dir="auto">bool Read_Response(long time_out) {<br />
int k=0;<br />
long wait_until;<br />
char ccc;<br />
//while (!Serial2.available() and millis()&lt;wait_until) {delay(10);}<br />
wait_until=millis()+time_out;<br />
while (millis()&lt;wait_until)<br />
{<br />
while (Serial2.available())<br />
{<br />
ccc=Serial2.read();<br />
<a href="//Serial.print" target="_blank" rel="noopener noreferrer nofollow ugc">//Serial.print</a>(ccc);<br />
if (k&lt;buffer_size-1)<br />
{<br />
Receive_buffer[k]=ccc;<br />
k++;<br />
}<br />
}<br />
Receive_buffer[k]=NULL;<br />
//if (strstr(Receive_buffer,"OK")!=NULL)<br />
// {<br />
<a href="//Serial.println" target="_blank" rel="noopener noreferrer nofollow ugc">//Serial.println</a>("OK found");<br />
//  SIM7600_Error=0;<br />
//break;<br />
//}<br />
}<br />
//if (k&gt;=buffer_size-1) {SIM7600_Error=1; strcpy(Receive_buffer,SIM7600_Error_list[SIM7600_Error].c_str());return;}<br />
//if (millis()&gt;=wait_until) {SIM7600_Error=2;  strcpy(Receive_buffer,SIM7600_Error_list[SIM7600_Error].c_str()); return;}<br />
Receive_buffer[k]=NULL;<br />
if (strstr(Receive_buffer,"ERROR")!=NULL) {return true;} else {return false;}<br />
}</p>
<p dir="auto">bool Read_Response_WaitFor(char* StopCharArray,long time_out) { // false als niet gevonden<br />
int k=0;<br />
long wait_until;<br />
char ccc;<br />
//while (!Serial2.available() and millis()&lt;wait_until) {delay(10);}<br />
time_taken=millis();<br />
wait_until=time_taken+time_out;<br />
while (millis()&lt;wait_until)<br />
{<br />
while (Serial2.available())<br />
{<br />
ccc=Serial2.read();<br />
<a href="//Serial.print" target="_blank" rel="noopener noreferrer nofollow ugc">//Serial.print</a>(ccc);<br />
if (k&lt;buffer_size-1)<br />
{<br />
Receive_buffer[k]=ccc;<br />
k++;<br />
}<br />
}<br />
Receive_buffer[k]=NULL;<br />
if (strstr(Receive_buffer,StopCharArray)!=NULL)<br />
{<br />
<a href="//Serial.println" target="_blank" rel="noopener noreferrer nofollow ugc">//Serial.println</a>("OK found");<br />
//  SIM7600_Error=0;<br />
Receive_buffer[k]=NULL;<br />
return false;<br />
}<br />
}<br />
//if (k&gt;=buffer_size-1) {SIM7600_Error=1; strcpy(Receive_buffer,SIM7600_Error_list[SIM7600_Error].c_str());return;}<br />
//if (millis()&gt;=wait_until) {SIM7600_Error=2;  strcpy(Receive_buffer,SIM7600_Error_list[SIM7600_Error].c_str()); return;}<br />
Receive_buffer[k]=NULL;<br />
time_taken=millis()-time_taken;<br />
Serial.println();<br />
Serial.print("1] This operation took ");<br />
Serial.print(time_taken);<br />
Serial.println(" millisec");<br />
return true;  //if (strstr(Receive_buffer,"ERROR")!=NULL) {return true;} else {return false;}<br />
}</p>
<p dir="auto">void clear_Receive_buffer(){<br />
for (int i=0;i&lt;buffer_size;i++) {Receive_buffer[i]=NULL;}<br />
}</p>
<p dir="auto">bool Process_DateandTime(bool PSUTZ) {<br />
char *Process_ptr;<br />
bool Date_Error;<br />
Date_Error=false;</p>
<p dir="auto">//Process_ptr=strstr(Receive_buffer,"CCLK:");<br />
if (PSUTZ)  {Process_ptr=strstr(Receive_buffer,"PSUTTZ:");}<br />
else        {Process_ptr=strstr(Receive_buffer,"CCLK:");}</p>
<p dir="auto">if (Process_ptr!=NULL)<br />
{</p>
<pre><code>   //strcpy(date_time_char_array,"PSUTTZ: 23/04/14,11:56:48\",\"+08\",1");
   //strcat(date_time_char_array,"\0");
  //Serial.println(date_time_char_array);
   Serial.println(Process_ptr);
   strcpy(date_time_char_array,Process_ptr);

  Serial.println(date_time_char_array);

 int k=0;
 for (int i=0; i&lt;strlen(date_time_char_array); i++)
   {
      if (strchr(allowed_char,date_time_char_array[i])!=NULL)
       {
         date_time_char_array_processed[k]=date_time_char_array[i];
         k++;
       }
   }



  Serial.println(date_time_char_array_processed); 



  Process_ptr=date_time_char_array_processed+1;
  Serial.println(Process_ptr);
   while (1)
     {
       Process_ptr=strtok(Process_ptr,"/,:");     // 23/04/14,11:56:48,+08,1
       if (Process_ptr==NULL) {DateTime_Error=true;break;}
       Thisday.Year=atoi(Process_ptr);

        Process_ptr=strtok(NULL,"/,:");     // 23/04/14,11:56:48,+08,1
        if (Process_ptr==NULL) {DateTime_Error=true;break;}
        Thisday.Month=atoi(Process_ptr);

        Process_ptr=strtok(NULL,"/,:");     // 23/04/14,11:56:48,+08,1
         if (Process_ptr==NULL) {DateTime_Error=true;break;}
          Thisday.Day=atoi(Process_ptr);


        Process_ptr=strtok(NULL,"/,:");     // 23/04/14,11:56:48,+08,1
         if (Process_ptr==NULL) {DateTime_Error=true;break;}
         Thisday.Hour=atoi(Process_ptr);

         Process_ptr=strtok(NULL,"/,:");     // 23/04/14,11:56:48,+08,1
         if (Process_ptr==NULL) {DateTime_Error=true;break;}
         Thisday.Minute=atoi(Process_ptr);

         Process_ptr=strtok(NULL,"/,:");     // 23/04/14,11:56:48,+08,1
        if (Process_ptr==NULL) {DateTime_Error=true;break;}
        Thisday.Second=atoi(Process_ptr);

         Process_ptr=strtok(NULL,"/,:");     // 23/04/14,11:56:48,+08,1
          if (Process_ptr==NULL) {DateTime_Error=true;break;}
          Thisday.Timezone=atoi(Process_ptr);
          Thisday.Hour=Thisday.Hour+(Thisday.Timezone/4);


         break;

       }


 
       //Append_this_Struct.Photo_Taken=SetDateTime(Thisday.Hour,Thisday.Minute,Thisday.Second, Thisday.Day,Thisday.Month,(Thisday.Year+30));    // CurrentYear (2023-1970) == 55 yea 23 plus 32 dus
       //print_time_t(Append_this_Struct.Photo_Taken);
       Serial.println();
       Serial.print(Thisday.Year);
       Serial.print("/");
       Serial.print( Thisday.Month);
       Serial.print("/");
       Serial.print( Thisday.Day);
       Serial.print(",");
       Serial.print(Thisday.Hour);
       Serial.print(":");
       Serial.print( Thisday.Minute);
       Serial.print(":");
       Serial.print( Thisday.Second);
       Serial.print(",");
       Serial.println( Thisday.Timezone);

       

       Date_payload="&amp;created_at=20"+String(Thisday.Year)+"-"+Int_to_2_Digits(Thisday.Month)+"-"+Int_to_2_Digits(Thisday.Day)+" "+Int_to_2_Digits(Thisday.Hour)+":"+Int_to_2_Digits(Thisday.Minute)+":"+Int_to_2_Digits(Thisday.Second);
       Serial.println(Date_payload);
          //Serial.println("Done with it");
         //while (1) {delay(300);}

       if (Thisday.Year&lt;23)   {Date_Error=true; }
       if (Thisday.Month&lt;0 or Thisday.Month&gt;12 )   {Date_Error=true; }
       if (Thisday.Day&lt;0 or Thisday.Month&gt;31 )   {Date_Error=true; }
       if (Thisday.Hour&lt;0 or Thisday.Hour&gt;12 )   {Date_Error=true; }
       if (Thisday.Minute&lt;0 or Thisday.Minute&gt;60 )   {Date_Error=true; }
       if (Thisday.Second&lt;0 or Thisday.Second&gt;60 )   {Date_Error=true; }
}
</code></pre>
<p dir="auto">else<br />
{<br />
//strcpy(fnameJPG,"AA00000001012011.JPG");<br />
Date_Error=true;<br />
}</p>
<p dir="auto">return Date_Error;<br />
}</p>
<p dir="auto">String Int_to_2_Digits(int this_int){</p>
<p dir="auto">if (this_int&lt;10)<br />
{return("0"+String(this_int));}<br />
else<br />
{return(String(this_int));}</p>
<p dir="auto">}</p>
<p dir="auto">bool GET_IP_Address () {</p>
<p dir="auto">char *p0;<br />
char *p1;<br />
int span;<br />
<a href="//Serial.println" target="_blank" rel="noopener noreferrer nofollow ugc">//Serial.println</a>("GET_IP_Address");</p>
<pre><code>    //strcpy(Receive_buffer,"CHOPEN: 0,\"aap.noot.mies\"");
    //strcpy(Receive_buffer,"CHOPEN: 0,\"\"");
     p0=strstr(Receive_buffer,"CNACT: ");
     if (p0!=NULL)
       {
         p0=p0+strlen("CNACT: ");
         p1=strstr(p0,"\n");
         if (p1!=NULL)
           {
             span=min(19,p1-p0);
             strncpy(IP_buffer, p0, span);
             IP_buffer[span]='\0';
             Serial.print("IP_buffer : ");
             Serial.println(IP_buffer);
             Serial.print(" : ");
             Serial.println(strlen(IP_buffer));
             if (strlen(IP_buffer) &gt;8) {return true;} else {return false;}
           }
         else
          { 
            return (false);
            Serial.println("No IP address");
          }
       }
     else
       {
         return (false);
         //$Serial.println("No IP address");
       }
</code></pre>
<p dir="auto">}</p>
<p dir="auto">void print_wakeup_reason(){<br />
esp_sleep_wakeup_cause_t wakeup_reason;</p>
<p dir="auto">wakeup_reason = esp_sleep_get_wakeup_cause();</p>
<p dir="auto">switch(wakeup_reason)<br />
{<br />
case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;<br />
case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;<br />
case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break;<br />
case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break;<br />
case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break;<br />
default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break;<br />
}<br />
}</p>
]]></description><link>https://community.m5stack.com/topic/5287/m5stick-sim7080-mqtt-thingspeak-sample-code</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Apr 2026 22:14:14 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/5287.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 11 May 2023 10:38:47 GMT</pubDate><ttl>60</ttl></channel></rss>