Skip to content

Erroneous string format using mosquitto_sub/_pub #15123

@chris-steema

Description

@chris-steema

Steps to reproduce

Run the following *.ps1 script in a text file with UTF-8 ecoding:

while ($true)
{ 
  $date = Get-Date -Format "o"
  $rand = Get-Random -Minimum -10 -Maximum 40
  $message = '{"time":' + '"' + "$date" + '"' + ', "value":' + "$rand" + ', "label":"ºC"}'
  #echo "$message"
  mosquitto_pub -h test.mosquitto.org -t tofol/test -m "$message"
  Start-Sleep -s 1
}

Now in another terminal window, subscribe to the mosquitto topic:

mosquitto_sub -h test.mosquitto.org -t tofol/test

The output is unexpected:

{time:2021-03-30T12:30:24.0266957+02:00, value:3, label:║C}

Expected behavior

Expected behavior is seem by running the following script:

while ($true)
{ 
  $date = Get-Date -Format "o"
  $rand = Get-Random -Minimum -10 -Maximum 40
  $message = '{"time":' + '"' + "$date" + '"' + ', "value":' + "$rand" + ', "label":"ºC"}'
  echo "$message"
  #mosquitto_pub -h test.mosquitto.org -t tofol/test -m "$message"
  Start-Sleep -s 1
}

This outputs:
{"time":"2021-03-30T12:31:48.2728626+02:00", "value":33, "label":"ºC"}

Environment data

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.19041
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions