<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>GSM &#8211; About Things | A Hans Scharler Blog</title>
	<atom:link href="https://nothans.com/tag/gsm/feed" rel="self" type="application/rss+xml" />
	<link>https://nothans.com</link>
	<description>Life, Comedy, Games, Tech, Marketing, and Community</description>
	<lastBuildDate>Mon, 09 Jan 2023 14:36:45 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://i0.wp.com/nothans.com/wp-content/uploads/2023/02/cropped-settings.png?fit=32%2C32&#038;ssl=1</url>
	<title>GSM &#8211; About Things | A Hans Scharler Blog</title>
	<link>https://nothans.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">114568856</site>	<item>
		<title>Send IoT Data to ThingSpeak using AT Commands (Arduino and SIM800L Tutorial)</title>
		<link>https://nothans.com/send-data-to-thingspeak-with-at-commands</link>
					<comments>https://nothans.com/send-data-to-thingspeak-with-at-commands#comments</comments>
		
		<dc:creator><![CDATA[Hans Scharler]]></dc:creator>
		<pubDate>Mon, 09 Jan 2023 14:36:41 +0000</pubDate>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[ThingSpeak]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[GPRS]]></category>
		<category><![CDATA[GSM]]></category>
		<category><![CDATA[internet of things]]></category>
		<category><![CDATA[iot]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[SIM800L]]></category>
		<category><![CDATA[thingspeak]]></category>
		<category><![CDATA[web of things]]></category>
		<guid isPermaLink="false">https://nothans.com/?p=3524</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[<h2 class="wp-block-heading" id="introduction">Introduction</h2>


<p>The <a rel="noreferrer noopener" href="https://www.amazon.com/HiLetgo-Smallest-Breakout-Quad-band-3-7-4-2V/dp/B01DLIJM2E?&amp;linkCode=sl1&amp;tag=nothans&amp;linkId=bba6df7a7bd85a7a248f9a73f8d4b1c3&amp;language=en_US&amp;ref_=as_li_ss_tl" target="_blank">SIM800L</a> module is a GSM/GPRS module that can be used to connect to the internet via a cellular network. It has a built-in SIM card slot and can be used to send and receive data over a cellular network connection instead of WI-Fi. <a rel="noreferrer noopener" href="https://thingspeak.com/" target="_blank">ThingSpeak</a> is an IoT platform that allows you to send and receive data from devices over the internet.</p>



<p>In this tutorial, we will use the SIM800L module and ThingSpeak&#8217;s API to send data from an Arduino board to be stored in the cloud.</p>


<h2 class="wp-block-heading" id="hardware">Hardware</h2>


<p>To complete this tutorial, you will need the following hardware:</p>



<ul class="wp-block-list">
<li>Arduino board</li>



<li>SIM800L module</li>
</ul>


<div class="wp-block-image">
<figure class="aligncenter size-full"><a href="https://amzn.to/3VX9D2t"><img data-recalc-dims="1" fetchpriority="high" decoding="async" width="750" height="667" data-attachment-id="3526" data-permalink="https://nothans.com/send-data-to-thingspeak-with-at-commands/image-1-6" data-orig-file="https://i0.wp.com/nothans.com/wp-content/uploads/2023/01/image-1.png?fit=909%2C809&amp;ssl=1" data-orig-size="909,809" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="SIM800L Module" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/nothans.com/wp-content/uploads/2023/01/image-1.png?fit=300%2C267&amp;ssl=1" data-large-file="https://i0.wp.com/nothans.com/wp-content/uploads/2023/01/image-1.png?fit=750%2C667&amp;ssl=1" src="https://i0.wp.com/nothans.com/wp-content/uploads/2023/01/image-1.png?resize=750%2C667&#038;ssl=1" alt="" class="wp-image-3526" srcset="https://i0.wp.com/nothans.com/wp-content/uploads/2023/01/image-1.png?w=909&amp;ssl=1 909w, https://i0.wp.com/nothans.com/wp-content/uploads/2023/01/image-1.png?resize=300%2C267&amp;ssl=1 300w, https://i0.wp.com/nothans.com/wp-content/uploads/2023/01/image-1.png?resize=768%2C684&amp;ssl=1 768w, https://i0.wp.com/nothans.com/wp-content/uploads/2023/01/image-1.png?resize=750%2C667&amp;ssl=1 750w" sizes="(max-width: 750px) 100vw, 750px" /></a><figcaption class="wp-element-caption"><a href="https://amzn.to/3VX9D2t" target="_blank" rel="noreferrer noopener">HiLetgo SIM800L GPRS GSM Breakout Module</a></figcaption></figure>
</div>

<h2 class="wp-block-heading" id="setting-up-the-sim800l-module">Setting up the SIM800L module</h2>


<p>First, let&#8217;s set up the SIM800L module. To use the SIM800L module with your Arduino board, you&#8217;ll need to connect it to the appropriate pins on the Arduino. The SIM800L module has a number of different pins, including power pins, serial communication pins, and control pins. You&#8217;ll need to consult the documentation for your particular module to determine which pins to use.</p>



<p>Once you have the SIM800L module connected to your Arduino board, you&#8217;ll need to use AT commands to communicate with it. AT commands are simple text-based commands that are used to control the module and send and receive data. Some common AT commands include <code>AT+CPIN</code>, which is used to enter the SIM card PIN number, and <code>AT+CREG</code>, which is used to check the registration status of the module.</p>



<p>To connect to the internet using the SIM800L module, you&#8217;ll need to attach it to the GPRS service and get an IP address. You can do this using the following AT commands:</p>



