problem when upload location data | General | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
problem when upload location data
No permission to create posts
November 10, 2014
4:42 am
Avatar
alessio31183

Silver
Members
Forum Posts: 6
Member Since:
November 10, 2014
sp_UserOfflineSmall Offline

Hi every one,
I'm developing some sensor nodes that measure some parameter for the air quality monitoring and upload data on thingspeak platform.
This is the channel: https://thingspeak.com/channels/17333
The issue is that I'm trying to upload also the position with latitude, longitude and elevation attribute but I don't see the correct data on my node.
This is a part of my .py code:

import httplib, urllib

__version__ = '0.1.1'

NUMOFCHANNELS = 8
field_keys = ['field' + str(n) for n in xrange(1,NUMOFCHANNELS+1)]
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}

def non_null_values(**kwargs):
return [(k,v) for (k,v) in kwargs.iteritems() if v != None]

class wrongFields(ValueError):
pass

class channel(object):
def __init__(self, write_key, cid=0 ):
"""write_key is the Write API Key.
cid is the read_key"""
self.write_key = write_key

def update(self, field_vals, lat=None, long=None, elevation=None, status=None):
if len(field_vals) != NUMOFCHANNELS:
raise wrongFields('update can only handle NUMOFCHANNELS field values per channel')
# this verbosity, rather than just using kwargs,
# so that callers get a prompt error if they supply an arg `update` cannot handle
named_args = non_null_values(lat=lat, long=long, elevation=elevation, status=status)
print named_args #FOR DEBUG ONLY
params = urllib.urlencode(zip(field_keys, field_vals) + [('key', self.write_key)] + named_args)
conn = httplib.HTTPConnection("api.thingspeak.com:80")
conn.request("POST", "/update", params, headers)
response = conn.getresponse()
conn.close()
return response

def fetch(self, format):
conn = httplib.HTTPConnection("api.thingspeak.com:80")
path = "/channels/{0}/feed.{1}".format(self.cid, format)
params = urllib.urlencode([('key',self.key)])
conn.request("GET", path, params, headers)
response = conn.getresponse()
return response

when I create th string to upload data by HTTP request I obtain something like this:
field1=(Field 1 Data)&field2=(Field 2 Data)&field3=(Field 3 Data)&field4=(Field 4 Data)&field5=(Field 5 Data)&field6=(Field 6 Data)&field7=(Field 7 Data)&field8=(Field 8 Data)&lat=(Latitude in Decimal Degrees)&long=(Longitude in Decimal Degrees)&elevation=(Elevation in meters)&status=(140 Character Message)

Every channel works correctly, also the status field, but the location is wrong.
I don't know what's the problem regarding.....

Any help?

Thanks in advance guys

November 10, 2014
8:42 am
Avatar
lee

Admin
Forum Posts: 457
Member Since:
March 14, 2011
sp_UserOfflineSmall Offline

Hi,

Are you including the parameter "location=true" when retrieving your Channel feed? https://thingspeak.com/docs/channels#get_feed

lee

November 13, 2014
4:35 am
Avatar
alessio31183

Silver
Members
Forum Posts: 6
Member Since:
November 10, 2014
sp_UserOfflineSmall Offline

Yes,
I send out a message like this one:
field6=33.4&field1=23.0&long=51.490664&location=true&lat=25.375852&elevation=19&field8=0.0&key=**************

But it doesn't work, the location isn't updateCryCry
this is the channel: https://thingspeak.com/channels/17333

Thanks

November 13, 2014
9:08 am
Avatar
lee

Admin
Forum Posts: 457
Member Since:
March 14, 2011
sp_UserOfflineSmall Offline

Hi,

I don't see any data in your Channel, are you sure you are adding the data correctly? Is the HTTP request sent properly with an API key?

lee

November 13, 2014
10:49 am
Avatar
Hans
Natick, MA

Admin
Forum Posts: 396
Member Since:
January 18, 2011
sp_UserOfflineSmall Offline

Use "location=true" when reading the data back from your channel.

November 18, 2014
4:13 am
Avatar
alessio31183

Silver
Members
Forum Posts: 6
Member Since:
November 10, 2014
sp_UserOfflineSmall Offline

lee said

Hi,

I don't see any data in your Channel, are you sure you are adding the data correctly? Is the HTTP request sent properly with an API key?

lee

Yes, I'm sure, you can see data in the channel.
Why don't you see data?

November 18, 2014
4:14 am
Avatar
alessio31183

Silver
Members
Forum Posts: 6
Member Since:
November 10, 2014
sp_UserOfflineSmall Offline

Hans said

Use "location=true" when reading the data back from your channel.

...but my question is: why the location data doesn't upload correctly?
I don't want read location data but write the location of my node and see it on the map

November 18, 2014
8:58 am
Avatar
lee

Admin
Forum Posts: 457
Member Since:
March 14, 2011
sp_UserOfflineSmall Offline

Your location data is being updated correctly, you can see it here: https://thingspeak.com/channels/17333/feed.json?results=5&location=true .

lee

November 18, 2014
10:26 am
Avatar
alessio31183

Silver
Members
Forum Posts: 6
Member Since:
November 10, 2014
sp_UserOfflineSmall Offline

lee said

Your location data is being updated correctly, you can see it here: https://thingspeak.com/channels/17333/feed.json?results=5&location=true .

