In my void loop I am calling callback() expecting it to return a new value ti variable "dim1".
When I try to verify my sketch I get:
Arduino: 1.8.13 (Linux), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"
/home/eirik/Arduino/try_1000/try_1000/try_1000.ino: In function 'void loop()':
try_1000:80:12: error: too few arguments to function 'void callback(char*, byte*, unsigned int)'
callback();
^
/home/eirik/Arduino/try_1000/try_1000/try_1000.ino:34:6: note: declared here
void callback(char* topic, byte* payload, unsigned int length) {
^~~~~~~~
try_1000:81:28: error: expected ')' before '{' token
if (dim1 != (dim_actual) {
^
try_1000:85:1: error: expected primary-expression before '}' token
}
^
/home/eirik/Arduino/try_1000/try_1000/try_1000.ino: In function 'void loop()':
try_1000:105:6: error: redefinition of 'void loop()'
void loop() {
^~~~
/home/eirik/Arduino/try_1000/try_1000/try_1000.ino:78:6: note: 'void loop()' previously defined here
void loop() {
^~~~
try_1000:106:3: error: 'client' was not declared in this scope
client.loop();
^~~~~~
/home/eirik/Arduino/try_1000/try_1000/try_1000.ino:106:3: note: suggested alternative: 'Client'
client.loop();
^~~~~~
Client
try_1000:107:12: error: too few arguments to function 'void callback(char*, byte*, unsigned int)'
callback();
^
/home/eirik/Arduino/try_1000/try_1000/try_1000.ino:34:6: note: declared here
void callback(char* topic, byte* payload, unsigned int length) {
^~~~~~~~
try_1000:108:28: error: expected ')' before '{' token
if (dim1 != (dim_actual) {
^
try_1000:112:1: error: expected primary-expression before '}' token
}
^
exit status 1
too few arguments to function 'void callback(char*, byte*, unsigned int)'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
This is my sketch code. Any pointers?
#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>
#include <RBDdimmer.h>
#define CLIENT_ID "Dimmer"
#define CLIENT_USER "testuser"
#define CLIENT_PASS "testpass"
// Update these with values suitable for your network.
byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress ip(192, 168, 68, 220);
IPAddress server(192, 168, 68, 115);
int dim1 = 0;// Dimming level (0-100) 0 = on, 100 = 0ff
int dim_actual = 0;
bool startsend = HIGH;
// Callback function header
void callback(char* topic, byte* payload, unsigned int length);
EthernetClient ethClient;
PubSubClient mqttClient(server, 1883, callback, ethClient);
void setup()
{
Ethernet.begin(mac, ip);
mqttClient.setCallback(callback);
}
//Callback function. Checks payload and update variable "dim1" with the value from mqtt.
void callback(char* topic, byte* payload, unsigned int length) {
char msgBuffer[20];
payload[length] = '\0'; // terminate string with '0'
String strPayload = String((char*)payload); // convert to string
dim1=strPayload.toInt();
}
// When I am done with this it will send data to mqtt broker.
void sendData() {
char msgBuffer[20];
if (mqttClient.connect(CLIENT_ID, CLIENT_USER, CLIENT_PASS)) {
mqttClient.subscribe("homeassistant/lys/brightness_state_topic");
if (startsend) {
mqttClient.publish("homeassistant/lys/brightness_state_topic", dim1);
startsend = LOW;
}
}
}
//brightness_command_topic string (optional)
//The MQTT topic to publish commands to change the light’s brightness.
//brightness_state_topic string (optional)
//The MQTT topic subscribed to receive brightness state updates.
//command_topic string REQUIRED
//The MQTT topic to publish commands to change the switch state.
// Void callback henter mqtt til dim1.
//Utfør endring av dimming
// Send tilbake kvittering på utført dimming
//Med jevne mellomrom sendt oppdatert status for å sørge for at dimming viser korrekt i home assistant dersom den skulle miste oversikten.
void loop() {
mqttClient.loop();
callback();
if (dim1 != dim_actual) {
dimmer.setPower(dim1);
dim_actual = dim1;
}
}
//brightness_command_topic string (optional)
//The MQTT topic to publish commands to change the light’s brightness.
//brightness_state_topic string (optional)
//The MQTT topic subscribed to receive brightness state updates.
//command_topic string REQUIRED
//The MQTT topic to publish commands to change the switch state.
// Void callback henter mqtt til dim1.
//Utfør endring av dimming
// Send tilbake kvittering på utført dimming
//Med jevne mellomrom sendt oppdatert status for å sørge for at dimming viser korrekt i home assistant dersom den skulle miste oversikten.