Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get number of bytes of UTF-8 encoded POST payload #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion smartapps/influxdb-logger/influxdb-logger.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,12 @@ def handleEvent(evt) {

}

String getLength(String message) {
assert message instanceof String
return message.getBytes("UTF-8").size().toString()
}



/*****************************************************************************************************************
* Main Commands:
Expand Down Expand Up @@ -596,7 +602,10 @@ def logSystemProperties() {
* Uses hubAction instead of httpPost() in case InfluxDB server is on the same LAN as the Smartthings Hub.
**/
def postToInfluxDB(data) {
logger("postToInfluxDB(): Posting data to InfluxDB: Host: ${state.databaseHost}, Port: ${state.databasePort}, Database: ${state.databaseName}, Data: [${data}]","debug")
def length = getLength(data)
state.headers.put("Content-Length", length)

logger("postToInfluxDB(): Posting data to InfluxDB: Host: ${state.databaseHost}, Port: ${state.databasePort}, Database: ${state.databaseName}, Data: [${data}], Size: ${length}","debug")

try {
def hubAction = new physicalgraph.device.HubAction(
Expand Down