lee

Thank you lee, but why I don't see the map and the correct position in the public channel view?

November 18, 2014
2:58 pm
Avatar
lee

Admin
Forum Posts: 457
Member Since:
March 14, 2011
sp_UserOfflineSmall Offline

Hi,

The map is based on the Channel's latitude and longitude, which is configured under the "Channel Settings" tab. This is different from the Channel feed's latitude and longitude, which is updated via the API (as you're doing now).

We don't currently have a visualization for the feed locations, but may add one in the future which would display a path of the updates on a map.

lee

November 19, 2014
7:21 am
Avatar
alessio31183

Silver
Members
Forum Posts: 6
Member Since:
November 10, 2014
sp_UserOfflineSmall Offline

lee said

Hi,

The map is based on the Channel's latitude and longitude, which is configured under the "Channel Settings" tab. This is different from the Channel feed's latitude and longitude, which is updated via the API (as you're doing now).

We don't currently have a visualization for the feed locations, but may add one in the future which would display a path of the updates on a map.

lee

Ok, thank you lee
Now everything is clear.
I think that a map's visualization based on the feed locations it will be very useful for the future.
thinking about a node with a GPS module onboard...........that is moving from position to position

Thanks

Alessio

February 25, 2016
6:46 am
Avatar
Things4U
New Member
Members
Forum Posts: 1
Member Since:
February 8, 2016
sp_UserOfflineSmall Offline

A long time has past since last post. Are there still plans to add updates to the map?
GPS location and map view is one of the most important functions when showing people how their IoT are doing and where they are.
It should not be too difiicult to add this function to the existing show map view, I'm surprised it takes so long.

If not, I need to start looking for another platform...

Thanks,

Maarten,

July 17, 2017
5:21 pm
Avatar
testing
New Member
Members
Forum Posts: 1
Member Since:
July 17, 2017
sp_UserOfflineSmall Offline

Hello, I need to do something similar- is there a way to automatically update the map that is already on the Channel Stats page with lat/lon data that is coming in from a RockBlock unit? Else, what is the other solution- create a Google Map api and read the Thingspeak data into that as a ThingHTTP? Thank you for any help. 

July 18, 2017
8:35 am
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 209
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

If you have access to MATLAB mapping toolbox you can use that to create a visualization, as described here.

The map that is already on the channel stats page has your channel location data, not field location data from posts - you would need the user API key the data would not relate to field data on you channel.  You can update the channel location as described in update a channel.  If you are updating the field location, it wont change the channel stats map, but that information is here: update a channel feed.

You could also create a plugin in ThingSpeak using the google maps API (you will have to get an API key from google here).  Here is javascript example code to read data from a channel and make a route map:

<script>
setInterval('getData()', 20000); //refresh the page every 20 s
setTimeout('getData()', 2000); //wait for the data to be available before the first load
var lat; //lattitude holder
var lng; //longitude holder
var mySpot; //present marker location
var channel_id = YOUR_CHEER_CHANNELID; // set your channel id here
var api_key = 'YOUR_THINGSPEAK_READ_APIKEY'; // set your channel's read api key here if necessary
var route = []; //route array
var map; //must make map a global since you reuse it each refresh

function getData() { // get the data from thingspeak and format it in route object
$.getJSON('https://api.thingspeak.com/channels/' + channel_id + '/fields/1.json?api_key=' + api_key + '&location=true&start=%200:0:0&timezone=America%2FNew_York', function(data) {
var count = 0; //loop counter
route = []; //all the places you have been
for (var prop in data.feeds) { //loop through all feeds

if (data.feeds.hasOwnProperty(prop)) { //if there is a value
lat = parseFloat(data.feeds[count].latitude); //get the lat
lng = parseFloat(data.feeds[count].longitude); //get the lng
route.push({
lat,
lng
}) //add it to the array
mySpot = {
lat: lat,
lng: lng
}; //save the last values to write a marker
count++;
}
}

if (data.feeds.length) {
document.getElementById('message').innerHTML = ""; //leave the message blank
updateMap(); //update the route
} else {
document.getElementById('message').innerHTML = "<h4>Press and Hold the Button to Reset</h4>"; //leave a message to press the button
} })
.fail(function(){alert("Error reading Thingspeak channel");
});
}
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 2,
center: {
lat: 0, //on startup center map
lng: 0
}
});
}

function updateMap() {
//add a new marker at the present location
var marker = new google.maps.Marker({
position: mySpot, //put a marker down at myspot
map: map
});

//add a new flightpath to the map
var flightPath = new google.maps.Polyline({

path: route,
geodesic: true,
strokeColor: '#FF0F00',
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
} </script>

 

Here is the html

<!DOCTYPE html>
<html>
<head>
<style>
#map {
height: 400px;
width: 100%;
}
</style>
</head>
<body>
<div id="message"></div>
<div id="map"></div>
%%PLUGIN_JAVASCRIPT%%
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR GOOGLE API KEY&callback=initMap">
</script>
</body>
</html>

here is the CSS

<style type="text/css"> body { background-color: #ddd; } #container { height: 100%; width: 100%; display: table; } #inner { vertical-align: middle; display: table-cell; } #g_map { }</style>

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
17 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

josephrj11, dennis55, jillhp4, tabathawg69, MarinaMa, Susandom

Administrators: Hans: 387, lee: 457