Skip to content

Commit eac6909

Browse files
committed
Merge branch 'feature/0.4'
2 parents 4c7dfa3 + 4671d78 commit eac6909

File tree

8 files changed

+262
-115
lines changed

8 files changed

+262
-115
lines changed

LogMessages.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
A copy of this file is included with the python script, so it can parse it to extract the log strings.
2424
The python script receives the messages as a few IDs and values in a JSON string.
2525
It uses this file to expand that to the full message.
26-
Not storing the full strings, but only the ID on the controller saves a lot of PROGMEM space.
26+
Not storing the full strings, but only the ID on the Arduino saves a lot of PROGMEM space.
2727
At startup the python script extracts the version number from this file and compares it to its own local copy.
2828
It will give a warning when the two strings do not match.
2929
*/
3030

3131
/* bump this version number when changing this file and copy the new version to the brewpi-script repository. */
32-
#define BREWPI_LOG_MESSAGES_VERSION 1
32+
#define BREWPI_LOG_MESSAGES_VERSION 2
3333

3434
#define MSG(errorID, errorString, ...) errorID
3535

@@ -52,12 +52,16 @@ enum errorMessages{
5252
// PiLink.cpp
5353
MSG(ERROR_EXPECTED_BRACKET, "Expected { got %c", character),
5454

55+
MSG(ERROR_ONEWIRE_INIT_FAILED, "OneWire initialization failed"),
56+
MSG(ERROR_DEVICE_ALREADY_INSTALLED, "This hardware device is already installed at slot %d. Uninstall it first.", slot),
57+
MSG(ERROR_FUNCTION_ALREADY_INSTALLED, "This device function is already installed at slot %d. Uninstall it first.", slot)
58+
5559
}; // END enum errorMessages
5660

