# Publishing gps data to cloud (NEO6mv)

**URL:** https://community.particle.io/t/publishing-gps-data-to-cloud-neo6mv/46790
**Category:** General
**Created:** [January 6, 2019, 5:41am UTC](https://community.particle.io/t/publishing-gps-data-to-cloud-neo6mv/46790 "2019-01-06T05:41:06Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![lunchboxp](https://avatars.discourse-cdn.com/v4/letter/l/3d9bf3/32.png) [@lunchboxp](https://community.particle.io/u/lunchboxp)
#### Post date: [January 6, 2019, 5:41am UTC](https://community.particle.io/t/publishing-gps-data-to-cloud-neo6mv/46790/1 "2019-01-06T05:41:06Z")

</div>

For the following code I am implementing a light sensor and a gps. The light sensor works fine, but I’m having trouble with the gps. It can’t seem to get the long and lat values for some reason…? (It just returns invalid) When I use the example code from the tinygps library though, the correct data is sent via serial to putty. Any ideas? Thank you so much in advance!

 ![Capture](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/9/d/9dc12c8dfaabed877d9bb2f7d2eb2a1c793edd47.PNG)  
PS Also, is there a way to send the long and lat values in one publish command rather than two?

---

<div class="post-metadata">

### Author: ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)
#### Post date: [January 6, 2019, 9:07am UTC](https://community.particle.io/t/publishing-gps-data-to-cloud-neo6mv/46790/2 "2019-01-06T09:07:18Z")

</div>

The GPS device continously sends data via the serial connection to the microcontroller but your code needs to read that data and feed it into the library via `gps.encode()` for the library to parse it. I can't see your code doing any of that.

> [@lunchboxp](#):
>
> PS Also, is there a way to send the long and lat values in one publish command rather than two?

Yes, the common way to wrap multiple variables into one string goes via `snprintf()`

> [@Publishing several fields in one event](https://community.particle.io/t/publishing-several-fields-in-one-event/33121/4):
>
> For float and double input variables snprintf() would require you to use something like "%.1f" instead of "%u". snprintf() uses the same formatting pattern as [printf()](http://www.cplusplus.com/reference/cstdio/printf/) %u stands for unsigned decimal integer - meaning an integer input type not to be confused with the output format.

---

<div class="post-metadata">

### Author: ![Rftop](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rftop/32/16896_2.png) [@Rftop](https://community.particle.io/u/Rftop)
#### Post date: [January 6, 2019, 1:43pm UTC](https://community.particle.io/t/publishing-gps-data-to-cloud-neo6mv/46790/3 "2019-01-06T13:43:41Z")

</div>

> [@lunchboxp](#):
>
> PS Also, is there a way to send the long and lat values in one publish command rather than two?

You may want to start with one of the example files in the Library that you're using to get started, and add your Light Sensor to it:

> **[Particle Web IDE](https://build.particle.io/libs/AssetTrackerRK/0.1.7/tab/example/1_SimpleGPS.cpp)**
>
> Write and flash code to your Particle devices

It makes use of snprintf(), as ScruffR suggests:

```cpp
char buf[128];
if (gps.location.isValid() && gps.location.age() < MAX_GPS_AGE_MS) {
  snprintf(buf, sizeof(buf), "%f,%f,%f", gps.location.lat(), gps.location.lng(), gps.altitude.meters() );
  Particle.publish("gps", buf);
}

```

You can swap your light() variable for gps.altitude, but remember to change the 3'rd (%f) to (%i) in the snprintf.  
Something like:

```auto
snprintf(buf, sizeof(buf), "%f, %f, %i", gps.location.lat(), gps.location.lng(), light() );

```

---

<div class="post-metadata">

### Author: ![lunchboxp](https://avatars.discourse-cdn.com/v4/letter/l/3d9bf3/32.png) [@lunchboxp](https://community.particle.io/u/lunchboxp)
#### Post date: [January 6, 2019, 5:16pm UTC](https://community.particle.io/t/publishing-gps-data-to-cloud-neo6mv/46790/4 "2019-01-06T17:16:23Z")

</div>

This is the gps code I have that works for when my electron is connected to my computer via USB. I’d like for my gps to work solely via battery (no USB connection) though, so I thought I would need to get rid of the serial prints/reads. If that is the case, how would I get the gps data (from gps.encode()) without having a usb connection?

 ![Capture](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/c/c/cc3ef3b87be41f10238ff9c1f60c89b90ac55151.PNG)

---

<div class="post-metadata">

### Author: ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)
#### Post date: [January 6, 2019, 5:27pm UTC](https://community.particle.io/t/publishing-gps-data-to-cloud-neo6mv/46790/5 "2019-01-06T17:27:09Z")

</div>

`Serial1` has nothing to do with USB but is the way the controller and the GPS module communicate - you **_need_** to keep that.  
And even if there is no connection to your computer, the `Serial.xxx()` functions won’t interfere - so just leave them there.  
Don’t confuse/conflate `Serial` and `Serial1` - they are two different interfaces.

But to get the data off of your device into the world, then you may want to look into the docs regarding [`Particle.publish()`](https://docs.particle.io/reference/device-os/firmware/electron/#particle-publish-)
