Compare commits

...

7 Commits

Author SHA1 Message Date
d95e123f7b publish default values on startup 2022-04-05 12:48:12 +02:00
a250a28cc0 reboot on error 2022-04-05 12:47:45 +02:00
e327e1ab21 fix crash 2022-04-05 12:46:50 +02:00
02f992a97b dos2unix 2022-04-02 11:48:04 +02:00
53f5b78356 suppress warnings 2022-04-02 11:47:00 +02:00
207c5e67ab enable mqtt in code 2022-04-02 09:32:13 +02:00
8f951d3f73 add clangd file 2022-04-02 09:31:52 +02:00
4 changed files with 374 additions and 352 deletions

View File

@@ -179,6 +179,8 @@ char* MQTTFormat_toClientString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
break; break;
} }
(void) strindex;
return strbuf; return strbuf;
} }
@@ -260,6 +262,7 @@ char* MQTTFormat_toServerString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
break; break;
} }
(void) strindex;
strbuf[strbuflen] = '\0'; strbuf[strbuflen] = '\0';
return strbuf; return strbuf;
} }

18
compile_flags.txt Normal file
View File

@@ -0,0 +1,18 @@
-D
__AVR_ATmega2560__
-D
F_CPU=16000000UL
-D
_WIZCHIP_=W5100
-I
/usr/lib/avr/include
-I
Internet
-I
Internet/MQTT
-I
Internet/MQTT/MQTTPacket/src
-I
Ethernet
-I
Ethernet/W5500

13
main.c
View File

@@ -17,7 +17,7 @@
#include "util/delay.h" #include "util/delay.h"
#define PLC_MQTT_ENABLED 0 #define PLC_MQTT_ENABLED 1
Client mqtt_client; Client mqtt_client;
@@ -86,7 +86,7 @@ void do_luefter(){
if (read_Input(BTN_LUEFTER_PLUS, RISING) && (fan_value+STEP_SIZE <= TOP_VALUE)) { if (read_Input(BTN_LUEFTER_PLUS, RISING) && (fan_value+STEP_SIZE <= TOP_VALUE)) {
fan_value += STEP_SIZE; fan_value += STEP_SIZE;
#if PLC_MQTT_ENABLED #if PLC_MQTT_ENABLED
char _msg[3]; char _msg[4];
sprintf(_msg, "%d", fan_value * 100 / 40); sprintf(_msg, "%d", fan_value * 100 / 40);
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/LuefterSpeed", _msg, 3); mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/LuefterSpeed", _msg, 3);
#endif #endif
@@ -96,7 +96,7 @@ void do_luefter(){
if (read_Input(BTN_LUEFTER_MINUS, RISING) && (fan_value-STEP_SIZE >= STEP_SIZE)) { if (read_Input(BTN_LUEFTER_MINUS, RISING) && (fan_value-STEP_SIZE >= STEP_SIZE)) {
fan_value -= STEP_SIZE; fan_value -= STEP_SIZE;
#if PLC_MQTT_ENABLED #if PLC_MQTT_ENABLED
char _msg[3]; char _msg[4];
sprintf(_msg, "%d", fan_value * 100 / 40); sprintf(_msg, "%d", fan_value * 100 / 40);
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/LuefterSpeed", _msg, 3); mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/LuefterSpeed", _msg, 3);
#endif #endif
@@ -207,7 +207,7 @@ int main()
else else
{ {
printf("--MQTT Connected ERROR: %ld\r\n", mqtt_rc); printf("--MQTT Connected ERROR: %ld\r\n", mqtt_rc);
//while(1); //Reboot the board while(1); //Reboot the board
} }
// Subscribe to all topics // Subscribe to all topics
@@ -222,10 +222,10 @@ int main()
uint32_t timer_blink_outs = millis(); uint32_t timer_blink_outs = millis();
uint32_t timer_send_uptime = millis(); uint32_t timer_send_uptime = millis();
OCR3B = 127;
#if PLC_MQTT_ENABLED #if PLC_MQTT_ENABLED
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/Luefter", "aus", 3); mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/Luefter", "aus", 3);
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/LuefterSpeed", "50", 2);
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/Zumbach", "aus", 3);
#endif #endif
while(1) while(1)
@@ -299,6 +299,7 @@ void timer3_init(void)
TCCR3A |= (1<<WGM30); // PWM Mode with ocra top TCCR3A |= (1<<WGM30); // PWM Mode with ocra top
TCCR3B |= (1<<WGM33); TCCR3B |= (1<<WGM33);
OCR3A = TOP_VALUE; OCR3A = TOP_VALUE;
OCR3B = 0;
TCCR3B |= (0<<CS32)|(1<<CS31)|(0<<CS30); // PS 1:1 TCCR3B |= (0<<CS32)|(1<<CS31)|(0<<CS30); // PS 1:1
TCCR3A |= (1<<COM3B1) | (0<<COM3B0); TCCR3A |= (1<<COM3B1) | (0<<COM3B0);

10
mqtt.c
View File

@@ -56,11 +56,11 @@ void mqtt_pub(Client* mqtt_client, char * mqtt_topic, char * mqtt_msg, int mqtt_
{ {
printf(" - ERROR\r\n"); printf(" - ERROR\r\n");
//Reboot device after 20 continuous errors (~ 20sec) //Reboot device after 20 continuous errors (~ 20sec)
while(1);
//if(mqtt_err_cnt++ > 20)
//{
// printf("Connection with MQTT Broker was lost!!\r\nReboot the board..\r\n");
//while(1); //while(1);
//} if(mqtt_err_cnt++ > 20)
{
printf("Connection with MQTT Broker was lost!!\r\nReboot the board..\r\n");
while(1);
}
} }
} }