<pre class="wp-block-code"><code>sendATCommand("AT+CFUN=1", 2000, DEBUG); // Enable full functionality
sendATCommand("AT+CIPMUX=0", 1000, DEBUG); // Set single connection mode
sendATCommand("AT+CGATT=1", 1000, DEBUG); // Attach to GPRS service
sendATCommand("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"", 1000, DEBUG); // Set connection type to GPRS
sendATCommand("AT+SAPBR=3,1,\"APN\",\"YOUR_APN\"", 1000, DEBUG); // Set APN
sendATCommand("AT+SAPBR=1,1", 1000, DEBUG); // Enable GPRS
sendATCommand("AT+SAPBR=2,1", 1000, DEBUG); // Get IP address
</code></pre>


<h2 class="wp-block-heading" id="setting-up-thingspeak">Setting up ThingSpeak</h2>


<p>Now that we have the SIM800L module set up, let&#8217;s set up ThingSpeak. To use ThingSpeak&#8217;s API with your SIM800L module, you&#8217;ll need to create a new &#8220;channel&#8221; on the ThingSpeak website. A channel is a way to represent a device or a group of devices on the ThingSpeak platform. Once you&#8217;ve created a channel, you&#8217;ll be given an API key that you can use to access and update the channel from your Arduino sketch.</p>


<h2 class="wp-block-heading" id="sending-data-to-thingspeak">Sending data to ThingSpeak</h2>


<p>To send data to ThingSpeak using the SIM800L module, you&#8217;ll need to use the <code>AT+HTTPPARA</code> command to set the necessary parameters for the HTTP request, and then use the <code>AT+HTTPACTION</code> command to send the request.</p>


<h2 class="wp-block-heading" id="receiving-a-response-from-thingspeak">Receiving a response from ThingSpeak</h2>


<p>After sending the request, you can use the <code>AT+HTTPREAD</code> command to read the response from the server. The response will be a string of text, which you can parse to check for any errors or confirm that the data was successfully sent.</p>


<h2 class="wp-block-heading" id="putting-it-all-together">Putting it all together</h2>


<p>Here is an example of how you can use the SIM800L module and ThingSpeak&#8217;s API to send data from your Arduino board to the internet:</p>



<pre class="wp-block-code"><code>#include &lt;SoftwareSerial.h&gt;

SoftwareSerial sim800l(10, 11); // RX, TX

void setup() {
  sim800l.begin(9600);
  sendATCommand("AT+CFUN=1", 2000, DEBUG); // Enable full functionality
  sendATCommand("AT+CIPMUX=0", 1000, DEBUG); // Set single connection mode
  sendATCommand("AT+CGATT=1", 1000, DEBUG); // Attach to GPRS service
  sendATCommand("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"", 1000, DEBUG); // Set connection type to GPRS
  sendATCommand("AT+SAPBR=3,1,\"APN\",\"YOUR_APN\"", 1000, DEBUG); // Set APN
  sendATCommand("AT+SAPBR=1,1", 1000, DEBUG); // Enable GPRS
  sendATCommand("AT+SAPBR=2,1", 1000, DEBUG); // Get IP address
}

void loop() {
  sendDataToThingSpeak();
  delay(20000); // delay 20 seconds
}

void sendDataToThingSpeak() {
  String cmd = "AT+HTTPPARA=\"URL\",\"http://api.thingspeak.com/update?api_key=YOUR_API_KEY&amp;field1=42\"";
  sendATCommand(cmd, 1000, DEBUG); // Set URL
  cmd = "AT+HTTPACTION=0";
  sendATCommand(cmd, 3000, DEBUG); // Send request
  delay(1000);
  String response = sendATCommand("AT+HTTPREAD", 1000, DEBUG); // Read response
  Serial.println(response);
}

String sendATCommand(String cmd, const int timeout, boolean debug) {
  String response = "";
  sim800l.println(cmd);
  long int time = millis();
  while((time+timeout) &gt; millis()) {
    while(sim800l.available()) {
      char c = sim800l.read();
      response += c;
    }
  }
  if (debug) {
    Serial.println(response);
  }
  return response;
}</code></pre>



<p>In this example code, the <code>sendATCommand</code> function sends AT commands to the SIM800L module and reads the response. The <code>sendDataToThingSpeak</code> function is used to set the URL for the HTTP request using the <code>AT+HTTPPARA</code> command, send the request using the <code>AT+HTTPACTION</code> command, and read the response using the <code>AT+HTTPREAD</code> command. The <code>loop</code> function calls the <code>sendDataToThingSpeak</code> function every 20 seconds to send data (the number 42 in this case) to ThingSpeak. You can customize the code to send any data that you want to the fields of your ThingSpeak channel.</p>


<h2 class="wp-block-heading" id="conclusion">Conclusion</h2>


<p>In this tutorial, we have learned how to use the SIM800L module and ThingSpeak&#8217;s API to send data from an Arduino board to the internet. We have set up the SIM800L module and used AT commands to connect to the internet and send HTTP requests. We have also set up a ThingSpeak channel and used the API to send data to the internet.</p>



<p>With these tools and techniques, you can build your own IoT projects and start collecting and analyzing data from your devices. You can use ThingSpeak to visualize the data and create charts and graphs, or you can use the data in your own applications or MATLAB analyses.</p>



<p>If you found this tutorial helpful and would like to stay updated with more IoT and Arduino tips and tricks, consider <a href="https://nothans.com/subscribe" data-type="page" data-id="3041">subscribing</a> to my blog. I post about once per week.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nothans.com/send-data-to-thingspeak-with-at-commands/feed</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3524</post-id>	</item>
	</channel>
</rss>
