634 } else if (strncmp(buf, "SET", 3) == 0) { |
615 } else if (strncmp(buf, "SET", 3) == 0) { |
635 if (cmd_set(buf) == 0) |
616 if (cmd_set(buf) == 0) |
636 wrconfig(); |
617 wrconfig(); |
637 } else if (strncmp(buf, "UNIT", 4) == 0) { |
618 } else if (strncmp(buf, "UNIT", 4) == 0) { |
638 cmd_unit(buf); |
619 cmd_unit(buf); |
|
620 |
|
621 /* |
|
622 * Now the old style (brewPi) commands. These will go away. |
|
623 */ |
639 } else if (strncmp(buf, "ack", 3) == 0) { |
624 } else if (strncmp(buf, "ack", 3) == 0) { |
640 srv_send((char *)"ack"); |
625 srv_send((char *)"ack"); |
641 } else if (strncmp(buf, "lcd", 3) == 0) { |
626 } else if (strncmp(buf, "lcd", 3) == 0) { |
642 sprintf(obuf, "[\" \", \" \", \" \", \" \"]"); |
627 sprintf(obuf, "[\" \", \" \", \" \", \" \"]"); |
643 #ifdef HAVE_WIRINGPI_H |
628 #ifdef HAVE_WIRINGPI_H |
648 obuf[i+74] = lcdbuf[lcdHandle][i][3]; |
633 obuf[i+74] = lcdbuf[lcdHandle][i][3]; |
649 } |
634 } |
650 #endif |
635 #endif |
651 srv_send(obuf); |
636 srv_send(obuf); |
652 } else if (strncmp(buf, "getMode", 7) == 0) { |
637 } else if (strncmp(buf, "getMode", 7) == 0) { |
653 srv_send("%c", Config.cs_mode); |
638 srv_send("%c", UNITmode[Config.units->mode]); |
654 } else if (strncmp(buf, "getFridge", 9) == 0) { |
639 } else if (strncmp(buf, "getFridge", 9) == 0) { |
655 srv_send("%.1f", Config.cs_fridgeSet); |
640 srv_send("%.1f", Config.units->fridge_set); |
656 } else if (strncmp(buf, "getBeer", 7) == 0) { |
641 } else if (strncmp(buf, "getBeer", 7) == 0) { |
657 srv_send("%.1f", Config.cs_beerSet); |
642 srv_send("%.1f", Config.units->beer_set); |
658 } else if (strncmp(buf, "getControlConstants", 19) == 0) { |
643 } else if (strncmp(buf, "getControlConstants", 19) == 0) { |
659 srv_send("{ \"tempFormat\":\"%c\", \"tempSetMin\":%.1f, \"tempSetMax\":%.1f, \"idleRangeH\":%.3f, \"idleRangeL\":%.3f }", |
644 srv_send("{ \"tempFormat\":\"%c\", \"tempSetMin\":%.1f, \"tempSetMax\":%.1f, \"idleRangeH\":%.3f, \"idleRangeL\":%.3f }", |
660 Config.tempFormat, Config.cc_tempSetMin, Config.cc_tempSetMax, Config.cc_idleRangeH, Config.cc_idleRangeL ); |
645 Config.tempFormat, Config.units->temp_set_min, Config.units->temp_set_max, Config.units->idle_rangeH, Config.units->idle_rangeL); |
661 } else if (strncmp(buf, "getControlSettings", 18) == 0) { |
646 } else if (strncmp(buf, "getControlSettings", 18) == 0) { |
662 srv_send("{ \"mode\":\"%c\", \"beerSet\":%.1f, \"fridgeSet\":%.1f, \"heatEstimator\":%.1f, \"coolEstimator\":%.1f }", |
647 srv_send("{ \"mode\":\"%c\", \"beerSet\":%.1f, \"fridgeSet\":%.1f, \"heatEstimator\":%.1f, \"coolEstimator\":%.1f }", |
663 Config.cs_mode, Config.cs_beerSet, Config.cs_fridgeSet, Config.cs_heatEstimator, Config.cs_coolEstimator); |
648 UNITmode[Config.units->mode], Config.units->beer_set, Config.units->fridge_set, cs_heatEstimator, cs_coolEstimator); |
664 } else if (strncmp(buf, "getControlVariables", 19) == 0) { |
649 } else if (strncmp(buf, "getControlVariables", 19) == 0) { |
665 srv_send("{ \"beerDiff\":%.2f }", cv_beerDiff); |
650 srv_send("{ \"beerDiff\":%.2f }", cv_beerDiff); |
666 } else if (strncmp(buf, "loadDefaultControlSettings", 26) == 0) { |
651 } else if (strncmp(buf, "loadDefaultControlSettings", 26) == 0) { |
667 defaultControlSettings(); |
652 // Does nothing anymore |
668 srv_send("ack"); |
653 srv_send("ack"); |
669 } else if (strncmp(buf, "loadDefaultControlConstants", 27) == 0) { |
654 } else if (strncmp(buf, "loadDefaultControlConstants", 27) == 0) { |
670 defaultControlConstants(); |
655 // Does nothing anymore |
671 srv_send("ack"); |
656 srv_send("ack"); |
672 } else if (strncmp(buf, "setBeer=", 8) == 0) { |
657 } else if (strncmp(buf, "setBeer=", 8) == 0) { |
673 inp = xstrcpy(buf+8); |
658 inp = xstrcpy(buf+8); |
674 rc = sscanf(inp, "%f", &newtemp); |
659 rc = sscanf(inp, "%f", &newtemp); |
675 if (debug) |
660 if (debug) |
676 fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc); |
661 fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc); |
677 if (rc == 1) { |
662 if (rc == 1) { |
678 if ((Config.cc_tempSetMin <= newtemp) && (newtemp <= Config.cc_tempSetMax)) { |
663 if ((Config.units->temp_set_min <= newtemp) && (newtemp <= Config.units->temp_set_max)) { |
679 syslog(LOG_NOTICE, "Beer temperature set to %.1f degrees in web interface", newtemp); |
664 syslog(LOG_NOTICE, "Beer temperature set to %.1f degrees in web interface", newtemp); |
680 srv_send("ack"); |
665 srv_send("ack"); |
681 Config.cs_mode = 'b'; |
666 Config.units->mode = UNITMODE_BEER; |
682 Config.cs_beerSet = newtemp; |
667 Config.units->beer_set = newtemp; |
683 } else { |
668 } else { |
684 syslog(LOG_NOTICE, "Beer temperature setting %.1f is outside of allowed range %.1f - %.1f", newtemp, Config.cc_tempSetMin, Config.cc_tempSetMax); |
669 syslog(LOG_NOTICE, "Beer temperature setting %.1f is outside of allowed range %.1f - %.1f", newtemp, Config.units->temp_set_min, Config.units->temp_set_max); |
685 srv_send("err"); |
670 srv_send("err"); |
686 } |
671 } |
687 } else { |
672 } else { |
688 syslog(LOG_NOTICE, "Cannot convert temperature '%s' to float", inp); |
673 syslog(LOG_NOTICE, "Cannot convert temperature '%s' to float", inp); |
689 srv_send("err"); |
674 srv_send("err"); |
693 inp = xstrcpy(buf+10); |
678 inp = xstrcpy(buf+10); |
694 rc = sscanf(inp, "%f", &newtemp); |
679 rc = sscanf(inp, "%f", &newtemp); |
695 if (debug) |
680 if (debug) |
696 fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc); |
681 fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc); |
697 if (rc == 1) { |
682 if (rc == 1) { |
698 if ((Config.cc_tempSetMin <= newtemp) && (newtemp <= Config.cc_tempSetMax)) { |
683 if ((Config.units->temp_set_min <= newtemp) && (newtemp <= Config.units->temp_set_max)) { |
699 syslog(LOG_NOTICE, "Fridge temperature set to %.1f degrees in web interface", newtemp); |
684 syslog(LOG_NOTICE, "Fridge temperature set to %.1f degrees in web interface", newtemp); |
700 srv_send("ack"); |
685 srv_send("ack"); |
701 Config.cs_mode = 'f'; |
686 Config.units->mode = UNITMODE_FRIDGE; |
702 Config.cs_fridgeSet = newtemp; |
687 Config.units->fridge_set = newtemp; |
703 } else { |
688 } else { |
704 syslog(LOG_NOTICE, "Fridge temperature setting %.1f is outside of allowed range %.1f - %.1f", newtemp, Config.cc_tempSetMin, Config.cc_tempSetMax); |
689 syslog(LOG_NOTICE, "Fridge temperature setting %.1f is outside of allowed range %.1f - %.1f", newtemp, Config.units->temp_set_min, Config.units->temp_set_max); |
705 srv_send("err"); |
690 srv_send("err"); |
706 } |
691 } |
707 } else { |
692 } else { |
708 syslog(LOG_NOTICE, "Cannot convert temperature '%s' to float", inp); |
693 syslog(LOG_NOTICE, "Cannot convert temperature '%s' to float", inp); |
709 srv_send("err"); |
694 srv_send("err"); |
724 q = strtok(NULL, (char *)":,}"); |
709 q = strtok(NULL, (char *)":,}"); |
725 if (strcmp(p, (char *)"tempSetMin") == 0) { |
710 if (strcmp(p, (char *)"tempSetMin") == 0) { |
726 rc = sscanf(q, "%f", &newtemp); |
711 rc = sscanf(q, "%f", &newtemp); |
727 if (rc == 1) { |
712 if (rc == 1) { |
728 syslog(LOG_NOTICE, "cc_tempSetMin = %1.f", newtemp); |
713 syslog(LOG_NOTICE, "cc_tempSetMin = %1.f", newtemp); |
729 Config.cc_tempSetMin = newtemp; |
714 Config.units->temp_set_min = newtemp; |
730 srv_send("ack"); |
715 srv_send("ack"); |
731 } else { |
716 } else { |
732 srv_send("ERR"); |
717 srv_send("ERR"); |
733 } |
718 } |
734 } else if (strcmp(p, (char *)"tempSetMax") == 0) { |
719 } else if (strcmp(p, (char *)"tempSetMax") == 0) { |
735 rc = sscanf(q, "%f", &newtemp); |
720 rc = sscanf(q, "%f", &newtemp); |
736 if (rc == 1) { |
721 if (rc == 1) { |
737 syslog(LOG_NOTICE, "cc_tempSetMax = %1.f", newtemp); |
722 syslog(LOG_NOTICE, "cc_tempSetMax = %1.f", newtemp); |
738 Config.cc_tempSetMax = newtemp; |
723 Config.units->temp_set_max = newtemp; |
739 srv_send("ack"); |
724 srv_send("ack"); |
740 } else { |
725 } else { |
741 srv_send("ERR"); |
726 srv_send("ERR"); |
742 } |
727 } |
743 } else { |
728 } else { |