George in Discussions
Última actividad el 14 de En. de 2023

Hi there, I am using the following code in order to try and access th location of my device (via MATLAB visualization): myChannel=*******; ReadAPIKey='xxxxxxxxxxxxx'; 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; At the moment, I have only 100 entries. However, I am getting the 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');". How do i fix this error? Or where would i predefine "lat"? I do not want to set "lat" as a constant value as my device will be moving around and I want to access the location of the device per message sent, wherever it may be. Please may anyone assist. Location of a moving device, via MATLAB visualization 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. 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 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 Can you clarify what you mean becasue I feel that was the question I already answered above. 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? 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. 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 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. 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 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. For the sigfox callback, I would consider using the body for your variables (like field4=) as in the JSON example here https://www.mathworks.com/help/thingspeak/writedata.html But I think the {computedlocation} question will have to go to sigfox, I'm sorry. Hi there Chris, thank you for your response. So from what I know, you set the field information in the "URL pattern" section of the Sigfox callback. The callback which is above was simply an attempt to get the {computedLocation} to send, the information which is showing on my page is a result of the callback below: So I set the URL pattern as https://api.thingspeak.com/update?api_key= XXXXXXXXXXXXX&field1={customData#temp}&field2={customData#t}&field3={customData#h} which thus sends information to the fields directly. The {computedLocation} is not sent from the Arduino code so that is why I didn't include it in this URL pattern and tried to create a separate callback for it. If this is not the best way to access location, is Thingspeak able to access the location of the incoming messages indpendently? Further, if this issue is beyond Thingspeak, I will go forward by attempting to ask Sigfox. Thank you! 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. 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! location dht11 arduino sigfox temperature humidity latitude longitude
Subtil Songeur in MATLAB Answers
Última actividad el 1 de Dic. de 2021

I get the data from my 2x dth11 (2x temp and 2x humidity) sensor and no error with this code, but thingspeak receved no data and i get only one loop. Any one see what wrong? #include <Ethernet.h> #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros #include "DHT.h" #define DHT1PIN 10 // what pin we're connected to #define DHT2PIN 9 // Uncomment whatever type you're using! #define DHT1TYPE DHT11 // DHT 11 #define DHT2TYPE DHT11 // DHT 11 DHT dht1(DHT1PIN, DHT1TYPE); DHT dht2(DHT2PIN, DHT2TYPE); byte mac[] = { 0xDE, 0xAD, 0xBE, 0xXX, 0xXX, 0xXX }; // Set the static IP address to use if the DHCP fails to assign IPAddress ip(192, 168, X, XXX); IPAddress myDns(192, 168, X, X); EthernetClient client; unsigned long myChannelNumber = XXXXXX; const char * myWriteAPIKey = "XXXXXXXXXXXXXXX"; // Initialize our values int number1 = 0; int number2 = random(0,100); int number3 = random(0,100); int number4 = random(0,100); void setup() { Ethernet.init(10); // Most Arduino Ethernet hardware Serial.begin(115200); //Initialize serial while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo native USB port only } // start the Ethernet connection: Serial.println("Initialize Ethernet with DHCP:"); if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); // Check for Ethernet hardware present if (Ethernet.hardwareStatus() == EthernetNoHardware) { Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); while (true) { delay(1); // do nothing, no point running without Ethernet hardware } } if (Ethernet.linkStatus() == LinkOFF) { Serial.println("Ethernet cable is not connected."); } // try to congifure using IP address instead of DHCP: Ethernet.begin(mac, ip, myDns); } else { Serial.print(" DHCP assigned IP "); Serial.println(Ethernet.localIP()); } // give the Ethernet shield a second to initialize: delay(1000); ThingSpeak.begin(client); // Initialize ThingSpeak Serial.println("DHT11 Fonctionnel"); dht1.begin(); dht2.begin(); } void loop() { // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) float t1 = dht1.readTemperature(); float h1 = dht1.readHumidity(); float t2 = dht2.readTemperature(); float h2 = dht2.readHumidity(); // check if returns are valid, if they are NaN (not a number) then something went wrong! if (isnan(t1) || isnan(h1)) { Serial.println("Failed to read from DHT #1"); } else { Serial.print("Temperature entrée: "); Serial.print(t1); Serial.print(" *C "); Serial.print(" Humidity entrée: "); Serial.print(h1); Serial.println(" %\t"); } if (isnan(t2) || isnan(h2)) { Serial.println("Failed to read from DHT #2"); } else { Serial.print("Temperature sortie: "); Serial.print(t2); Serial.print(" *C "); Serial.print(" Humidity sortie: "); Serial.print(h2); Serial.println(" %\t"); } // set the fields with the values ThingSpeak.setField(1, dht1.readTemperature()); delay(10000); ThingSpeak.setField(2, dht1.readHumidity()); delay(10000); ThingSpeak.setField(3, dht2.readTemperature()); delay(10000); ThingSpeak.setField(4, dht2.readHumidity()); delay(10000); // write to the ThingSpeak channel // write to the ThingSpeak channel int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); if(x == 200){ Serial.println("Mise a jour du Canal."); } else{ Serial.println("Problem updating channel. HTTP error code " + String(x)); } // change the values number1++; if(number1 > 99){ number1 = 0; } number2 = random(0,100); number3 = random(0,100); number4 = random(0,100); delay(20000);// Wait 20 seconds to update the channel again }
Jeff in MATLAB Answers
Última actividad el 23 de Jun. de 2021

