[SOLVED] Photon Weather Station not uploading to WUnderground

For the past 9 - 11 months I have had this home built weather station running on a photon. I’ve had little problem with it but recently, on Feb. 2 the upload protocol was working but nothing is being posted to WUndergound. I use TCPClient to send the data stream and was working with no problem. I was trying to get a result string to be returned so I could see what the problem is but was unable to get the client.read() to work correctly. Here is my code. Any help would be greatly appreciated.

TCPClient client;
char SERVER[] = "weatherstation.wunderground.com"; //https://weatherstation.wunderground.com
char WEBPAGE [] = "GET /weatherstation/updateweatherstation.php?"; ///weatherstation/updateweatherstation.php?
//char WEBPAGE [] = "/weatherstation/updateweatherstation.php?";
char ID [] = "KOKCLINT3";
//char SOFTVER [] = "&softwaretype=Arduino%20UNO%20version1&action=updateraw";
char SOFTVER [] = "&action=updateraw";
char PASSWORD [] = "";

float tempF = 32.0;
//float windDegrees = 180;
float humidityRH = 48.0;
float dewptf = 12.0;
float pressureKPa = 28;
//float rainIn = 0.00;
float windMPH = 14.0;
//float gustMPH = 25.0;
unsigned int timeNextPublish;
unsigned int publishPeriod = 30000;

