Open rburghol opened 3 years ago
Installing Guzzle:
# intall and ebable curl php extension
sudo apt-get install php5-curl
sudo apachectl restart
# See: https://guzzle3.readthedocs.io/getting-started/installation.html
# install composer is this needed or is only the php one?
sudo apt-get install composer
# composer php install. This is needed, is the previous?
cd /var/www/d.live
curl -sS https://getcomposer.org/installer | php
# install guzzle - see also: https://guzzle3.readthedocs.io/getting-started/installation.html
composer require guzzlehttp/guzzle
Then, we can test Guzzle with this:
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client([
// Base URI is used with relative requests
'base_uri' => 'http://httpbin.org',
// You can set any number of default request options.
'timeout' => 2.0,
]);
dpm($client,'client');
?>
NOTE: UPdated 9/15/2021, changed httr command from "GET" to "POST" @hdaniel7 the following doesn't work, but it gets a small foundation based on the hydrotools rest code. The contents of "/opt/model/config.private" is that json string with username and password. Hope it is helpful:
library("rjson")
site = "https://webservice.hobolink.com"
client_info <- rjson::fromJSON(file="/opt/model/config.private")
username <- as.character(client_info$onset_client_id)
userpass <- as.character(client_info$onset_client_secret)
inputs <- list(
client_id = username,
client_secret = userpass
)
hobo_rest <- httr::POST(
paste0(site, "/","ws/auth/token"),
query = inputs,
encode = "json"
);
httr::content(hobo_rest)
Yo @hdaniel7 !! I got it, this works to get the token (what we do with the toke after is anyone's guess!):
hobo_rest <- httr::POST(
paste0(site, "/","ws/auth/token"),
encode = "form",
httr::content_type("application/x-www-form-urlencoded"),
query = inputs
);
httr::content(hobo_rest)
Great to know! I haven't had a chance to dig further into it but I'll try to figure how to utilize the token in the coming days
On Wed, Sep 15, 2021, 2:19 PM rburghol @.***> wrote:
Yo @hdaniel7 https://github.com/hdaniel7 !! I got it, this works to get the token (what we do with the toke after is anyone's guess!):
hobo_rest <- httr::POST( paste0(site, "/","ws/auth/token"), encode = "form", httr::content_type("application/x-www-form-urlencoded"), query = inputs
);
httr::content(hobo_rest)
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/rburghol/om_agman/issues/278#issuecomment-920266837, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIXJA62OAGOYW7U4YULWXBLUCDPTFANCNFSM44DPQOWQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
interestingly enough, the chunk of code you posted doesn't seem to work for me -- running it gives me the error "Error in curl::curl_fetch_memory(url, handle = handle) : Protocol "" not supported or disabled in libcurl". Digging into it a bit, it seems to take issue with the query parameter and the lack of a body parameter -- to make sure I understand what exactly the parameters were doing, I changed it into
hobo_rest <- httr::POST( url = paste0(site, "/","ws/auth/token"), encode = "form", config = httr::content_type("application/x-www-form-urlencoded"), query = inputs
);
httr::content(hobo_rest)
and am having the same issue. Interestingly enough, if I add a body parameter and comment out the query parameter (i.e.
hobo_rest <- httr::POST( url = paste0(site, "/","ws/auth/token"), encode = "form", config = httr::content_type("application/x-www-form-urlencoded"),
body = 'hi'
);
it seems to at least communicate with the site, even if I get an error 405 (method not allowed) returned instead of anything useful. Any ideas why it's working for you and not for me? Looking at some of the old hydro_tools code, it became readily apparent that you've used code with very similar syntax before that worked perfectly... so I'm a bit confused as to why I'm struggling so much to get this to function. Perhaps you're using some package besides curl as the libcurl binding?
Looking ahead, I realized that I'll probably need the serial number of the HOBO device in order to test any code after I'm successfully able to get a token -- could you send that my way or put it in the authentification document on the drive or something when you have a chance?
@hdaniel7 - the loggerid you can use is 20622331 as for the connection issue, 2 things:
body = inputs
From my read of that error message, it is saying that something with the library "curl" that your machine is using does not allow and empty protocol. Looking at my code, it appears that I added an additional variable in the inputs list, which may be the reason that the protocol fails. An updated set of code that is working for me is below:
library("rjson")
site = "https://webservice.hobolink.com"
client_info <- rjson::fromJSON(file="/opt/model/config.private")
username <- as.character(client_info$onset_client_id)
userpass <- as.character(client_info$onset_client_secret)
inputs <- list(
client_id = username,
client_secret = userpass,
grant_type = 'client_credentials'
)
hobo_rest <- httr::POST(
paste0(site, "/","ws/auth/token"),
encode = "form",
httr::content_type("application/x-www-form-urlencoded"),
query = inputs
);
hobo_response <- httr::content(hobo_rest)
access_token <- hobo_response$access_token
If that doesn't work, it suggests to me that maybe there is some version information that has changed, or perhaps that I have some setting on my machine that is separate from yours. In other words, it does not seem, to me, that the error message is coming from the server at hobolink. Especially since I have successfully authenticated with the same code, and gotten the authentication token back from them. But anyhow, pop that up there.
Backup copy of the V3 HOBOlink web developer's guide -- just in case they move it around or get rid of it again: 25113-A HOBOlink Web Services V3 Developer's Guide.pdf
Tasks:
Use
Rscript modules/dh_weather/src/r/get_hobo_ts.R 6920 dh_feature 7451 20622331 "2022-12-09 00:00:00" "2022-12-09 23:59:59" /tmp/dh_weather_6920.txt
Use: catch_up_hobo past_days fid hobo_logger_id hobo_uid single_day=0(0/1)
./catch_up_hobo 16 6920 20622331 7451 0
drush scr modules/dh_weather/src/summarise_last24.php [entity type] [entity id]
drush scr modules/dh_weather/src/summarise_last24.php dh_feature 6920
hobo_userid
property andhobo_logger
property)Call Each Sensor Update (from file list)
Generate list of devices
Data Model
This needs to have an updated model to handle the new station config (single sensor instead of multiple as before). But for now it is keeping the old method.
R Oauth token access
Code 1: Download data from HOBO.
PHP Testing:
R Code Dev:
HOBO Station REST Documentation:
Drupal REST client