Skip to content

400 error when space is in value #83

@r0b0tb4c0n

Description

@r0b0tb4c0n

i get the following error when my window shade is partially open:
Status: 400, Error: Bad Request, Headers: [X-Influxdb-Error:metric parse error: expected field at 6:98: "windowShade,deviceName=Office\ Shade,deviceId=190,hubName=Home,unit=windowShade value="partially\ open",valueBinary=0i 1777933070012000000", Content-Length:444, Date:Mon, 04 May 2026 22:28:21 GMT, Content-Type:application/json], Data: null

i'm not using the advanced. Looking at the influx documentation:
https://docs.influxdata.com/influxdb/v1/write_protocols/line_protocol_reference/#special-characters
you only need to escape double quotes and backslash characters for string field values.

as a test i made this:

private String escapeFieldValueStringForInfluxDB(String str) {
    if (str == null) {
        return '"null"'
    }
    
    str = str.replaceAll("\\\\", "\\\\\\\\") // Escape backslashes
    str = str.replaceAll("\"", "\\\\\"")     // Escape double quotes
    
    return str
}

and then changed line 883 to this (showing line 882 and 883 below):

            // Everything else is a string.
            value = '"' + escapeFieldValueStringForInfluxDB(evt.value) + '"'

the errors stopped and data started flowing again. i was then able to check my db and the "partially open" value was there. I'd make a PR, but i'm not 100% sure that the change of line 883 is safe/won't cause unintended side-effects

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions