Prajna Bhat in MATLAB Answers
Letzte Aktivitätam 11 Feb. 2023

The ThingSpeak API provides the possibility to embed the chart with historical values of a channel in a web page. Now I would also like to show the last value of a channel as a number on this page. I looked into some of the answers. But I could not understand. Can someone please share the JavaScript code OR the HTML code? I am new to ThingSpeak and Web Development. Please help me out!! Thank you, Prajna Bhat
Andrew Clark in Discussions
Letzte Aktivitätam 2 Feb. 2023

Hello, I need help with a simple example. I am trying to do a simple bulk update using JSON & Javascript, using this parm, header and body: $.post("https://api.thingspeak.com/channels/xxxxxxxxx/bulk_update.json" ,{ "Content-Type": "application/json", "write_api_key" : "xxxxxxxxxxxxxxxx", "updates": [ { "created_at": "2022-12-30 10:26:2 -0800", "field1": 100, "status": "good" }, { "created_at": "2022-01-12 10:27:2 -0800", "field2": 100, "field3": 200, "field5": 600, "latitude": 123, "longitude": 23, "elevation": 34 }], function(data){ console.log(data) // log anything returned to the console } }); When I run the above (Mac OS, Chrome) I receive this error message: Access to XMLHttpRequest at 'https://api.thingspeak.com/channels/1283582/bulk_update.json' from origin 'https://backpaqlabs.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. api.thingspeak.com/channels/1283582/bulk_update.json:1 Failed to load resource: net::ERR_FAILED Is there something wrong with the syntax or JSON payload? I have literally taken it from the example in the doc, so I assume it should comply with the API endpoint. BTW, I am receiving CORS errors with getJSON as well, also from Javascript/Chrome. Appreciate any help. Thanks! Still getting CORS error with Bulk Update I think the browser route is specifically denied in the CORS policy on purpose. Ill see what else I can find out. Hi Christopher, thanks for the response. Javascript, which runs in browsers such as Chrome, is allowed, and I use it extensively to fetch data (ie, READ) from Thingspeak. The issue seems to be with WRITE/UPDATE, as all of my READ API functions are currently working. My question is concerning the WRITE function and what seems to be blocking my API calls on your server/endpoint. Can you please verify that UPDATE API requests (and specifically, BULK UPDATE) from outside THINGSPEAK.COM domain are allowed by your CORS policy to access the Thingspeak servers? Thanks much! The dev team agrees with you that bulk update via browser is not specifically prohibited in our policy. You should also have the header 'Access-Control-Allow-Origin' with the value set to *. Do you have this in your request? Christopher, thanks for the tip. Unfortunately, same result using 'Access-Control-Allow-Origin' : '*' in the request Header. I was able to get the "non-bulk" request to work, that is, "update.json". So it seems it's something specific to Bulk. I am also wondering if it could be something in the JSON body that's triggering the error...is the JSON syntax somehow position sensitive, ala Python (in other words, are invisible blanks or tabs a problem in the JSON?) Thanks! Hi Christopher, need to bump this Q as i am still unable to perform the Bulk Updates using JSON due to CORS errors. Can you please confirm with development that I should be able to do the bulk method as described in the above example? Thanks much! I tried out your code and I think this is not a ThingSpeak issue. If I change the URL to anything, I still get the error. Ill keep plugging though. Hi Christopher, thanks for taking a look! It may not be a Thingspeak issue per se, but may be something to do with how the JSON request is formatted or specified. I have tested the JSON and it's semantically correct and correctly formatted. To me, it's still a Thingspeak issue if simple Update API requests will not work or are so hard to use that users will give up. As has been mentioned several times prior, it would be great if we could do this request from the Library API or some other easier-to-use method. Thanks! bulk update json javascript cors
Hans Scharler in Discussions
Letzte Aktivitätam 6 Apr. 2022

Hi everyone. I updated my <https://github.com/nothans/iot-debugger IoT Debugger> project on GitHub. You can use the debugger to view channel data from ThingSpeak. IoT Debugger on GitHub (updated) Thanks. I've been wanting to publish my own, now I can work with yours! javascript iot
Sharif Ahmed in MATLAB Answers
Letzte Aktivitätam 14 Okt. 2021

Hi there, i am trying to pull some data with java script, but i cant find a solution. can u please help me or push me into the right direction. Thank you
Prajna Bhat in Discussions
Letzte Aktivitätam 5 Jul. 2021

Hi all, The ThingSpeak API provides the possibility to embed the chart with historical values of a channel in a web page. Now I would also like to show the last value of a channel as a number on this page. I looked into some of the answers. But I could not understand. Can someone please share the JavaScript code OR the HTML code? I am new to ThingSpeak and Web Development. Please help me out!! Thank you, Prajna Bhat Javascript to display last value of a channel on web page | ThingSpeak API thingspeakapi javascript html thingspeak
Gcobani Mkontwana in MATLAB Answers
Letzte Aktivitätam 7 Nov. 2019

Hi Team I want to change the status of a message to be true, when the button is clicked 'on' and vice versa when is clicked off to be off. So far the functionality seem working not according to what i need it to be. e.g If my button is off, button continues to previous state as true(on). Off which i dont want that, want current state the button to be it remain and keep its value. Like if its on should be remain its value as on, same applies to off logic. I am struggling to get this work. I show you my code so far what i have done. <!---HTML code----> <body> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"><br/> <div class ="success"></div> <div class = "warning"></div> <div class="col-md-2 text-center"> <button id="singlebutton" name="singlebutton" class="btn btn-danger" onclick="BtnOff();">Off</button> <br> </div> <!------ ----> <br/> <div class = "col-md-2 text-center"> <button id = "singlebtn" name="singlebtn" class="btn btn-success" onclick = "BtnOn();">On</button> <br> </div> </body> </html> <!----Javascript code----> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script> function BtnOff() { $.ajax({ url:'https://api.thingspeak.com/update?api_key=D****&field8=0', type:'GET', data:{ type:'text' }, success:function(response){ alert(response); $('div.warning').html('status changed to zero').delay(1000).fadeOut(); $('#singlebutton').append(data); } }); //setTimeout("Subscribe()", 100); } // second button to unsubscribe. function BtnOn() { $.ajax({ url:'https://api.thingspeak.com/update?api_key=*****&field8=1', type:'GET', data:{ type:'text' }, success:function(response){ alert(response); $('div.success').html('status changed to one').delay(1000).fadeOut(); $('#singlebtn').append(data); } }); //setTimeout("UnSubscribe()", 100); } </script>
Gcobani Mkontwana in MATLAB Answers
Letzte Aktivitätam 5 Nov. 2019

Hi Is there anyone who can me help with work around example, as to how to publish message using talkback or plugin on client side? I am using native javascript with jquery and have API key sending GET protocol. I want my button to subscribe to that channel i created, please help me by showing an example i am sure can able to do this. My channel have two fields temp and illuminance, both been programmed on IDE Arduno and have button_state that must read from my talkback functionality; Plugin functionality for my button to read or subscribing my channel; <html> <head> <!-- NOTE: This plugin will not be visible on public views of a channel. If you intend to make your channel public, consider using the MATLAB Visualization App to create your visualizations. --> %%PLUGIN_CSS%% %%PLUGIN_JAVASCRIPT%% </head> <body> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"><br/> <div class="col-md-4 text-center"> <button id="singlebutton" name="singlebutton" class="btn btn-primary">IOT-Talk</button> </div> </body> </html> <script src="https://code.jquery.com/jquery-3.3.1.js"integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="crossorigin="anonymous"></script> <script type="text/javascript"> function OPENDOOR() { $.ajax({ url:"https://api.thingspeak.com/talkbacks/35734/commands?key=MF710NTKMG0E44UG&command_string=OPENDOOR&position=1", type: 'GET', success: function(data) { //called when successful //console.log(data); $('#singlebutton').on('click', function (e) { $('#singlebutton').append(data); }) } }); } </script>

Info zu ThingSpeak

The community for students, researchers, and engineers looking to use MATLAB, Simulink, and ThingSpeak for Internet of Things applications. You can find the latest ThingSpeak news, tutorials to jump-start your next IoT project, and a forum to engage in a discussion on your latest cloud-based project. You can see answers to problems other users have solved and share how you solved a problem.