Dion Guek in MATLAB Answers
上次活动时间: 2024-6-4

This string of code is taken from the thingSpeak documentation for matlab. I just copy and paste but still got this error. I would very much appreciate it if anyone can tell me where i did wrong <</matlabcentral/answers/uploaded_files/94486/error.JPG>>
Pedro in Discussions
上次活动时间: 2023-7-18

Good morning, I am trying to send a long number to a channel convert it to a string once received. The number, as an example, might look like this: field1=100630000553400000000 However, if I input it to a matlab analyze in thingspeak, i get it either as a number in scientific notation, or it is giving me a different number if I convert it using functions like mat2str, compose, num2str, etc. In the case of the number above, i get numbers like: field1=0100630000553399992320 It looks like the numbers are pretty close or there is some strange rounding going on. I am sending the field from a desktop mqtt server so the value is set by me. Is there something I should consider when sending such long numbers? Thanks! Reading long numbers in thingspeak Can you share your code to read the number (and perhaps your channel ID if it is public?) The key is when the string to number conversion is happening. I recommend keeping it a string at long as possible to keep the literal digits. Thank you for your help. The channel ID is 2221937. I made it public so you can see the message received. When I read your field 1 data, I see {"created_at": "2023-07-17T09:52:45-04:00","entry_id": 2,"field1": "100630000609200000099"}, Based on your criteria above, this looks like what you hoped for? Can you confirm if that is what you expect? Are you reading it into MATLAB and then printing there? Can you share the code youy use to read tha values? This is my code, i wil change the API key later. You can check the result register variables does not match what we can normally read using https://api.thingspeak.com/channels/2221937/feeds.json?results=2 % Enter your MATLAB code below % Channel ID to read data from readChannelID = 2221937; % Channel Read API Key % If your channel is private, then enter the read API % Key between the '' below: readAPIKey = 'VEMNQ70TRRNSVL1O'; format long registers2 = num2str(thingSpeakRead(readChannelID,'Fields',1,'ReadKey',readAPIKey),25) registers2 = num2str(thingSpeakRead(readChannelID,'Fields',2,'ReadKey',readAPIKey),25) registers3 = num2str(thingSpeakRead(readChannelID,'Fields',3,'ReadKey',readAPIKey),21) registers4 = num2str(thingSpeakRead(readChannelID,'Fields',4,'ReadKey',readAPIKey),21) registers5 = num2str(thingSpeakRead(readChannelID,'Fields',7,'ReadKey',readAPIKey),21) took me a little bit of futzing, but I got this: url='https://api.thingspeak.com/channels/2221937/feeds.json?results=1' kim=webread(url) registers1 = kim.feeds.field1 registers2 = kim.feeds.field2 ... also consider using thingSpeakRead with 'outputformat','timetable' when you want to read string type data. url='https://api.thingspeak.com/channels/2221937/feeds.json' btw, you dont need the api key if the channel is set to public. Thank you, Christopher! I will give it a shot today. I tried changing the output format but it was still showing as scientific notation. matlab long number string
Lorenzo Scavarda in Discussions
上次活动时间: 2022-6-8

Good morning, I'm working with an Arduino MKR 1010 which takes information about weather from the website "api.openweathermap.org". On a ThingSpeak dashboard I displayed the main numbers (float) information like: temperature, wind speed, humidity, etc. Moreover, from the openweathermap I can also get string sentence (e.g. "light rain" or "broken clouds" etc.). I'm wondering if there is a way to display on the ThingSpeak dashboard string fields. Indeed, in the ThingSpeak Channel Settings I added an extra Field in order to store these string words but I don't know how to print them in the dashboard. Someone can help me? Thanks in advance, Lorenzo Display message on ThingSpeak Are you trying to display the text on your ThingSpeak channel? If so, you can use a MATLAB visualization, and use the text or annotate functions to put the text on a figure. Then add the visualization to your channel. When I've done this, i occasionally have to experiment with scaling the figure and text, but with a little work, you can definitely get what you want. Maybe you can use the Status field of the channel to display the text? Thanks Christopher for the answer. Yes, I though it but I have a doubt: what is the right function to retrieve the string (that I want to display) and put it in the annotate function? Because my problem is that the String is one of the Fields of my Channel. For example I found: data = thingSpeakRead(readChannelID,'Fields',field_number,NumPoints=3) but I don't how to handle a string variable. Is it enough use: data = thingSpeakRead(readChannelID,'Fields',field_number) Do you have some hints? Thanks a lot in advance, Cheers, Lorenzo Hi Vinod, yes, I'm using the Status Field indeed. However, it is not the best way because the layout and format of the text is very fixed, for example I can't use the "new line" but the text is in just one line. If I want to display a sort of weather report for the next hours of the day (i.e. not just one word but several sentences) is not very suitable. Either option you show above will work fine. dashboard string arduino api field
Muhammad Rakeh Saleem in MATLAB Answers
上次活动时间: 2018-5-31

So i have been getting this error for quite a long and i don't know whats the problem in the code. Refer to the code, I have to plot the waveform of the data that is stored in the z variable after concatenation of several strings. The point is to get data from 8 different fields of same channel in Thingspeak platform. So far I have received data from the all fields and make a single string of the data. In the end, when I try to plot it prompt me with the following error and does not plot the data. ======> "Undefined function 'real' for input arguments of type 'string' Error" <====== Can somebody please guide me how to remove this error as I am not very familiar with MATLAB coding. Any help will be really appreciated. data1=thingSpeakRead(readChannelID,'Fields',[1],'NumPoint',1,'OutputFormat','timetable'); data2=thingSpeakRead(readChannelID,'Fields',[2],'NumPoint',1,'OutputFormat','timetable'); data3=thingSpeakRead(readChannelID,'Fields',[3],'NumPoint',1,'OutputFormat','timetable'); data4=thingSpeakRead(readChannelID,'Fields',[4],'NumPoint',1,'OutputFormat','timetable'); data5=thingSpeakRead(readChannelID,'Fields',[5],'NumPoint',1,'OutputFormat','timetable'); data6=thingSpeakRead(readChannelID,'Fields',[6],'NumPoint',1,'OutputFormat','timetable'); data7=thingSpeakRead(readChannelID,'Fields',[7],'NumPoint',1,'OutputFormat','timetable'); data8=thingSpeakRead(readChannelID,'Fields',[8],'NumPoint',1,'OutputFormat','timetable'); L=string(data1.test1); L1=extractBefore(L,"/"); x1=strsplit(L1,' '); M=string(data2.test2); M1=extractBefore(M,"/"); x2=strsplit(M1,' '); N=string(data3.test3); N1=extractBefore(N,"/"); x3=strsplit(N1,' '); O=string(data4.test4); O1=extractBefore(O,"/"); x4=strsplit(O1,' '); P=string(data5.test5); P1=extractBefore(P,"/"); x5=strsplit(P1,' '); Q=string(data6.test6); Q1=extractBefore(Q,"/"); x6=strsplit(Q1,' '); R=string(data7.test7); R1=extractBefore(R,"/"); x7=strsplit(R1,' '); S=string(data8.test8); x8=strsplit(S,' '); z=cat(2,x1,x2,x3,x4,x5,x6,x7,x8) thingSpeakPlot(z)

关于 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.