Compare commits
6 Commits
5825769356
...
246cc875a1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
246cc875a1 | ||
|
|
e6e0a01b6c | ||
|
|
1bd732d812 | ||
|
|
411f2f59cd | ||
|
|
ffe7c9507b | ||
|
|
79feed7a92 |
3
Makefile
3
Makefile
@@ -10,7 +10,8 @@ TOOL = atmelice_isp
|
|||||||
|
|
||||||
BUILDDIR = Builds
|
BUILDDIR = Builds
|
||||||
|
|
||||||
DEFINES = -I . -IInternet/MQTT -I Internet/MQTT/MQTTPacket/src -I Ethernet/W5500 -I Ethernet -DF_CPU=16000000UL -D_WIZCHIP_=W5100
|
DEFINES = -I . -IInternet/MQTT -I Internet/MQTT/MQTTPacket/src -I Ethernet/W5500 -I Ethernet -DF_CPU=16000000UL -D_WIZCHIP_=W5100 -DPLC_MQTT_ENABLED=1
|
||||||
|
|
||||||
|
|
||||||
CFLAGS =-mmcu=$(MCU) -O2 -Wall -Wpedantic $(DEFINES) -std=c99 -ffunction-sections -fdata-sections
|
CFLAGS =-mmcu=$(MCU) -O2 -Wall -Wpedantic $(DEFINES) -std=c99 -ffunction-sections -fdata-sections
|
||||||
#LDFLAGS =-mmcu=$(MCU) -Wl,--gc-sections
|
#LDFLAGS =-mmcu=$(MCU) -Wl,--gc-sections
|
||||||
|
|||||||
@@ -68,6 +68,9 @@ void ioHelperEdgeDetector(void);
|
|||||||
#define BitPD6 22 //D22
|
#define BitPD6 22 //D22
|
||||||
#define BitPJ4 23 //D23
|
#define BitPJ4 23 //D23
|
||||||
|
|
||||||
|
#define BitPA0 24 //R0
|
||||||
|
#define BitPA1 25 //R1
|
||||||
|
|
||||||
|
|
||||||
#define LED_GRN_NOTAUS_ANLAGE BitPE4
|
#define LED_GRN_NOTAUS_ANLAGE BitPE4
|
||||||
#define LED_ROT_NOTAUS_ANLAGE BitPE5
|
#define LED_ROT_NOTAUS_ANLAGE BitPE5
|
||||||
@@ -75,10 +78,17 @@ void ioHelperEdgeDetector(void);
|
|||||||
#define LED_ROT_NOTAUS_SCHRANK BitPE3
|
#define LED_ROT_NOTAUS_SCHRANK BitPE3
|
||||||
#define LED_PLC_OK BitPH5
|
#define LED_PLC_OK BitPH5
|
||||||
#define LED_BUS_OK BitPD4
|
#define LED_BUS_OK BitPD4
|
||||||
|
#define LED_KALTWASSER_DRAN_GR 23
|
||||||
|
#define LED_KALTWASSER_DRAN_RT 22
|
||||||
|
|
||||||
|
#define LED_PUMPE_AN 11
|
||||||
|
|
||||||
#define OUT_PUMPE_STARTSTOP BitPB5
|
#define OUT_PUMPE_STARTSTOP BitPB5
|
||||||
#define OUT_PUMPE_PWM BitPB6
|
#define OUT_PUMPE_PWM BitPB6
|
||||||
|
|
||||||
|
#define OUT_VENTIL_PUMPE BitPA0
|
||||||
|
#define OUT_VENTIL_ABLASS BitPA1
|
||||||
|
|
||||||
//Inputs
|
//Inputs
|
||||||
//Verknüpfen von Pin | Bit mit Bitposition (0...n) inStates[0...n/8].
|
//Verknüpfen von Pin | Bit mit Bitposition (0...n) inStates[0...n/8].
|
||||||
#define BitPinF0 0 //A0
|
#define BitPinF0 0 //A0
|
||||||
@@ -92,13 +102,26 @@ void ioHelperEdgeDetector(void);
|
|||||||
|
|
||||||
#define BitPinK0 8 //A8
|
#define BitPinK0 8 //A8
|
||||||
#define BitPinK1 9 //A9
|
#define BitPinK1 9 //A9
|
||||||
#define BitPinD3 10 //INO
|
#define BitPinK2 10 //A10
|
||||||
#define BitPinD2 11 //IN1
|
#define BitPinK3 11 //A11
|
||||||
|
#define BitPinK4 12 //A12
|
||||||
|
#define BitPinK5 13 //A13
|
||||||
|
#define BitPinK6 14 //A14
|
||||||
|
#define BitPinK7 15 //A15
|
||||||
|
|
||||||
|
#define BitPinD7 16 //I16
|
||||||
|
#define BitPinG2 17 //I17
|
||||||
|
#define BitPinG1 18 //I18
|
||||||
|
#define BitPinD3 19 //INO
|
||||||
|
#define BitPinD2 20 //IN1
|
||||||
|
|
||||||
#define IN_ANLAGE_EIN_INV BitPinF5
|
#define IN_ANLAGE_EIN_INV BitPinF5
|
||||||
#define IN_NOTAUS_ANLAGE BitPinF7
|
#define IN_NOTAUS_ANLAGE BitPinF7
|
||||||
#define IN_NOTAUS_SCHRANK BitPinK0
|
#define IN_NOTAUS_SCHRANK BitPinK0
|
||||||
|
|
||||||
#define IN_KLATWASSER_DRAN BitPinF6
|
#define IN_KLATWASSER_DRAN 9
|
||||||
|
|
||||||
|
#define BTN_BECKEN_FUELLEN 11
|
||||||
|
#define BTN_BECKEN_LEEREN 12
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
62
main.c
62
main.c
@@ -18,11 +18,10 @@
|
|||||||
#include "temperature.h"
|
#include "temperature.h"
|
||||||
#include "modbus-master.h"
|
#include "modbus-master.h"
|
||||||
#include "gefran_gtf.h"
|
#include "gefran_gtf.h"
|
||||||
|
#include "pumpe.h"
|
||||||
|
|
||||||
#include "util/delay.h"
|
#include "util/delay.h"
|
||||||
|
|
||||||
#define PLC_MQTT_ENABLED 1
|
|
||||||
|
|
||||||
Client mqtt_client;
|
Client mqtt_client;
|
||||||
|
|
||||||
//***********Prologue for fast WDT disable & and save reason of reset/power-up: BEGIN
|
//***********Prologue for fast WDT disable & and save reason of reset/power-up: BEGIN
|
||||||
@@ -92,14 +91,11 @@ void do_notaus(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void send_values(void){
|
void send_temperatures(void){
|
||||||
char msg[10];
|
|
||||||
for(uint8_t i=0; i<sizeof(ADC_reading)/sizeof(ADC_reading[0]);i++){
|
for(uint8_t i=0; i<sizeof(ADC_reading)/sizeof(ADC_reading[0]);i++){
|
||||||
char msg[64];
|
|
||||||
char tpc[64];
|
char tpc[64];
|
||||||
sprintf(msg, "%.1f", ADC_reading[i]);
|
|
||||||
sprintf(tpc, "/Filamentanlage/02_Wasserbecken/state/temp%d", 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, 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_blink_outs = millis();
|
||||||
uint32_t timer_send_uptime = 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));
|
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)
|
while(1)
|
||||||
{
|
{
|
||||||
@@ -179,34 +178,37 @@ int main()
|
|||||||
|
|
||||||
// Toggle all outs which are set to blinking
|
// Toggle all outs which are set to blinking
|
||||||
if(millis() - timer_blink_outs > 500){
|
if(millis() - timer_blink_outs > 500){
|
||||||
|
timer_blink_outs = millis();
|
||||||
outStates[0] ^= outStatesBlinking[0];
|
outStates[0] ^= outStatesBlinking[0];
|
||||||
outStates[1] ^= outStatesBlinking[1];
|
outStates[1] ^= outStatesBlinking[1];
|
||||||
#if PLC_MQTT_ENABLED
|
outStates[2] ^= outStatesBlinking[2];
|
||||||
send_values();
|
outStates[3] ^= outStatesBlinking[3];
|
||||||
#endif
|
}
|
||||||
timer_blink_outs = millis();
|
|
||||||
printf("gefran: 0x%02X\n", gtf_firmware_version(5));
|
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
|
// send misc info
|
||||||
if(millis() - timer_send_uptime > 5000){
|
if(millis() - timer_send_uptime > 5000){
|
||||||
timer_send_uptime += 5000;
|
timer_send_uptime = millis();
|
||||||
char msg[64];
|
send_value(&mqtt_client, "/Filamentanlage/02_Wasserbecken/uptime", millis()/1000);
|
||||||
sprintf(msg, "%ld", millis()/1000);
|
|
||||||
mqtt_pub(&mqtt_client, "/Filamentanlage/02_Wasserbecken/uptime", msg, strlen(msg));
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
do_pumpe();
|
||||||
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_notaus();
|
do_notaus();
|
||||||
|
|
||||||
#if PLC_MQTT_ENABLED
|
#if PLC_MQTT_ENABLED
|
||||||
@@ -235,7 +237,7 @@ static void avr_init(void)
|
|||||||
{
|
{
|
||||||
// Initialize device here.
|
// Initialize device here.
|
||||||
// WatchDog INIT
|
// 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
|
wdt_reset(); // wdt reset ~ every <2000ms
|
||||||
|
|
||||||
timer0_init();// Timer0 millis engine init
|
timer0_init();// Timer0 millis engine init
|
||||||
|
|||||||
22
mqtt.c
22
mqtt.c
@@ -1,3 +1,5 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "mqtt.h"
|
#include "mqtt.h"
|
||||||
|
|
||||||
@@ -64,3 +66,23 @@ void mqtt_pub(Client* mqtt_client, char * mqtt_topic, char * mqtt_msg, int mqtt_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void send_value(Client* mqtt_client,char* topic, int16_t value){
|
||||||
|
char msg[32];
|
||||||
|
sprintf(msg, "%d", value);
|
||||||
|
#if PLC_MQTT_ENABLED
|
||||||
|
mqtt_pub(mqtt_client, topic, msg, strlen(msg));
|
||||||
|
#else
|
||||||
|
printf("%s: %s\n", topic, msg);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void send_value_fl(Client* mqtt_client,char* topic, float value, uint8_t decimal_points){
|
||||||
|
#if PLC_MQTT_ENABLED
|
||||||
|
char msg[32];
|
||||||
|
sprintf(msg, "%.1f"/*, decimal_points*/, value);
|
||||||
|
mqtt_pub(mqtt_client, topic, msg, strlen(msg));
|
||||||
|
#else
|
||||||
|
printf("%s: %.1f\n", topic, /*decimal_points,*/ value);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|||||||
2
mqtt.h
2
mqtt.h
@@ -14,5 +14,7 @@ extern uint8_t MQTT_targetIP[4];
|
|||||||
|
|
||||||
void messageArrived(MessageData* md);
|
void messageArrived(MessageData* md);
|
||||||
void mqtt_pub(Client* mqtt_client, char * mqtt_topic, char * mqtt_msg, int mqtt_msg_len);
|
void mqtt_pub(Client* mqtt_client, char * mqtt_topic, char * mqtt_msg, int mqtt_msg_len);
|
||||||
|
void send_value(Client* mqtt_client,char* topic, int16_t value);
|
||||||
|
void send_value_fl(Client* mqtt_client,char* topic, float value, uint8_t decimal_points);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
24
pumpe.c
Normal file
24
pumpe.c
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include "avrIOhelper/io-helper.h"
|
||||||
|
|
||||||
|
#include "mqtt.h"
|
||||||
|
extern Client mqtt_client;
|
||||||
|
|
||||||
|
void do_pumpe(){
|
||||||
|
if(read_Input(BTN_BECKEN_FUELLEN, RISING)){
|
||||||
|
set_Output(OUT_PUMPE_STARTSTOP, 1);
|
||||||
|
set_Output(OUT_PUMPE_PWM, 1);
|
||||||
|
set_Output(OUT_VENTIL_ABLASS, 0);
|
||||||
|
set_Output(OUT_VENTIL_PUMPE, 0);
|
||||||
|
set_Output(LED_PUMPE_AN, 1);
|
||||||
|
send_value(&mqtt_client, "/Filamentanlage/02_Wasserbecken/state/pumpe_warm", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(read_Input(BTN_BECKEN_LEEREN, RISING)){
|
||||||
|
set_Output(OUT_PUMPE_STARTSTOP, 0);
|
||||||
|
set_Output(OUT_PUMPE_PWM, 0);
|
||||||
|
set_Output(OUT_VENTIL_ABLASS, 1);
|
||||||
|
set_Output(OUT_VENTIL_PUMPE, 1);
|
||||||
|
set_Output(LED_PUMPE_AN, 0);
|
||||||
|
send_value(&mqtt_client, "/Filamentanlage/02_Wasserbecken/state/pumpe_warm", 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user