void setup() {

void loop() {
    if(timeNextPublish <= millis()) {
        timeNextPublish = millis() + publishPeriod;

void publisToWUnderground(float tempF, float baromin, float dewptf, float humidityRH, float windMPH) {
   //Send data to Weather Underground
    if (client.connect(SERVER, 80)) { 
        Particle.publish("xDEBUG", "Sending Data...");
        // Ship it!
        //client.print("now");    //can use instead of RTC if sending in real time

        client.print(SOFTVER); //&realtime=1&rtfreq=2.5");//Rapid Fire
    } else {
        Particle.publish("xDEBUG", "Connection Failed");
}//End loop

What’s the result saying for Particle.publish()?

It does show that it’s sending data.

Hmm… Did you reupload the code to the Photon recently? Can you try pasting the entire url in a browser and see if data is send to WUnderground successfully?

1 Like

I did try pasting the entire url to wunderground and it works just as expected. for some reason the tcpclient is just no working. I may try httpclient

HTTPS is not supported

the https is an old commented out line. I need to remove it.

I recently switched from TCPClient to using WebHooks for my Wunderground functionality. Is this a possibility for you? Otherwise, I still have my code for my wunderground TCPClient setup, but it’s well ingrained into my weather station code. I could extract it for you, if required.

I’m actually considering going to using webhooks as well, it’s just finding the time to learn it. If you wouldn’t mind posting your code that would be great.

I don’t mind. The exact code that I use is:

(triggered every five seconds by a software timer):

  Particle.publish("app/output/data", String::format(
      "\"t\":%d,"       /* {{t}} timestamp */
          "%6.2f,"        /* {{d.0.0}} temp c */
          "%6.2f"         /* {{d.0.1}} temp f */
          "%6.2f,"        /* {{d.1.0}} dewpoint c */
          "%6.2f"         /* {{d.1.1}} dewpoint f */
        "%6.2f,"          /* {{d.2}} humidity percent */
          "%s,"        /* {{d.3.0}} windchill c */
          "%s"         /* {{d.3.1}} windchill f */
          "%7.2f,"        /* {{d.4.0}} pressure hpa */
          "%5.2f"         /* {{d.4.1}} pressure inhg */
          "%s,"        /* {{d.5.0}} heat index c */
          "%s"         /* {{d.5.1}} heat index f */
          "%s,"        /* {{d.6.0}} humidex c */
          "%s"         /* {{d.6.1}} humidex f */
            "%3d,"      /* {{d.7.0.0}} wind, current, direction degrees */
            "%5.2f,"      /* {{d.7.0.1}} wind, current, speed m/s */
            "%5.1f,"      /* {{d.7.0.2}} wind, current, speed kmh */
            "%5.1f"       /* {{d.7.0.3}} wind, current, speed mph */
            "%3d,"      /* {{d.7.1.0}} wind, average 2m, direction degrees */
            "%5.2f,"      /* {{d.7.1.1}} wind, average 2m, speed m/s */
            "%5.1f,"      /* {{d.7.1.2}} wind, average 2m, speed kmh */
            "%5.1f"       /* {{d.7.1.3}} wind, average 2m, speed mph */
            "%3d,"      /* {{d.7.2.0}} wind, gust 10m, direction degrees */
            "%5.2f,"      /* {{d.7.2.1}} wind, gust 10m, speed m/s */
            "%5.1f,"      /* {{d.7.2.2}} wind, gust 10m, speed kmh */
            "%5.1f"       /* {{d.7.2.3}} wind, gust 10m, speed mph */
            "%5.2f,"    /* {{d.8.0.0}} rain, 1h, mm */
            "%4.2f"     /* {{d.8.0.1}} rain, 1h, in */
            "%5.2f,"    /* {{d.8.1.0}} rain, 6h, mm */
            "%4.2f"     /* {{d.8.1.1}} rain, 6h, in */
            "%5.2f,"    /* {{d.8.2.0}} rain, 24h, mm */
            "%4.2f"     /* {{d.8.2.1}} rain, 24h, in */
            "%5.2f,"    /* {{d.8.3.0}} rain, since midnight, mm */
            "%4.2f"     /* {{d.8.3.1}} rain, since midnight, in */
    data.humidity.percent > 100.00? 100.00 : data.humidity.percent,
    isnan(data.windchill.celsius)? "null" : String::format("%6.2f", data.windchill.celsius).c_str(),
    isnan(data.windchill.fahrenheit)? "null" : String::format("%6.2f", data.windchill.fahrenheit).c_str(),
    isnan(data.heatindex.celsius)? "null" : String::format("%6.2f", data.heatindex.celsius).c_str(),
    isnan(data.heatindex.fahrenheit)? "null" : String::format("%6.2f", data.heatindex.fahrenheit).c_str(),
    isnan(data.humidex.celsius)? "null" : String::format("%6.2f", data.humidex.celsius).c_str(),
    isnan(data.humidex.fahrenheit)? "null" : String::format("%6.2f", data.humidex.fahrenheit).c_str(),
    data.wind.speed.kilometersPerHour * 0.2777778, /* quick & dirty conversion */
    data.windAvg2m.speed.kilometersPerHour * 0.2777778, /* quick & dirty conversion */
    data.windGust10m.speed.kilometersPerHour * 0.2777778, /* quick & dirty conversion */
    ), 3600, PRIVATE);

I publish everything in both units so that multiple webhooks, that may publish to different places and require different units, can be used on the same publish. I would have made the JSON nicer, but there’s a pretty strict character limit for Particle Publishes, and this is about as good as I can get.

Adjust as necessary to use your own variables.

This is the webhook (edit as necessary):

    "deviceID": "<device id>",
    "event": "app/output/data",
    "mydevices": true,
    "integration_type": "Webhook",
    "url": "http://rtupdate.wunderground.com/weatherstation/updateweatherstation.php",
    "requestType": "GET",
    "query": {
      "rtfreq": "5",
      "realtime": "1",
      "action": "updateraw",
      "softwaretype": "Particle-Photon",
      "dailyrainin": "{{d.8.3.1}}",
      "rainin": "{{d.8.0.1}}",
      "windgustmph_10m": "{{d.7.2.3}}",
      "windgustdir_10m": "{{d.7.2.0}}",
      "windgustmph": "{{d.7.2.3}}",
      "windgustdir": "{{d.7.2.0}}",
      "windspdmph_avg2m": "{{d.7.1.3}}",
      "winddir_avg2m": "{{d.7.1.0}}",
      "windspeedmph": "{{d.7.0.3}}",
      "winddir": "{{d.7.0.0}}",
      "baromin": "{{d.4.1}}",
      "humidity": "{{d.2}}",
      "dewptf": "{{d.1.1}}",
      "tempf": "{{d.0.1}}",
      "dateutc": "now",
      "PASSWORD": "<wu password>",
      "ID": "<wu station ID>"
    "noDefaults": true,
    "rejectUnauthorized": false,
    "responseTopic": "hook/wu/success",
    "errorResponseTopic": "hook/wu/error"
1 Like

This Saturday I worked on the webhooks and was able to get the weatherstation to report again. Thanks for the help.


@bearloverhr, can you explain what the problem was with the webhook that your fixed?

@peekay123 I was not using a webhook in my original code, was using TCPClient to pass data to WUnderground. I actually have never worked with webhooks until this project.

1 Like

I have the exact same problem with an Electron and Weather under ground. It had been working for 10 months and then just stopped working. I was using TCP client also.

I looked at the webhook idea but don’t understand how to format my data for WU to display it. the code posted by legoguy is quite opaque to me…I did look at Particle docs for using Web hooks but it did not shed much light on my understanding what to do.

Thanks in advance for any advice!

David G.

I agree with you as well. I would greatly appreciate an explanation of his code for the Photon. I have a decent grasp on the code for the Webhook but I am still confused by the code for the Photon. How does the String::format work?

String::format() works the same way as printf() in C/C++

1 Like

Hi there,

A colleague recently brought this same issue to me; he too had a working station that had stopped sending data in early February. After looking at the code, it seemed to me that the HTTP GET request was incompletely formed. I removed the final println statement from the sendToWU() function in the code supplied by Sparkfun and replaced it with the following:

  client.print(" HTTP/1.0\nHost: ");
  client.println("\nContent-Length: 0\r\n\r\n");

That seems to work. My best guess is that someone updated something on the backend of Weather Underground and it would no longer accept the partial GET request.

Hope that helps someone.

  • Rob
1 Like

Where does the webhook go in the body of the code? void setup?

I have the same problem with my weather station: I cannot get TCPClient to work. @bearloverhr, could you paste your entire code from start to finish so I can see how the webhooks all fit together?

I’m sure there is a way to paste in the whole code, but I haven’t actually figured that out and my weatherstation code is near 550 lines. I’m going to give you the meat of what you are asking for.

I have the webhook call in a procedure that I call in the main loop, “void loop {”. That call is:


The procedure that I call is:

void publisToWUnderground(float tempF,float humidityRH,float dewptf,float pressureKPa,float windMPH,float gustMPH,float windDegrees,float rainIn,float dailyRainIn) {
   Particle.publish("app/output/data", String::format(
        ), 3600, PRIVATE);

Hope this helps.