5761
enum warningMessages{
5862
// PiLink.cpp
5963
MSG(WARNING_COULD_NOT_PROCESS_SETTING, "Could not process setting"),
60-
MSG(WARNING_INVALID_COMMAND, "Invalid command received by controller: %c", character),
64+
MSG(WARNING_INVALID_COMMAND, "Invalid command received by Arduino: %c", character),
6165

6266
// OneWireTempSensor.cpp
6367
MSG(WARNING_TEMP_SENSOR_DISCONNECTED, "Temperature sensor disconnected pin %d, address %s", pinNr, addressString),
@@ -82,7 +86,7 @@ enum infoMessages{
8286
MSG(INFO_INSTALL_SWITCH_SENSOR, "installing switch sensor with function %d", config.deviceFunction),
8387
MSG(INFO_INSTALL_DEVICE, "Installing device f=%d", config.deviceFunction),
8488
MSG(INFO_MATCHING_DEVICE, "Matching device at slot %d", out.slot),
85-
MSG(INFO_SETTING_ACTIVATOR_STATE, "Setting activator state %d", state),
89+
MSG(INFO_SETTING_ACTUATOR_VALUE, "Setting actuator value %d", val),
8690

8791
// PiLink.cpp
8892
MSG(INFO_RECEIVED_SETTING, "Received new setting: %s = %s", key, val),

MigrateSettings.py

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,62 @@
2828

2929
MigrateSettingsDefaultRestoreValidity = [
3030
SettingMigrate('tempFormat', '0', '1000', []),
31-
SettingMigrate('tempSetMin', '0', '1000', []),
32-
SettingMigrate('tempSetMax', '0', '1000', []),
33-
SettingMigrate('Kp', '0', '1000', []),
34-
SettingMigrate('Ki', '0', '1000', []),
35-
SettingMigrate('Kd', '0', '1000', []),
36-
SettingMigrate('iMaxErr', '0', '1000', []),
37-
SettingMigrate('pidMax', '0.2.4', '1000', []),
38-
SettingMigrate('idleRangeH', '0', '1000', []),
39-
SettingMigrate('idleRangeL', '0', '1000', []),
40-
SettingMigrate('heatTargetH', '0', '1000', []),
41-
SettingMigrate('heatTargetL', '0', '1000', []),
42-
SettingMigrate('coolTargetH', '0', '1000', []),
43-
SettingMigrate('coolTargetL', '0', '1000', []),
44-
SettingMigrate('maxHeatTimeForEst', '0', '1000', []),
45-
SettingMigrate('maxCoolTimeForEst', '0', '1000', []),
46-
SettingMigrate('fridgeFastFilt', '0.2.0', '1000', []),
47-
SettingMigrate('fridgeSlowFilt', '0.2.0', '1000', []),
48-
SettingMigrate('fridgeSlopeFilt', '0.2.0', '1000', []),
49-
SettingMigrate('beerFastFilt', '0.2.0', '1000', []),
50-
SettingMigrate('beerSlowFilt', '0.2.3', '1000', []),
51-
SettingMigrate('beerSlopeFilt', '0.2.3', '1000', []),
52-
SettingMigrate('lah', '0', '1000', []),
53-
SettingMigrate('hs', '0', '1000', []),
54-
SettingMigrate('heatEst', '0', '1000', []),
55-
SettingMigrate('coolEst', '0', '1000', []),
31+
SettingMigrate('tempSetMin', '0', '0.2.11', []),
32+
SettingMigrate('tempSetMax', '0', '0.2.11', []),
33+
SettingMigrate('Kp', '0', '0.2.11', []),
34+
SettingMigrate('Ki', '0', '0.2.11', []),
35+
SettingMigrate('Kd', '0', '0.2.11', []),
36+
SettingMigrate('iMaxErr', '0', '0.2.11', []),
37+
SettingMigrate('pidMax', '0.2.4', '0.2.11', []),
38+
SettingMigrate('idleRangeH', '0', '0.2.11', []),
39+
SettingMigrate('idleRangeL', '0', '0.2.11', []),
40+
SettingMigrate('heatTargetH', '0', '0.2.11', []),
41+
SettingMigrate('heatTargetL', '0', '0.2.11', []),
42+
SettingMigrate('coolTargetH', '0', '0.2.11', []),
43+
SettingMigrate('coolTargetL', '0', '0.2.11', []),
44+
SettingMigrate('maxHeatTimeForEst', '0', '0.2.11', []),
45+
SettingMigrate('maxCoolTimeForEst', '0', '0.2.11', []),
46+
SettingMigrate('fridgeFastFilt', '0.2.0', '0.2.11', []),
47+
SettingMigrate('fridgeSlowFilt', '0.2.0', '0.2.11', []),
48+
SettingMigrate('fridgeSlopeFilt', '0.2.0', '0.2.11', []),
49+
SettingMigrate('beerFastFilt', '0.2.0', '0.2.11', []),
50+
SettingMigrate('beerSlowFilt', '0.2.3', '0.2.11', []),
51+
SettingMigrate('beerSlopeFilt', '0.2.3', '0.2.11', []),
52+
SettingMigrate('lah', '0', '0.2.11', []),
53+
SettingMigrate('hs', '0', '0.2.11', []),
54+
SettingMigrate('heatEst', '0', '0.2.11', []),
55+
SettingMigrate('coolEst', '0', '0.2.11', []),
5656
SettingMigrate('fridgeSet', '0', '1000', []),
5757
SettingMigrate('beerSet', '0', '1000', []),
58-
SettingMigrate('mode', '0', '1000', [])
58+
SettingMigrate('mode', '0', '1000', []),
59+
60+
SettingMigrate('heater1_kp', '0.4.0', '1000', []),
61+
SettingMigrate('heater1_ti', '0.4.0', '1000', []),
62+
SettingMigrate('heater1_td', '0.4.0', '1000', []),
63+
SettingMigrate('heater1_infilt', '0.4.0', '1000', []),
64+
SettingMigrate('heater1_dfilt', '0.4.0', '1000', []),
65+
SettingMigrate('heater2_kp', '0.4.0', '1000', []),
66+
SettingMigrate('heater2_ti', '0.4.0', '1000', []),
67+
SettingMigrate('heater2_td', '0.4.0', '1000', []),
68+
SettingMigrate('heater2_infilt', '0.4.0', '1000', []),
69+
SettingMigrate('heater2_dfilt', '0.4.0', '1000', []),
70+
SettingMigrate('cooler_kp', '0.4.0', '1000', []),
71+
SettingMigrate('cooler_ti', '0.4.0', '1000', []),
72+
SettingMigrate('cooler_td', '0.4.0', '1000', []),
73+
SettingMigrate('cooler_infilt', '0.4.0', '1000', []),
74+
SettingMigrate('cooler_dfilt', '0.4.0', '1000', []),
75+
SettingMigrate('beer2fridge_kp', '0.4.0', '1000', []),
76+
SettingMigrate('beer2fridge_ti', '0.4.0', '1000', []),
77+
SettingMigrate('beer2fridge_td', '0.4.0', '1000', []),
78+
SettingMigrate('beer2fridge_infilt', '0.4.0', '1000', []),
79+
SettingMigrate('beer2fridge_dfilt', '0.4.0', '1000', []),
80+
SettingMigrate('beer2fridge_pidMax', '0.4.0', '1000', []),
81+
SettingMigrate('minCoolTime', '0.4.0', '1000', []),
82+
SettingMigrate('minCoolIdleTime', '0.4.0', '1000', []),
83+
SettingMigrate('heater1PwmPeriod', '0.4.0', '1000', []),
84+
SettingMigrate('heater2PwmPeriod', '0.4.0', '1000', []),
85+
SettingMigrate('coolerPwmPeriod', '0.4.0', '1000', []),
86+
SettingMigrate('deadTime', '0.4.0', '1000', [])
5987
]
6088

6189
class MigrateSettings:

brewpi.py

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,13 @@ def printStdErr(*objs):
8080
compatibleHwVersion = "0.2.4"
8181

8282
# Control Settings
83-
cs = dict(mode='b', beerSet=20.0, fridgeSet=20.0, heatEstimator=0.2, coolEstimator=5)
83+
cs = dict(mode='b', beerSet=20.0, fridgeSet=20.0)
8484

8585
# Control Constants
86-
cc = dict(tempFormat="C", tempSetMin=1.0, tempSetMax=30.0, pidMax=10.0, Kp=20.000, Ki=0.600, Kd=-3.000, iMaxErr=0.500,
87-
idleRangeH=1.000, idleRangeL=-1.000, heatTargetH=0.301, heatTargetL=-0.199, coolTargetH=0.199,
88-
coolTargetL=-0.301, maxHeatTimeForEst="600", maxCoolTimeForEst="1200", fridgeFastFilt="1", fridgeSlowFilt="4",
89-
fridgeSlopeFilt="3", beerFastFilt="3", beerSlowFilt="5", beerSlopeFilt="4", lah=0, hs=0)
86+
cc = dict()
9087

91-
# Control variables
92-
cv = dict(beerDiff=0.000, diffIntegral=0.000, beerSlope=0.000, p=0.000, i=0.000, d=0.000, estPeak=0.000,
93-
negPeakEst=0.000, posPeakEst=0.000, negPeak=0.000, posPeak=0.000)
88+
# Control variables (json string, sent directly to browser without decoding)
89+
cv = ""
9490

9591
# listState = "", "d", "h", "dh" to reflect whether the list is up to date for installed (d) and available (h)
9692
deviceList = dict(listState="", installed=[], available=[])
@@ -501,7 +497,7 @@ def renameTempKey(key):
501497
cs['dataLogging'] = config['dataLogging']
502498
conn.send(json.dumps(cs))
503499
elif messageType == "getControlVariables":
504-
conn.send(json.dumps(cv))
500+
conn.send(cv)
505501
elif messageType == "refreshControlConstants":
506502
ser.write("c")
507503
raise socket.timeout
@@ -523,40 +519,31 @@ def renameTempKey(key):
523519
except ValueError:
524520
logMessage("Cannot convert temperature '" + value + "' to float")
525521
continue
526-
if cc['tempSetMin'] <= newTemp <= cc['tempSetMax']:
527-
cs['mode'] = 'b'
528-
# round to 2 dec, python will otherwise produce 6.999999999
529-
cs['beerSet'] = round(newTemp, 2)
530-
ser.write("j{mode:b, beerSet:" + json.dumps(cs['beerSet']) + "}")
531-
logMessage("Notification: Beer temperature set to " +
532-
str(cs['beerSet']) +
533-
" degrees in web interface")
534-
raise socket.timeout # go to serial communication to update controller
535-
else:
536-
logMessage("Beer temperature setting " + str(newTemp) +
537-
" is outside of allowed range " +
538-
str(cc['tempSetMin']) + " - " + str(cc['tempSetMax']) +
539-
". These limits can be changed in advanced settings.")
522+
523+
cs['mode'] = 'b'
524+
# round to 2 dec, python will otherwise produce 6.999999999
525+
cs['beerSet'] = round(newTemp, 2)
526+
ser.write("j{mode:b, beerSet:" + json.dumps(cs['beerSet']) + "}")
527+
logMessage("Notification: Beer temperature set to " +
528+
str(cs['beerSet']) +
529+
" degrees in web interface")
530+
raise socket.timeout # go to serial communication to update controller
531+
540532
elif messageType == "setFridge": # new constant fridge temperature received
541533
try:
542534
newTemp = float(value)
543535
except ValueError:
544536
logMessage("Cannot convert temperature '" + value + "' to float")
545537
continue
546538

547-
if cc['tempSetMin'] <= newTemp <= cc['tempSetMax']:
548-
cs['mode'] = 'f'
549-
cs['fridgeSet'] = round(newTemp, 2)
550-
ser.write("j{mode:f, fridgeSet:" + json.dumps(cs['fridgeSet']) + "}")
551-
logMessage("Notification: Fridge temperature set to " +
552-
str(cs['fridgeSet']) +
553-
" degrees in web interface")
554-
raise socket.timeout # go to serial communication to update controller
555-
else:
556-
logMessage("Fridge temperature setting " + str(newTemp) +
557-
" is outside of allowed range " +
558-
str(cc['tempSetMin']) + " - " + str(cc['tempSetMax']) +
559-
". These limits can be changed in advanced settings.")
539+
cs['mode'] = 'f'
540+
cs['fridgeSet'] = round(newTemp, 2)
541+
ser.write("j{mode:f, fridgeSet:" + json.dumps(cs['fridgeSet']) + "}")
542+
logMessage("Notification: Fridge temperature set to " +
543+
str(cs['fridgeSet']) +
544+
" degrees in web interface")
545+
raise socket.timeout # go to serial communication to update controller
546+
560547
elif messageType == "setOff": # cs['mode'] set to OFF
561548
cs['mode'] = 'o'
562549
ser.write("j{mode:o}")
@@ -697,6 +684,13 @@ def renameTempKey(key):
697684
continue
698685
ser.write("U" + json.dumps(configStringJson))
699686
deviceList['listState'] = "" # invalidate local copy
687+
elif messageType == "writeDevice":
688+
try:
689+
configStringJson = json.loads(value) # load as JSON to check syntax
690+
except json.JSONDecodeError:
691+
logMessage("Error: invalid JSON parameter string received: " + value)
692+
continue
693+
ser.write("d" + json.dumps(configStringJson))
700694
elif messageType == "getVersion":
701695
if hwVersion:
702696
response = hwVersion.__dict__
@@ -706,6 +700,9 @@ def renameTempKey(key):
706700
response = {}
707701
response_str = json.dumps(response)
708702
conn.send(response_str)
703+
elif messageType == "resetController":
704+
logMessage("Resetting controller to factory defaults")
705+
ser.write("E")
709706
else:
710707
logMessage("Error: Received invalid message on socket: " + message)
711708

@@ -812,7 +809,7 @@ def renameTempKey(key):
812809
# do not print this to the log file. This is requested continuously.
813810
elif line[0] == 'V':
814811
# Control settings received
815-
cv = json.loads(line[2:])
812+
cv = line[2:] # keep as string, do not decode
816813
elif line[0] == 'N':
817814
pass # version number received. Do nothing, just ignore
818815
elif line[0] == 'h':

brewpiVersion.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def getVersionFromSerial(ser):
3232
retry = True
3333
while 1: # read all lines from serial
3434
loopTime = time.time()
35+
line = None
3536
try:
3637
line = ser.readline()
3738
except SerialException as e:

0 commit comments

Comments
 (0)