problem when upload location data | General | Forum

Avatar

Please consider registering
Guest

Search

— Forum Scope —






— Match —





— Forum Options —





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

Register Lost password?
sp_Feed sp_TopicIcon
problem when upload location data
Avatar
alessio31183

Silver
Forum Posts: 6
sp_UserOfflineSmall Offline
1
November 10, 2014 - 4:42 am
sp_Permalink sp_Print

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

Avatar
lee

Forum Posts: 457
sp_UserOfflineSmall Offline
2
November 10, 2014 - 8:42 am
sp_Permalink sp_Print

Hi,

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

lee

Avatar
alessio31183

Silver
Forum Posts: 6
sp_UserOfflineSmall Offline
3
November 13, 2014 - 4:35 am
sp_Permalink sp_Print

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

Avatar
lee

Forum Posts: 457
sp_UserOfflineSmall Offline
4
November 13, 2014 - 9:08 am
sp_Permalink sp_Print

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

Avatar
Hans
Natick, MA

Forum Posts: 390
sp_UserOfflineSmall Offline
5
November 13, 2014 - 10:49 am
sp_Permalink sp_Print

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

Avatar
alessio31183

Silver
Forum Posts: 6
sp_UserOfflineSmall Offline
6
November 18, 2014 - 4:13 am
sp_Permalink sp_Print

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?

Avatar
alessio31183

Silver
Forum Posts: 6
sp_UserOfflineSmall Offline
7
November 18, 2014 - 4:14 am
sp_Permalink sp_Print

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

Avatar
lee

Forum Posts: 457
sp_UserOfflineSmall Offline
8
November 18, 2014 - 8:58 am
sp_Permalink sp_Print

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

lee

Avatar
alessio31183

Silver
Forum Posts: 6
sp_UserOfflineSmall Offline
9
November 18, 2014 - 10:26 am
sp_Permalink sp_Print

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?

Avatar
lee

Forum Posts: 457
sp_UserOfflineSmall Offline
10
November 18, 2014 - 2:58 pm
sp_Permalink sp_Print

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

Avatar
alessio31183

Silver
Forum Posts: 6
sp_UserOfflineSmall Offline
11
November 19, 2014 - 7:21 am
sp_Permalink sp_Print

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

Avatar
Things4U
New Member
Forum Posts: 1
sp_UserOfflineSmall Offline
12
February 25, 2016 - 6:46 am
sp_Permalink sp_Print

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,

Avatar
testing
New Member
Forum Posts: 1
sp_UserOfflineSmall Offline
13
July 17, 2017 - 5:21 pm
sp_Permalink sp_Print

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. 

Avatar
cstapels

Gold
Forum Posts: 129
sp_UserOfflineSmall Offline
14
July 18, 2017 - 8:35 am
sp_Permalink sp_Print

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: acemarie
22 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 252

Vinod: 164

cstapels: 96

piajola: 75

vespapierre: 63

Adarsh_Murthy: 59

Newest Members:

acemarie

CecilApolf

Detmeblap

Viewport Tech

bessiefi3

GuestBeigh

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee