Location of a moving device, via MATLAB visualization

George on 13 Dec 2022
Latest activity Reply by George on 14 Jan 2023

Hi there, I have been attempting to try and access the loaction of my device using the following code:
myChannel=*******;
ReadAPIKey='xxxxxxxxxxxx';
myData=thingSpeakRead(myChannel,'ReadKey', ReadAPIKey,'numpoints',100,'outputformat','timetable','location',1);
myVector=(myData.Latitude).^2+(myData.Longitude).^2+myData.Altitude.^2;
maxVector=max(myData.Latitude)^2+max(myData.Longitude)^2+max(myData.Altitude)^2;
myVector=myVector/maxVector;
myMap=geoscatter(myData.lat,myData.long,15,myVector,'filled');
geobasemap('satellite');
colormap jet;
I have about 100 entry points at this stage. However, i get the following error:
Error using .
Unrecognized table variable name 'lat'.
Error in Custom (no starter code) 2 (line 7)
myMap=geoscatter(myData.lat,myData.long,15,myVector,'filled');
I am attempting to access the location of a moving device. Meaning, the longitude and latitude values will be constantly changing, thus, I do not want to set my latitude or longitude value as a constant but i want it to keep on updating as my device moves around. How would I do this? How would I ammend this error without setting the "lat" or "long" as a consant before hand?
Further, my device should be constantly sending messages, this, the number of entries to which it will see the location of will be contantly changing. How can I thus not set the entry points as a specific value but rather have it update as my device sends messags?
Is there an easier or better way to do this?
Thanks
Christopher Stapels
Christopher Stapels on 13 Dec 2022
You might try channel 876466 to practice reading data from. Its one of my channels with position data in it.
I'm sorrry I didnt clean up the code I shared above. I had it and I wanted to share quickly but I didnt test it.
Use myData.Latitude and myData.Longitude and you shouldnt get an error, assuming there is location data in the channel. To make sure there is position data in the channel, you have to use the format for the write REST call that I gave in the other post. The parameters for &latitude=xx and &longtitude=yy have to be written to the channel at least once. Every time you read the channel, you will get the most recent n points that show where your device is.
There are a lot of ways to handle the changing number of entries. For one, when you read you can use a set time format parameter, such as days= or minutes=. Then thingspeak will retrurn as many points (up to 8k) that are in that time range. There are alse begin and end parameters, and you can use datatime manipulation to set rolling dates with your code. When you read the data, if you need to know the number of points, MATLAB has lots of functions to help with that (size, and height, for example)
Another thing you can do is to increment a channel field witht he number of points, then read that channel value to know how many points there are.
George
George on 14 Dec 2022
Hi there, thank you for this helpful reply. I adjusted the variable names and it seemed to be accepted. Upon searching for information about a REST api call, it said that i must search that call in my web's search bar. Is this the correct way to go about doing this? If not, what else would i do?
Regarding the ways to handle changing the number of entries, I am slightly unsure on where to use "days=" or "minutes=" within that MATLAB visualization code which you sent previously.Where would I incorporate this in my code?
Also, my aim is to solely see the location of the last message which has been sent, including indications of previous locations (the history of other locations). Would this be the best way to do this? Or is there another code which would do this best? If so, please may you share this code as i have struggled to do this and would greatly appreciate some assistance on this problem.
Thank you
George
George on 17 Dec 2022
Hi there Chris, please may you let me know if it is possible to show the location history of the device (thus the location of each of the messages recived) on Thingspeak? If it is possible, please may you guide me on how to do this.
Thank you
Christopher Stapels
Christopher Stapels on 19 Dec 2022
Can you clarify what you mean becasue I feel that was the question I already answered above.
George
George on 20 Dec 2022
My aim is to show the location of each message that has ever been sent to the ThingSpeak channel. Such as the image attached below (an example from a Things.io channel). For each message recieved from my device, I want there to be a map and a pin at the precise location at which the message was sent. I am unsure on how to get the code above to do this. I am also still unsure on how to get the number of messages (the 260 or the 100 number in my case) to increase as the incoming messages increases.
Also, I am unsure on how to connect the REST api call to the code. I did some research on it and it said to search the REST api call in your browser's search bar. However, this did not work.
Please may you assist.
Is there another way I could communicate with you, perhaps on email?
Christopher Stapels
Christopher Stapels on 20 Dec 2022
Thank you for taking the time to describe your goal carefully. You say "show the location of each message that has ever been sent." If your device did not send its location, it is not possible for ThingSpeak to show you the location. Our service does not get the device location from the server if the device did not send the info. Does your device post its location data when it sends data to ThingSpeak? Is your device aware of its location?
Support via email is available for holders of commercial or academic licenses.
George
George on 20 Dec 2022
My dvice is sending information from Sigfox to Tingspeak. My Sigfox Atlas is enabled which allows the location of the device to be seen on Sigfox. This was my initial issue, which was how to send the location of my device from Sigfox to Thingspeak. I have a callback enabled on Sigfox's end which sends the "computedLocation" to my field4 of Thingspeak but nothing appears on Thingspeak's end (my goal here is to have a map showing the "computedLocation" from Sigfox), and this is why I think that I am sending the location from Sigfox incorrecly. Do you know how i could send the location from Sigfox to Thingspeak or any other way in which i could do this? I cannot find any resources which do this.
Thanks
Christopher Stapels
Christopher Stapels on 20 Dec 2022
Thats perfect, thanks for the clarification. I see that some of the info was in your earlier posts, but I didnt quite piece it all together. Can you show what the computed location on field 4 looks like - or can you share your channel ID if it is public? Is the data "lattitude,Longitude" or something like that?
It might be easier if your callback from sigfox wrote the data into the lattitude and longitude fields, but we can also extract them form field 4 fairly easily too.
Once you show me the data format, I can help you use the code above to read the last points in your channel. If you ask thingspeak for more data than you have, it will return the most recent data up to 8000 points. From what you said the problem about getting an increasing number of locations wont be a problem until you hit 8000. Lets get the map working first and then we can deal with the other issue.
George
George on 20 Dec 2022 (Edited on 20 Dec 2022)
Yes I do see how my previous messages could have been confusing, but i really do appreciate all of your help.
So on Sigfox this is the location which is being recorded (which is correct and quite precise).
Following this, I attempted to make a callback following this blog (which uses thethings.io rather than Thingspeak) : https://blog.thethings.io/computedlocation-sigfox-and-visualize-on-a-map-your-devices/ . From this, I generated the following callback on Sigfox:
But I do now recognize how this method could be incorrect since I have not recieved any information to do with location on Thingspeak's end.When I show field 4's visualization, it is a blank graph. This is how i know that I am not recieving anything from Sigfox with the above callback. However, since the link above is the only source that I can find which is doing what I aim to do, I am at a loss.
Sigfox does have different variables which can be sent through a DATA-ADVANCED callback, which can be seen here: https://support.sigfox.com/docs/data-advanced . However, when I try to enter variables into the "Body" section of the callback, such as "computedLocation.lat", it says that "computedLocation.lat" is undefined and does not let me save the callback. I have also tried to see why this is the case but cannot find the solution. Thus, computedLocation was the variable which i have been attempting to pass to Thingspeak, as i imagine that once it is sent correclty, I will have access to a map on Thingspeak which illustrates the device's location per message sent, similar to the map above.
This is a basically a summary of the root to my issue. I know that you have not worked with Sigfox so I really do appreciate your advice and guidance to solve this issue.
I made my channel public so that you can see. My channel ID is 1970146
Thanks
Christopher Stapels
Christopher Stapels on 10 Jan 2023
For the sigfox callback, I would consider using the body for your variables (like field4=) as in the JSON example here
But I think the {computedlocation} question will have to go to sigfox, I'm sorry.
Christopher Stapels
Christopher Stapels on 30 Dec 2022
Im glad you redacted your API key, but I cant quite see the format you used. Is here any other field information in the URL pattern? Looking at your channel, there seems to be data getting in, was that data a result from the callback above? In the POST body, you should consider using
field1=(some data)
field3=(other data)
field4={computedlocation}
or something similar. Otherwise ThingSpeak wont know where you want to put the data.
George
George on 14 Jan 2023
I see.
I will let you know when I manage to find a solution, thank you for all of your time and for your help, it was extremely helpful and is greatly appreciated!
Christopher Stapels
Christopher Stapels on 13 Jan 2023
ThingSpeak does not have a way to localize message source. ITs too bad the callback cant access {computed location} becasue that would be a nice thing to write to ThingSpeak without having to add a GPS to your device. Please let us know if you figure out how to get the data from sigfox. I looked the their doc briefly and it seemed liek it should work close to how you had it above.