|
|
|
|
@ -18,11 +18,10 @@
|
|
|
|
|
#include "temperature.h"
|
|
|
|
|
#include "modbus-master.h"
|
|
|
|
|
#include "gefran_gtf.h"
|
|
|
|
|
#include "pumpe.h"
|
|
|
|
|
|
|
|
|
|
#include "util/delay.h"
|
|
|
|
|
|
|
|
|
|
#define PLC_MQTT_ENABLED 1
|
|
|
|
|
|
|
|
|
|
Client mqtt_client;
|
|
|
|
|
|
|
|
|
|
//***********Prologue for fast WDT disable & and save reason of reset/power-up: BEGIN
|
|
|
|
|
@ -92,14 +91,11 @@ void do_notaus(){
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void send_values(void){
|
|
|
|
|
char msg[10];
|
|
|
|
|
void send_temperatures(void){
|
|
|
|
|
for(uint8_t i=0; i<sizeof(ADC_reading)/sizeof(ADC_reading[0]);i++){
|
|
|
|
|
char msg[64];
|
|
|
|
|
char tpc[64];
|
|
|
|
|
sprintf(msg, "%.1f", ADC_reading[i]);
|
|
|
|
|
sprintf(tpc, "/Filamentanlage/02_Wasserbecken/state/temp%d", i);
|
|
|
|
|
mqtt_pub(&mqtt_client, tpc, msg, strlen(msg));
|
|
|
|
|
send_value_fl(&mqtt_client, tpc, ADC_reading[i], 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@ -160,14 +156,17 @@ int main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ioHelperSetBit(outStatesBlinking, LED_PLC_OK, 1);
|
|
|
|
|
//ioHelperSetBit(outStatesBlinking, OUT_VENTIL_ABLASS, 1);
|
|
|
|
|
//ioHelperSetBit(outStatesBlinking, OUT_VENTIL_PUMPE, 1);
|
|
|
|
|
|
|
|
|
|
ioHelperSetBit(outStates, OUT_PUMPE_STARTSTOP, 1);
|
|
|
|
|
ioHelperSetBit(outStates, OUT_PUMPE_PWM, 1);
|
|
|
|
|
|
|
|
|
|
uint32_t timer_blink_outs = millis();
|
|
|
|
|
uint32_t timer_send_uptime = millis();
|
|
|
|
|
uint32_t timer_send_temps = millis();
|
|
|
|
|
|
|
|
|
|
printf("anlage: %x\n\r", read_Input(IN_ANLAGE_EIN_INV, LEVEL));
|
|
|
|
|
send_value(&mqtt_client, "/Filamentanlage/02_Wasserbecken/connected", 1);
|
|
|
|
|
send_value(&mqtt_client, "/Filamentanlage/02_Wasserbecken/state/pumpe_warm", -1);
|
|
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
@ -179,34 +178,37 @@ int main()
|
|
|
|
|
|
|
|
|
|
// Toggle all outs which are set to blinking
|
|
|
|
|
if(millis() - timer_blink_outs > 500){
|
|
|
|
|
timer_blink_outs = millis();
|
|
|
|
|
outStates[0] ^= outStatesBlinking[0];
|
|
|
|
|
outStates[1] ^= outStatesBlinking[1];
|
|
|
|
|
#if PLC_MQTT_ENABLED
|
|
|
|
|
send_values();
|
|
|
|
|
#endif
|
|
|
|
|
timer_blink_outs = millis();
|
|
|
|
|
outStates[2] ^= outStatesBlinking[2];
|
|
|
|
|
outStates[3] ^= outStatesBlinking[3];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(millis() - timer_send_temps > 500){
|
|
|
|
|
timer_send_temps = millis();
|
|
|
|
|
send_temperatures();
|
|
|
|
|
printf("gefran: 0x%02X\n", gtf_firmware_version(5));
|
|
|
|
|
|
|
|
|
|
if(read_Input(IN_KLATWASSER_DRAN, LEVEL)){
|
|
|
|
|
send_value(&mqtt_client, "/Filamentanlage/03_Wasserbecken/state/connected", 1);
|
|
|
|
|
set_Output(LED_KALTWASSER_DRAN_GR, 1);
|
|
|
|
|
set_Output(LED_KALTWASSER_DRAN_RT, 0);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
send_value(&mqtt_client, "/Filamentanlage/03_Wasserbecken/state/connected", 0);
|
|
|
|
|
set_Output(LED_KALTWASSER_DRAN_GR, 0);
|
|
|
|
|
set_Output(LED_KALTWASSER_DRAN_RT, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if PLC_MQTT_ENABLED
|
|
|
|
|
// send misc info
|
|
|
|
|
if(millis() - timer_send_uptime > 5000){
|
|
|
|
|
timer_send_uptime += 5000;
|
|
|
|
|
char msg[64];
|
|
|
|
|
sprintf(msg, "%ld", millis()/1000);
|
|
|
|
|
mqtt_pub(&mqtt_client, "/Filamentanlage/02_Wasserbecken/uptime", msg, strlen(msg));
|
|
|
|
|
timer_send_uptime = millis();
|
|
|
|
|
send_value(&mqtt_client, "/Filamentanlage/02_Wasserbecken/uptime", millis()/1000);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(read_Input(IN_ANLAGE_EIN_INV, FALLING)){
|
|
|
|
|
printf("anlage ein\n\r");
|
|
|
|
|
}
|
|
|
|
|
// ioHelperSetBit(outStates, LED_GRN_NOTAUS_SCHRANK, 1);
|
|
|
|
|
//}
|
|
|
|
|
//else{
|
|
|
|
|
// ioHelperSetBit(outStates, LED_GRN_NOTAUS_SCHRANK, 0);
|
|
|
|
|
//}
|
|
|
|
|
do_pumpe();
|
|
|
|
|
do_notaus();
|
|
|
|
|
|
|
|
|
|
#if PLC_MQTT_ENABLED
|
|
|
|
|
@ -235,7 +237,7 @@ static void avr_init(void)
|
|
|
|
|
{
|
|
|
|
|
// Initialize device here.
|
|
|
|
|
// WatchDog INIT
|
|
|
|
|
wdt_enable(WDTO_8S); // set up wdt reset interval 2 second
|
|
|
|
|
wdt_enable(WDTO_2S); // set up wdt reset interval 2 second
|
|
|
|
|
wdt_reset(); // wdt reset ~ every <2000ms
|
|
|
|
|
|
|
|
|
|
timer0_init();// Timer0 millis engine init
|
|
|
|
|
|