Which datetime PHP format should I use best?

More
2 years 1 month ago - 2 years 1 month ago #6238 by DonZalmrol
Hi,

From the radmon.org API topic I see that "datetime" can be used to upload your precise datetime of your logging entry into the Radmon DB.
https://radmon.org/index.php/forum/howtos-and-faqs/864-radmon-org-api

Under the notes it says

The datetime parameter should be in a PHP parseable format. It is for uploading data that is stored due to intermittent network access.

Since my current connection is a bit intermittent I would like to start using this.
When I upload the Unix epoch time I get a 400 (Bad Request response status code) error for my upload, which is odd as an epoch should be an accepted PHP format. If this is not the case, what notation for date & time should I use best?

My code is simple, so that should not be the issue at hand, and when I comment the datetime part it works fine like it always has.
// Upload data to the RadMon.org server
static void connecToRadMonLogger(void)
{
  esp_task_wdt_add(NULL);
 
  WiFiClient wifi;
  HttpClient client = HttpClient(wifi, "radmon.org", 80);

  Serial.println(F("Connection to radmon monitoring platform succeeded!"));

  // Concat data for POST
  // API URL
  String ptr = "/radmon.php?function=submit";
  ptr += "&user=";
  ptr += UserName;
  ptr += "&password=";
  ptr += DataSendingPassWord;
  ptr += "&value=";
  ptr += String(cpm);
  ptr += "&unit=CPM";
  ptr += "&datetime=";
  ptr += String(epoch);

  // Test output
  //Serial.println("Uploaded CPM = " + String(cpm));
  Serial.println("created PTR = " + ptr);

  client.beginRequest();
  client.post(ptr);
  client.sendHeader("Content-Type", "application/x-www-form-urlencoded");
  client.sendHeader("Content-Length", ptr.length());
  client.beginBody();
  client.print("");
  client.endRequest();

  // read the status code and body of the response
  statusCodeRadmon = client.responseStatusCode();

  // Give the client some time to stop
  yield();

  esp_task_wdt_delete(NULL);
 
  Serial.println(F("Connection to radmon monitoring platform Disconnected."));
  Serial.println(F("\n"));
}

Thanks!
Last edit: 2 years 1 month ago by DonZalmrol. Reason: wrong code formatting

Please Log in or Create an account to join the conversation.

More
2 years 1 week ago #6264 by Simomax
It is not required that you POST the datetime as the Radmon server does this automatically when submitting a CPM value.

PHP datetime without additional formatting is generally as 'Y-m-d H:i:s', so now would be '2022-11-12 10:19:32'. However, I don't know if this is the exact format that Radmon expects as I have never used it. In the API documentation it states 'The datetime parameter should be in a PHP parseable format. It is for uploading data that is stored due to intermittent network access.' Unless you are working offline then unloading a bulk of readings to Radmon then the datetime field is not required, is my understanding.

Please Log in or Create an account to join the conversation.

Moderators: Gamma-Man
Time to create page: 0.126 seconds
Powered by Kunena Forum
Everything's free. Please support us by considering a donation. Log in first!
Solar powered Raspberry Pi 4 server stats: CPU 32% Memory 22% Swap 70% CPU temp=49.1'C Uptime 72 Days