{"id":3077,"date":"2022-08-08T09:28:58","date_gmt":"2022-08-08T13:28:58","guid":{"rendered":"https:\/\/blogs.mathworks.com\/iot\/?p=3077"},"modified":"2025-12-08T15:41:47","modified_gmt":"2025-12-08T20:41:47","slug":"post-images-to-thingspeak-channels-from-your-iot-devices","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/iot\/2022\/08\/08\/post-images-to-thingspeak-channels-from-your-iot-devices\/","title":{"rendered":"New Feature: ThingSpeak Now Supports Images"},"content":{"rendered":"<p>Many users have asked, and it&#8217;s finally here: <strong>Your devices can upload images to ThingSpeak!<\/strong><\/p>\n<p>With this new feature, you can create a cloud-based tracking or monitoring system for your important assets by taking photos and uploading them to ThingSpeak image channels. Users with a paid ThingSpeak license can <a href=\"https:\/\/www.mathworks.com\/help\/thingspeak\/create-an-image-channel.html\">create image channels<\/a> and then embed the output from the image channel onto a channel view using the <a href=\"https:\/\/www.mathworks.com\/help\/thingspeak\/channel_display_widgets.html#mw_a1f3991b-41ca-4970-ab26-84f19a505ac3\">image widget<\/a>.<\/p>\n<p>To help you get started, the ThingSpeak documentation includes two examples for uploading images to ThingSpeak: <a href=\"https:\/\/www.mathworks.com\/help\/thingspeak\/write-image-to-thingspeak-from-esp32-camera-board.html\">ESP32-CAM camera module<\/a> and <a href=\"https:\/\/www.mathworks.com\/help\/thingspeak\/write-image-to-thingspeak-from-raspberry-pi-with-python.html\">Raspberry Pi-connected camera<\/a>.<\/p>\n<p><a href=\"https:\/\/blogs.mathworks.com\/iot\/files\/2022\/08\/RPiImageBlog.png\"><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-3089 aligncenter\" src=\"https:\/\/blogs.mathworks.com\/iot\/files\/2022\/08\/RPiImageBlog-300x208.png\" alt=\"\" width=\"389\" height=\"270\" \/><\/a> <br \/>Many ThingSpeak channels represent a particular IoT project. Previously, to show an image in the channel view you had to go to some lengths &#8211; including <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/answers\/590692-read-database-from-cloud-storage-dropbox-or-onedrive-to-thingspeak\">copying from third-party location<\/a> using <a href=\"https:\/\/www.mathworks.com\/help\/thingspeak\/matlab-visualizations-app.html\">MATLAB visualizations<\/a> or <a href=\"https:\/\/thingspeak.com\/channels\/276330\">using an existing photo<\/a> on the web. The ThingSpeak images feature uses your<a href=\"https:\/\/www.mathworks.com\/products\/matlab-drive.html\"> MATLAB Drive space<\/a> to store images, so they will be available for your channels whenever you need them.<\/p>\n<p>Here is some MATLAB code that will write to an image channel from your computer. This code will help you get an image into ThingSpeak without needing an IoT device. Save an image to your system and name it &#8220;myImage.jpg&#8221;.<\/p>\n<pre>% Import these libraries to use the HTTP interface.\u00a0 <br \/>% They are in base MATLAB, no extra license is required.<br \/>import matlab.net.http.*<br \/>import matlab.net.http.field.*<br \/>import matlab.net.http.io.*<br \/><br \/>% Edit this section for your files. Timestamps are optional.<br \/>channelId = 'X1X1X1X1X1';<br \/>channelApiKey = HeaderField('thingspeak-image-channel-api-key', 'ZZZZZZZZZZZZZZZZ');<br \/>filename = 'myImage.jpg';<br \/>clientTimestamp = '2022-01-29T15:06:35.642Z'; % Optional Timestamp<br \/><br \/>provider = FileProvider(['.\/', filename]);<br \/>req = RequestMessage(RequestMethod.POST, [channelApiKey], provider);<br \/>url = ['https:\/\/data.thingspeak.com\/channels\/', channelId, '\/images\/', ...<br \/>filename, '\/', clientTimestamp ];<br \/>response = req.send(url)<\/pre>\n<p>If everything worked, you should expect a <em>StatusLine<\/em> of\u00a0 &#8216;HTTP\/1.1 202 Accepted&#8217; in the response. If you want to see this image on a channel view, follow the steps in the <a href=\"https:\/\/www.mathworks.com\/help\/thingspeak\/channel_display_widgets.html?searchHighlight=image%20widget#mw_a1f3991b-41ca-4970-ab26-84f19a505ac3\">documentation<\/a>.<\/p>\n<p><a href=\"https:\/\/blogs.mathworks.com\/iot\/files\/2022\/08\/thingspeakCars.png\"><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-3092 aligncenter\" src=\"https:\/\/blogs.mathworks.com\/iot\/files\/2022\/08\/thingspeakCars-300x207.png\" alt=\"\" width=\"465\" height=\"321\" \/><\/a><br \/>Be careful when saving a regular stream of images, they can fill up your drive space fast. Here is MATLAB code to delete a date range of images.<\/p>\n<pre><br \/>import matlab.net.http.*<br \/>import matlab.net.http.field.*<br \/>import matlab.net.http.io.*<br \/><br \/>% Edit this section with your information.<br \/>channelId = 'x1x1x1x1x1';<br \/>channelApiKey = HeaderField('thingspeak-image-channel-api-key' ...<br \/>, 'xxxxxxxxxxxxxxxx');<br \/>endDate = datetime('now');<br \/>startDate = endDate - days(3);<br \/><br \/>fmt = 'yyyy-mm-ddThh:MM:ssZ';<br \/>startDate = datestr(startDate,fmt);<br \/>endDate = datestr(endDate,fmt);<br \/><br \/>pathRange = sprintf('\/images?timestamp=ingest&amp;start=%sZ&amp;end=%s',...<br \/>startDate,endDate);<br \/><br \/>req = RequestMessage(RequestMethod.DELETE, [channelApiKey]);<br \/>url = ['https:\/\/data.thingspeak.com\/channels\/', channelId, ...<br \/>pathRange];<br \/>response = req.send(url)<\/pre>\n<p>In both cases, you will get a status code that you can check using the <a href=\"https:\/\/www.mathworks.com\/help\/thingspeak\/readstatusofimagerequest.html\">status endpoint<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/iot\/files\/2022\/08\/RPiImageBlog.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div>\n<p>Many users have asked, and it&#8217;s finally here: Your devices can upload images to ThingSpeak!<br \/>\nWith this new feature, you can create a cloud-based tracking or monitoring system for your important&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/iot\/2022\/08\/08\/post-images-to-thingspeak-channels-from-your-iot-devices\/\">read more >><\/a><\/p>\n","protected":false},"author":175,"featured_media":3089,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[22,4],"tags":[296,299],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts\/3077"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/users\/175"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/comments?post=3077"}],"version-history":[{"count":15,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts\/3077\/revisions"}],"predecessor-version":[{"id":3561,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts\/3077\/revisions\/3561"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/media\/3089"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/media?parent=3077"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/categories?post=3077"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/tags?post=3077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}