I've just installed a NodeMCU for transmitting temperature data to Thingspeak & am very impressed. However, will it do this reliably & continuously for months without my intervention ? I often go away on holiday for a few months and want something that doesn't stop at random. The Node transmits temperature data, then goes into deep sleep for 3 minutes and then repeats the process. I've had a Raspberry Pi sending data to PrivateEyePi for several years. However, this drops out at random every few weeks and needs a reboot. To fix that, I have script which reboots the Pi every 30 minutes and a plug in timer to reboot it every 24h. Will I need any similar set up to ensure my node MCU doesn't drop out ? Or do these usually work ?
Lutfi Can Koseoglu in MATLAB Answers
Última actividad el 4 de Jun. de 2021

Wireless Weather Station - ThingSpeak IoT Hello, I want to make a weather forecast for the next 3 days using the data I received from my sensors on the thingsspeak server I gave the link above, how can I do this? I need to do it with mathlab code in Thingsspeak system but I am very new to Mathlab. Thanks for your help.
Quoc-Khanh Pham in MATLAB Answers
Última actividad el 28 de Sept. de 2020

I have recently installed an NCD MegaModem paired with an NCD Temperature sensor for our lab freezers (-80c). I have set the gateway for MQTT transmissions. I can see that my MQTT gateway is transmitting data to mqtt… ….com:1883 since I am getting the following output: {"channel":{"id":1155233,"name":"baolab","latitude":"0.0","longitude":"0.0","field1":"temperature_celsius","created_at":"2020-09-23T15:38:10Z","updated_at":"2020-09-23T22:07:26Z","last_entry_id":7982},"feeds":[{… …"created_at":"2020-09-25T17:13:36Z","entry_id":7981,"field1":"{"transmission_count":105,"battery_level":3.06544,"type":39,"node_id":0,"rssi":34,"temperature_celsius":-80.18}"},{"created_at":… …"2020-09-25T17:13:58Z","entry_id":7982,"field1":"{"transmission_count":107,"battery_level":3.06544,"type":39,"node_id":0,"rssi":31,"temperature_celsius":-80.08}"}]} My question is… …: How can I select/choose to show only temperature_celsius on the graph? Right now I am not getting anything on the graphs. Field1 name is temperature_celsius. Thanks a lot!
frank odonnell in MATLAB Answers
Última actividad el 6 de Jun. de 2019

need to know how to retrieve local outdoor temperature in Celsius from say "openweathermap.org" or similar so that Thingspeak/MATLABThingspeak/MATLAB can use it to analyze ideal humidity? Thank you
Mark Clark in MATLAB Answers
Última actividad el 29 de Mzo. de 2019

Good Day I have a question on thingSpeakPlot. How do plot against time on the X axis. Im currently using plot shown below. The problem is when there is a power failure there may be less than 250 data points in that day which then gives an error. I would also like to include the current day which may only have a few data points. See https://thingspeak.com/channels/569794. Notice the time shift in the 3 day temperture comparison following power failure. thingSpeakPlot((1:250),allData,'legend',{'Yesterday','DBY','3DaysAgo',}, ... 'xlabel','Time Measurement number','YLabel','Temperature C', ... 'Title','3-Day Temperature Comparison');

Acerca de 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.