Compare commits
11 Commits
ddbbbf7581
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| d95e123f7b | |||
| a250a28cc0 | |||
| e327e1ab21 | |||
| 02f992a97b | |||
| 53f5b78356 | |||
| 207c5e67ab | |||
| 8f951d3f73 | |||
| 1b055628c3 | |||
| 000eeba54e | |||
| 10594f2b43 | |||
| a5ff9a0183 |
@@ -179,6 +179,8 @@ char* MQTTFormat_toClientString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
|
||||
break;
|
||||
}
|
||||
|
||||
(void) strindex;
|
||||
|
||||
return strbuf;
|
||||
}
|
||||
|
||||
@@ -260,6 +262,7 @@ char* MQTTFormat_toServerString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
|
||||
break;
|
||||
}
|
||||
|
||||
(void) strindex;
|
||||
strbuf[strbuflen] = '\0';
|
||||
return strbuf;
|
||||
}
|
||||
|
||||
18
compile_flags.txt
Normal file
18
compile_flags.txt
Normal 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
|
||||
35
main.c
35
main.c
@@ -17,7 +17,7 @@
|
||||
|
||||
#include "util/delay.h"
|
||||
|
||||
#define PLC_MQTT_ENABLED 0
|
||||
#define PLC_MQTT_ENABLED 1
|
||||
|
||||
Client mqtt_client;
|
||||
|
||||
@@ -57,9 +57,10 @@ void IO_LIBRARY_Init(void) {
|
||||
#define STEP_SIZE 5
|
||||
#define TOP_VALUE 40
|
||||
void do_luefter(){
|
||||
static uint8_t fan_value = TOP_VALUE*0.8;
|
||||
static uint8_t fan_value = TOP_VALUE*0.5;
|
||||
static uint8_t fan_state = 0;
|
||||
|
||||
|
||||
if(!read_Input(IN_ANLAGE_EIN, LEVEL)){
|
||||
fan_state = 0;
|
||||
ioHelperSetBit(outStates, LED_LUEFTER, 0);
|
||||
@@ -85,15 +86,20 @@ void do_luefter(){
|
||||
if (read_Input(BTN_LUEFTER_PLUS, RISING) && (fan_value+STEP_SIZE <= TOP_VALUE)) {
|
||||
fan_value += STEP_SIZE;
|
||||
#if PLC_MQTT_ENABLED
|
||||
char _msg[3];
|
||||
sprintf(_msg, "%d", fan_value);
|
||||
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/Speed", _msg, 3);
|
||||
char _msg[4];
|
||||
sprintf(_msg, "%d", fan_value * 100 / 40);
|
||||
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/LuefterSpeed", _msg, 3);
|
||||
#endif
|
||||
printf("luefter %d\n\r", fan_value);
|
||||
}
|
||||
|
||||
if (read_Input(BTN_LUEFTER_MINUS, RISING) && (fan_value-STEP_SIZE >= STEP_SIZE)) {
|
||||
fan_value -= STEP_SIZE;
|
||||
#if PLC_MQTT_ENABLED
|
||||
char _msg[4];
|
||||
sprintf(_msg, "%d", fan_value * 100 / 40);
|
||||
mqtt_pub(&mqtt_client, "/Filamentanlage/04_Messmodul/state/LuefterSpeed", _msg, 3);
|
||||
#endif
|
||||
printf("luefter %d\n\r", fan_value);
|
||||
}
|
||||
}
|
||||
@@ -149,8 +155,10 @@ void do_notaus(){
|
||||
set_Output(LED_GRN_NOTAUS_SCHRANK, ON);
|
||||
}
|
||||
else{
|
||||
set_Output(LED_GRN_NOTAUS_ANLAGE, BLINK);
|
||||
set_Output(LED_GRN_NOTAUS_SCHRANK, BLINK);
|
||||
set_Output(LED_GRN_NOTAUS_ANLAGE, ON);
|
||||
set_Output(LED_GRN_NOTAUS_SCHRANK, ON);
|
||||
set_Output(LED_ROT_NOTAUS_ANLAGE, ON);
|
||||
set_Output(LED_ROT_NOTAUS_SCHRANK, ON);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -186,7 +194,7 @@ int main()
|
||||
MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
|
||||
data.willFlag = 0;
|
||||
data.MQTTVersion = 4;//3;
|
||||
data.clientID.cstring = (char*)"controllino";
|
||||
data.clientID.cstring = (char*)"controllino_messmodul";
|
||||
data.username.cstring = (char*)"Messmodul";
|
||||
data.password.cstring = (char*)"\0";
|
||||
data.keepAliveInterval = 10;
|
||||
@@ -199,7 +207,7 @@ int main()
|
||||
else
|
||||
{
|
||||
printf("--MQTT Connected ERROR: %ld\r\n", mqtt_rc);
|
||||
//while(1); //Reboot the board
|
||||
while(1); //Reboot the board
|
||||
}
|
||||
|
||||
// Subscribe to all topics
|
||||
@@ -214,12 +222,18 @@ int main()
|
||||
uint32_t timer_blink_outs = millis();
|
||||
uint32_t timer_send_uptime = millis();
|
||||
|
||||
OCR3B = 127;
|
||||
#if PLC_MQTT_ENABLED
|
||||
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
|
||||
|
||||
while(1)
|
||||
{
|
||||
wdt_reset(); // WDT reset at least every sec
|
||||
|
||||
|
||||
|
||||
//if (flag_refresh_inStates) {
|
||||
ioHelperReadPins();
|
||||
ioHelperDebounce();
|
||||
@@ -285,6 +299,7 @@ void timer3_init(void)
|
||||
TCCR3A |= (1<<WGM30); // PWM Mode with ocra top
|
||||
TCCR3B |= (1<<WGM33);
|
||||
OCR3A = TOP_VALUE;
|
||||
OCR3B = 0;
|
||||
|
||||
TCCR3B |= (0<<CS32)|(1<<CS31)|(0<<CS30); // PS 1:1
|
||||
TCCR3A |= (1<<COM3B1) | (0<<COM3B0);
|
||||
|
||||
10
mqtt.c
10
mqtt.c
@@ -56,11 +56,11 @@ void mqtt_pub(Client* mqtt_client, char * mqtt_topic, char * mqtt_msg, int mqtt_
|
||||
{
|
||||
printf(" - ERROR\r\n");
|
||||
//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);
|
||||
//if(mqtt_err_cnt++ > 20)
|
||||
//{
|
||||
// printf("Connection with MQTT Broker was lost!!\r\nReboot the board..\r\n");
|
||||
// while(1);
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user