[SOLVED] Photon Weather Station not uploading to WUnderground

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 */
      "\"d\":["
        "["
          "%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 */
          "]"
        "]"
      "]"
    "}",
    Time.now(),
    data.temperatureBaro.celsius,
    data.temperatureBaro.fahrenheit,
    data.dewpoint.celsius,
    data.dewpoint.fahrenheit,
    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(),
    data.relativePressure.hectopascals,
    data.relativePressure.inchesOfMercury,
    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(),
    (int)data.wind.direction.degrees,
    data.wind.speed.kilometersPerHour * 0.2777778, /* quick & dirty conversion */
    data.wind.speed.kilometersPerHour,
    data.wind.speed.milesPerHour,
    (int)data.windAvg2m.direction.degrees,
    data.windAvg2m.speed.kilometersPerHour * 0.2777778, /* quick & dirty conversion */
    data.windAvg2m.speed.kilometersPerHour,
    data.windAvg2m.speed.milesPerHour,
    (int)data.windGust10m.direction.degrees,
    data.windGust10m.speed.kilometersPerHour * 0.2777778, /* quick & dirty conversion */
    data.windGust10m.speed.kilometersPerHour,
    data.windGust10m.speed.milesPerHour,
    data.rain.pastHour.millimeters,
    data.rain.pastHour.inches,
    data.rain.past6h.millimeters,
    data.rain.past6h.inches,
    data.rain.past24h.millimeters,
    data.rain.past24h.inches,
    data.rain.today.millimeters,
    data.rain.today.inches
    ), 3600, PRIVATE);
  }
  #endif

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.

2 Likes

@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.print(SERVER);
  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

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:

publisToWUnderground(tempF,humidityRH,dewptf,pressureKPa,windMPH,gustMPH,windDegrees,rainIn,rainPerDay);

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(
      "{"
        "\"d\":["
            "["
                "%6.2f,"
                "%6.2f,"
                "%6.2f,"
                "%7.2f,"
                "%5.1f,"
                "%5.1f,"
                "%5.1f,"
                "%4.2f,"
                "%4.2f"
            "]"
        "]"
        "}",
        tempF,
        humidityRH,
        dewptf,
        pressureKPa,
        windMPH,
        gustMPH,
        windDegrees,
        rainIn,
        dailyRainIn
        ), 3600, PRIVATE);
}

Hope this helps.

Ok, I’m getting closer. I’m using the Particle webhook builder. It is a very helpful tool, but I still don’t understand the code you offered, @legoguy. I pasted your code into the JSON builder and it shows nicely in the webhook builder tool. However, I still don’t understand how you define all your variables. Could you paste all your code including void setup and declaring all your variables??

For simplicity, my only sensor is a DHT22. I’ll only passing temp and humidity.
Thanks!

@bearloverhr, that helps. Possible that you can point me to how I can better understand to where 6.2f, 7.2f, 5.1f, etc point? I'm having a hard time understanding the terminology as I look through the Particle docs...

It’s if used for defining the how the variable will be displayed or recorded in the String::format.

In this example %6.2f means 6 digits with 2 decimal places that is used for a floating value. So n= 91.2345 would be recorded as ‘91.23’.

If n=1234567.2345 then what is recorded would be ‘234567.23’.

Why I use 6 digits is beyond me because you only need 3 digits for the temp (for normal weatherstation temps you should never be above 999, god help us all).

This way of formatting a string is not documented by Particle since this is a standard C feature which is widely documented already
e.g. http://www.cplusplus.com/reference/cstdio/printf/

Hence the Particle docs “only” provide a link

1 Like