|
|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
#include <avr/io.h>
|
|
|
|
|
#include <avr/interrupt.h>
|
|
|
|
|
#include <avr/wdt.h> // WatchDog
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "Ethernet/socket.h"
|
|
|
|
|
@ -14,11 +15,13 @@
|
|
|
|
|
#include "uart.h"
|
|
|
|
|
#include "spi.h"
|
|
|
|
|
#include "mqtt.h"
|
|
|
|
|
#include "temperature.h"
|
|
|
|
|
#include "modbus-master.h"
|
|
|
|
|
#include "gefran_gtf.h"
|
|
|
|
|
#include "pumpe.h"
|
|
|
|
|
|
|
|
|
|
#include "util/delay.h"
|
|
|
|
|
|
|
|
|
|
#define PLC_MQTT_ENABLED 0
|
|
|
|
|
|
|
|
|
|
Client mqtt_client;
|
|
|
|
|
|
|
|
|
|
//***********Prologue for fast WDT disable & and save reason of reset/power-up: BEGIN
|
|
|
|
|
@ -142,6 +145,15 @@ void do_notaus(){
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
void send_temperatures(void){
|
|
|
|
|
for(uint8_t i=0; i<sizeof(ADC_reading)/sizeof(ADC_reading[0]);i++){
|
|
|
|
|
char tpc[64];
|
|
|
|
|
sprintf(tpc, "/Filamentanlage/02_Wasserbecken/state/temp%d", i);
|
|
|
|
|
send_value_fl(&mqtt_client, tpc, ADC_reading[i], 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
// INIT MCU
|
|
|
|
|
@ -189,20 +201,26 @@ int main()
|
|
|
|
|
while(1); //Reboot the board
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Subscribe to all topics
|
|
|
|
|
char SubString[] = "/Filamentanlage/02_Wasserbecken/#";
|
|
|
|
|
//char SubString[] = "/Filamentanlage/03_Wasserbecken/#";
|
|
|
|
|
mqtt_rc = MQTTSubscribe(&mqtt_client, SubString, QOS0, messageArrived);
|
|
|
|
|
printf("Subscribed (%s) %ld\r\n", SubString, mqtt_rc);
|
|
|
|
|
//// Subscribe to all topics
|
|
|
|
|
//char SubString[] = "/Filamentanlage/02_Wasserbecken/#";
|
|
|
|
|
////char SubString[] = "/Filamentanlage/03_Wasserbecken/#";
|
|
|
|
|
//mqtt_rc = MQTTSubscribe(&mqtt_client, SubString, QOS0, messageArrived);
|
|
|
|
|
//printf("Subscribed (%s) %ld\r\n", SubString, mqtt_rc);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ioHelperSetBit(outStatesBlinking, LED_PLC_OK, 1);
|
|
|
|
|
//ioHelperSetBit(outStatesBlinking, OUT_VENTIL_ABLASS, 1);
|
|
|
|
|
//ioHelperSetBit(outStatesBlinking, OUT_VENTIL_PUMPE, 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)
|
|
|
|
|
{
|
|
|
|
|
@ -214,30 +232,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];
|
|
|
|
|
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
|
|
|
|
|
@ -266,11 +291,14 @@ 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
|
|
|
|
|
uart_init();
|
|
|
|
|
initADC();
|
|
|
|
|
|
|
|
|
|
modbus_master_init();
|
|
|
|
|
|
|
|
|
|
sei(); //re-enable global interrupts
|
|
|
|
|
|
|
|
|
|
|