GPS pubnub communication

#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#include <SPI.h>
#include <Ethernet.h>
#include <PubNub.h>
#include "pitches.h"
#include "string.h"


SoftwareSerial serial_connection(10,11);
TinyGPSPlus gps;


const int buttonPin = 2;  
int buttonState = 0;

byte mac[] = {0x00, 0x0E, 0xEF, 0x00, 0x00, 0x34}; 
// do not change the 0x00 0x0E 0xEF 0x00 0x00 prefix


char pubkey[] = "*************************";
char subkey[] = "****************************";
char channel[] = "iotchannel";

void setup()
{
  

  Serial.begin(9600);
  serial_connection.begin(9600);
  Serial.println("Serial set up");


  while (!Ethernet.begin(mac)) 
  {
    Serial.println("ethernet setup error");
    delay(10);
  }
  
  pinMode(buttonPin, INPUT);

  PubNub.begin(pubkey, subkey);
  Serial.println("PubNub set up");
}


void loop()
{

  buttonState = digitalRead(buttonPin);
  
  Ethernet.maintain();

  EthernetClient *client;

 while(serial_connection.available())
  {
    gps.encode(serial_connection.read());
  }

 if(gps.location.isUpdated())
{
  Serial.println("Satellite Count:");
  Serial.println(gps.location.lat(),3);
}
  

 char msg[32] = "{\"eon\":{\"sensor\":";
 char msglng[32] = "{\"0";
 
  dtostrf(gps.location.lng(),3,3,msglng);
  sprintf(msg + strlen(msg), msglng);
   strcat(msg, "}}");

  Serial.print("publishing message: ");
  Serial.println(msg);
  client = PubNub.publish(channel, msg);
  if (!client) {
    Serial.println("publishing error");
  } else {
    client->stop();
  }

 

delay(500);
}

Hi, trying to my arduino to publish data with pubnub but it seems that if(gps.location.isUpdated()) and while (!Ethernet.begin(mac)) are not playing ball. when I remove !Ethernet.begin I get this printed in serial:
19:06:12.917 → publishing message: {“eon”:{“sensor”:-2.586}}
19:06:12.984 → publishing error

when I put !Ethernet.begin back into the code I get this:
19:08:38.144 → publishing message: {“eon”:{“sensor”:0.000}}
It is publishing fine as i can see on my pubnub analytics.

any help appreciated thanks :slight_smile:

Have you played with "gps.location.isUpdated()" alone? My first GPS project used TinyGPS and I thought I understood what was meant by the documentation. In debugging at that time, by printing the return of gps.location.isUpdated() I learned it did not mean what I thought it meant or behave as I thought it should have. If you have a GPS that outputs NMEA GPRMC once a second, even with half the fields empty, gps.location.isUpdated() returns true. Another means is necessary to validate the data decoded.