I have run into a couple of string problems I don't understand, These could well be beginners silly issues - so I apologize in advance.
I would appreciate any helpful advice as I am completely stuck with these issues at the moment.
Issue a) Something is substituting groups of characters in a print statement:
I have a lua script for heating control and one function scans for and updates device IDs using a curl call. If I have a missing device I report the error in the log and give some helpful info as follows:
Code: Select all
print(string.format("try updating it from the real device or URL as follows"))
print(string.format("http://1.2.3.4:8080/json.htm?type=command¶m=udevice&idx=%d&nvalue=0&svalue=andywasere", zoneInfoIDX))
Issue b) Something is stripping whitespace.2016-03-22 12:12:00.308 LUA: try updating it from the real device or URL as follows
2016-03-22 12:12:00.308 LUA: http://1.2.3.4:8080/json.htm?type=comma ... andywasere
I use a text type device per zone for communicating a lot of general heating zone info from a mysensors battery thermostat. Part of that string is the zone name, which I try and pad to fixed length using spaces. Something is stripping all but the first space from the string. I have worked around it by using an underscore instead of space - but it looks untidy.
Example 1: Works using underscore
Code: Select all
local newZoneName = zoneName.."________"
newZoneInfo = string.format("%s%03d%03d%03d%c ",string.sub(newZoneName,1,12), newZoneTimer,
newHouseTimer,tonumber(newZoneSetpoint)*10,flgs1)
Example 2: Doesn't work using spaces
Code: Select all
local newZoneName = zoneName.." "
newZoneInfo = string.format("%s%03d%03d%03d%c ",string.sub(newZoneName,1,12), newZoneTimer,
newHouseTimer,tonumber(newZoneSetpoint)*10,flgs1)
Example 3: Doesn't work using spaces
Code: Select all
newZoneInfo = string.format("%-12s%03d%03d%03d%c ",zoneName, newZoneTimer,
newHouseTimer,tonumber(newZoneSetpoint)*10,flgs1)
Basically any way I can find of padding the zonename with spaces ONLY ever adds 1 space to the end output. If I pad the string to 20 characters with spaces and then check its length at that point it will correctly be 20. As soon as I use it in string.format it looses the last few spaces, leaving only 1