Sigfox parse error: Why can it not send my message? - arduino

I'm testing the Sigfox communication with a Breakout board BRKWS01 and a Nucleo-32 L432KC. I work with Arduino IDE. I can send a message of 12 bytes. I used 12 "char" to save my data but it did not work. Then I test with 3 "int" but I always receive the error message: "Error: parse error", and I don't know why.
This is the structure of my message:
typedef struct {
unsigned int temperature;
unsigned int latitude;
unsigned int longitude;
} Payload;
Here is my code:
#include "IO_WSSFM10.h"
IO_WSSFM10 mySigfox(10, 11, true);
typedef struct {
unsigned int temperature;
unsigned int latitude;
unsigned int longitude;
} Payload;
unsigned int counter=0;
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
mySigfox.begin();
delay(50);
mySigfox.test();
mySigfox.getID();
mySigfox.getPAC();
mySigfox.getTemp();
//mySigfox.setPowerMode(1);
}
// the loop function runs over and over again forever
void loop() {
String sfResponse;
Payload p;
p.temperature = 1075847679;
p.latitude = 441300000;
p.longitude = 41000000;
bool statusS = mySigfox.send(&p, sizeof(p));
if (statusS) counter++;
delay(10000);
/*
bool statusSR = mySigfox.sendReceive(&p, sizeof(p), sfResponse);
if (statusS) {
for (uint8_t i= 0; i<26; ++i) {//RX= 01 02 03 04 05 06 07 08
Serial.println(sfResponse[i]);
counter++;
}
}*/
}
Could you help me please?

Related

(.text+0x0): multiple definition of `__vector_13'

Using NewPing.h seems to be the main issue.
Code:
#include <LedControl.h>
#include "pitches.h"
#include "SR04.h"
#include "NewPing.h"
#define TRIGGER_PIN 13
#define ECHO_PIN 8
#define MAX_DISTANCE 200
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
long duration;
int distance;
int DIN = 12;
int CS = 11;
int CLK = 10;
LedControl lc=LedControl(DIN,CLK,CS,0);
const int buzzer = 9;
void setup(){
lc.shutdown(0,false); //The MAX72XX is in power-saving mode on startup
lc.setIntensity(0,15); // Set the brightness to maximum value
lc.clearDisplay(0); // and clear the display
pinMode(buzzer, OUTPUT); //buzzer shit
pinMode(TRIGGER_PIN, OUTPUT); // Sets the trigPin as an OUTPUT
pinMode(ECHO_PIN, INPUT); // Sets the echoPin as an INPUT
Serial.begin(9600); // // Serial Communication is starting with 9600 of baudrate speed
}
void loop(){
unsigned int uS = sonar.ping();
Serial.print(uS / US_ROUNDTRIP_CM);
byte a[8]= {0x18,0x18,0x18,0x18,0x18,0x00,0x18,0x18,};
byte b[8]= {0x18,0x18,0x18,0x18,0x00,0x18,0x18,0x00,};
byte c[8]= {0x18,0x18,0x18,0x18,0x18,0x00,0x18,0x18,}; //done
byte d[8] = {0x00,0x18,0x18,0x18,0x18,0x18,0x00,0x18,}; //done
byte e[8]= {0x18,0x5a,0x3c,0x18,0x18,0x24,0x5a,0x18,}; //done
byte f[8]= {0x99,0x5a,0x18,0x18,0x18,0x00,0x5a,0x99,}; //done
byte g[8]= {0x99,0x18,0x18,0x18,0x18,0x00,0x18,0x99,};
byte h[8]= {0x18,0x18,0x18,0x18,0x18,0x00,0x18,0x18,};
if (uS <= 20){
printByte(a);
tone(buzzer, 1000);
delay(100);
printByte(b);
noTone(buzzer);
delay(100);
printByte(c);
tone(buzzer, 1000);
delay(100);
printByte(d);
noTone(buzzer);
delay(100);
printByte(e);
tone(buzzer, 1000);
delay (100);
printByte(f);
noTone(buzzer);
delay (100);
printByte(g);
tone(buzzer, 1000);
delay (100);
printByte(h);
noTone(buzzer);
delay(1000);
}
}
void printByte(byte character [])
{
int i = 0;
for(i=0;i<8;i++)
{
lc.setRow(0,i,character[i]);
}
}
The main thing that stands out in the error is the line
"(.text+0x0): multiple definition of `__vector_13'
C:\Users\name\AppData\Local\Temp\arduino_build_789753\libraries\NewPing\NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here".
However, I don't exactly know how to solve it.

Esp32: Dual Core task crashing even though same command works elsewhere

I have ventured beyond my ability in this one.
This project is for an IoT demo to some students. Using Telegram they can control some lighting as well as receive some notifications to events.
The following are confirmed to be working:
All lighting and lighting telegram messages
Temperature sensor and telegram messages
Door bell but NOT the telegram message
If bot.sendMessage(chat_id, "Someone is at the door.", ""); is added to the soundDoorbell() function then the following crash occurs
CORRUPT HEAP: Bad head at 0x3fff479c. Expected 0xabba1234 got
0x3ffffff8 abort() was called at PC 0x40086cd1 on core 0
ELF file SHA256: 0000000000000000
Backtrace: 0x40088904:0x3ffdc5d0 0x40088b81:0x3ffdc5f0
0x40086cd1:0x3ffdc610 0x40086dfd:0x3ffdc640 0x400f6bcf:0x3ffdc660
0x400f2ebd:0x3ffdc920 0x400f2e4c:0x3ffdc970 0x4008d25d:0x3ffdc9a0
0x40081f1e:0x3ffdc9c0 0x4008208d:0x3ffdc9e0 0x40123ca6:0x3ffdca00
0x4011706a:0x3ffdca20 0x400d3a28:0x3ffdca40 0x400d3629:0x3ffdca60
0x400d37fb:0x3ffdca80 0x400d38f1:0x3ffdcab0 0x400d464d:0x3ffdcad0
0x400d707d:0x3ffdcb00 0x400d15cd:0x3ffdcba0 0x400d16a3:0x3ffdcbc0
0x40089b92:0x3ffdcc00
Rebooting... ets Jun 8 2016 00:22:57
rst:0xc (SW_CPU_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT) configsip: 0,
SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1 load:0x3fff0018,len:4 load:0x3fff001c,len:1044
load:0x40078000,len:10124 load:0x40080400,len:5856 entry 0x400806a8
The decode stack shows:
0x40088904: invoke_abort at
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c
line 156 0x40088b81: abort at
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c
line 171 0x40086cd1: lock_acquire_generic at
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/locks.c
line 143 0x40086dfd: _lock_acquire_recursive at
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/locks.c
line 171 0x400f6bcf: _vfiprintf_r at
../../../.././newlib/libc/stdio/vfprintf.c line 860 0x400f2ebd:
fiprintf at ../../../.././newlib/libc/stdio/fiprintf.c line 50
0x400f2e4c: __assert_func at ../../../.././newlib/libc/stdlib/assert.c
line 59 0x4008d25d: multi_heap_free at
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap_poisoning.c
line 218 0x40081f1e: heap_caps_free at
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/heap_caps.c line 268 0x4008208d: esp_mbedtls_mem_free at
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/mbedtls/port/esp_mem.c
line 35 0x40123ca6: mbedtls_free at
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/mbedtls/mbedtls/library/platform.c
line 98 0x4011706a: mbedtls_ssl_free at
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/mbedtls/mbedtls/library/ssl_tls.c
line 8992 0x400d3a28: stop_ssl_socket(sslclient_context*, char const*,
char const*, char const*) at
C:\Users\abas034\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\WiFiClientSecure\src\ssl_client.cpp
line 272 0x400d3629: WiFiClientSecure::stop() at
C:\Users\abas034\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\WiFiClientSecure\src\WiFiClientSecure.cpp
line 93 0x400d37fb: WiFiClientSecure::connect(char const*, unsigned
short, char const*, char const*, char const*) at
C:\Users\abas034\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\WiFiClientSecure\src\WiFiClientSecure.cpp
line 154 0x400d38f1: WiFiClientSecure::connect(char const*, unsigned
short) at
C:\Users\abas034\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\WiFiClientSecure\src\WiFiClientSecure.cpp
line 112 0x400d464d: UniversalTelegramBot::sendGetToTelegram(String
const&) at C:\Users\abas034\UOA\OneDrive - The University of
Auckland\Documents\Arduino\libraries\UniversalTelegramBot\src\UniversalTelegramBot.cpp
line 73 0x400d707d: UniversalTelegramBot::getUpdates(long) at
C:\Users\ab\UOA\OneDrive - The University of
Auckland\Documents\Arduino\libraries\UniversalTelegramBot\src\UniversalTelegramBot.cpp
line 369 0x400d15cd: checkTelegramBot() at
C:\Users\ab\OneDrive\Documents\Projects\WorkingOn\IoT-Demo\HomeAutomationV3/HomeAutomationV3.ino
line 315 0x400d16a3: nonloopingCode(void*) at
C:\Users\ab\OneDrive\Documents\Projects\WorkingOn\IoT-Demo\HomeAutomationV3/HomeAutomationV3.ino
line 343 0x40089b92: vPortTaskWrapper at
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c
line 143
Given that the "bot.sendMessage" function works everywhere else, I can't work out why it would fail in this instance.
Code
#include
#include
#include
#ifdef ESP32
#include
#else
#include
#endif
#include
#include
#include
#include "DHTesp.h"
//Wifi & Telgram credentials
#include "config.h"
// Sensors & Control
#define pin_DHT11 4 //
#define pin_alarmsensor 2 //RCWL-0516
#define pin_siren 19
#define pin_led_veranda 26
#define pin_led_bedroom 25
#define pin_doorbell 27
DHTesp dht;
#define DATA_PIN 18
#define LED_TYPE WS2812
#define COLOR_ORDER GRB
#define NUM_LEDS 12
CRGB leds[NUM_LEDS];
#define BRIGHTNESS 50
#define FRAMES_PER_SECOND 120
bool alarmArmed = false;
bool alarmTriggered = false;
bool partyledson = false;
bool livingroomledson = false;
int buttonState;
int lastButtonState = LOW;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);
int botRequestDelay = 50;
unsigned long lastTimeBotRan;
char textoption;
String chat_id;
TaskHandle_t loopingTasks;
TaskHandle_t nonloopingTasks;
void GetTemperature() { //implemented
String message = "Temperature: ";
TempAndHumidity newValues = dht.getTempAndHumidity();
message.concat(String(newValues.temperature)); message.concat(".");
bot.sendMessage(chat_id, message, "");
}
void ToggleAlarm() {
alarmArmed = !alarmArmed;
if (alarmArmed) {
bot.sendMessage(chat_id, "Alarm armed.", "");
}
else bot.sendMessage(chat_id, "Alarm disarmed.", "");
}
void TogglePartylights() {
partyledson = !partyledson;
if (partyledson) {
livingroomledson = false;
bot.sendMessage(chat_id, "Party lights switched on.", "");
}
else bot.sendMessage(chat_id, "Party lights switched off.", "");
}
void ToggleVerandaLights() {
bool LightStatus = digitalRead(pin_led_veranda);
LightStatus = !LightStatus;
digitalWrite(pin_led_veranda, LightStatus);
LightStatus = digitalRead(pin_led_veranda);
if (LightStatus) {
bot.sendMessage(chat_id, "Veranda light switched on.", "");
}
else bot.sendMessage(chat_id, "Veranda light switched off.", "");
}
void ToggleLivingRoomLights() {
partyledson = false;
bool LightStatus = livingroomledson;
livingroomledson = !livingroomledson;
if (livingroomledson) {
for ( int i = 0; i (leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear();
FastLED.show();
Serial.println("Started");
pinMode(pin_siren, OUTPUT);
pinMode(pin_led_veranda, OUTPUT);
pinMode(pin_led_bedroom, OUTPUT);
pinMode(pin_alarmsensor, INPUT);
pinMode(pin_doorbell, INPUT_PULLUP);
// Connect to Wi-Fi
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
client.setCACert(TELEGRAM_CERTIFICATE_ROOT);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi..");
}
// Print ESP32 Local IP Address
Serial.println(WiFi.localIP());
Serial.println("Bot started?");
bot.sendMessage(CHAT_ID, "System restarted", "");
//create a task that will be executed in the Task1code() function, with priority 1 and executed on core 0
xTaskCreatePinnedToCore(
nonloopingCode, /* Task function. */
"nonloopingTasks", /* name of task. */
16384, /* Stack size of task */
NULL, /* parameter of the task */
1, /* priority of the task */
&nonloopingTasks, /* Task handle to keep track of created task */
0); /* pin task to core 0 */
delay(500);
xTaskCreatePinnedToCore(
juggle, /* Task function. */
"loopingTasks", /* name of task. */
16384, /* Stack size of task */
NULL, /* parameter of the task */
1, /* priority of the task */
&loopingTasks, /* Task handle to keep track of created task */
1); /* pin task to core 1 */
delay(500);
}
void checkTelegramBot() {
if (millis() > lastTimeBotRan + botRequestDelay) {
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
while (numNewMessages) {
Serial.println("Got response");
handleNewMessages(numNewMessages);
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
}
lastTimeBotRan = millis();
}
}
void nonloopingCode(void * pvParamters) {
Serial.print("nonloopingCode running on core ");
Serial.println(xPortGetCoreID());
for (;;) {
if ((!partyledson) && (!livingroomledson)) {
FastLED.clear();
FastLED.show();
}
if (alarmArmed) {
if (digitalRead(pin_alarmsensor)) {
bot.sendMessage(chat_id, "Alarm triggered", "");
partyledson = false;
alarmTriggered = true;
}
}
checkTelegramBot();
}
}
void juggle(void * pvParamters) {
Serial.print("Juggle running on core ");
Serial.println(xPortGetCoreID());
for (;;) {
checkDoorbell();
if (alarmTriggered)soundAlarm();
if (partyledson) {
fadeToBlackBy( leds, NUM_LEDS, 20);
byte dothue = 0;
int i = 0;
while ((i debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == LOW) {
soundDoorbell();
}
}
}
lastButtonState = reading;
}
void loop() {
}
I don't think the Telegram routines are threadsafe.
Using FreeRTOS mutexes (https://microcontrollerslab.com/arduino-freertos-mutex-tutorial-priority-inversion-priority-inheritance/), I managed to get it to work although there is lots of lag but that is an easier issue to sort out :)

Reading an absolute encoder with gray code output

I have an absolute encoder(Hengstler AD36) that gives 12 bit position value with gray code. I am trying to convert that value to decimal, I mean in degrees 0 to 360.
I have the 12 bit value in gray code by using Arduino.I have read the Arduino port and converted it in Python, but I need to do it in Arduino. But, I couldn't convert it to any meaningful numbers in Arduino.
///Pin setup for the Sensor
const int CLOCK_PIN = 18;
const int DATA_PIN = 19;
const int DATA_PIN2 = 17;
///12-bit sensor
const int BIT_COUNT = 12;
void setup() {
//setup our pins
pinMode(DATA_PIN, INPUT);
pinMode(CLOCK_PIN, OUTPUT);
//give some default values
digitalWrite(CLOCK_PIN, HIGH);
Serial.begin(9600);
}
void loop() {
unsigned long reading1 = readPosition1();
Serial.print(reading1,BIN);
Serial.print(",");
delay(50);
}
//read the current angular position
int readPosition1() {
unsigned long sample1 = shiftIn(DATA_PIN, CLOCK_PIN, BIT_COUNT);
delayMicroseconds(25); // delay for clock
return sample1;
}
//read in a byte of data from the digital input of the board.
unsigned long shiftIn(const int data_pin, const int clock_pin, const int bit_count) {
unsigned long data = 0;
for (int i=0; i<bit_count; i++) {
data <<= 1;
digitalWrite(clock_pin, LOW);
delayMicroseconds(1);
digitalWrite(clock_pin, HIGH);
delayMicroseconds(1);
data |= digitalRead(data_pin);
}
return data;
}
How can I convert data to decimal (0 to 360 degrees)?
The main problem that I couldn't solve, I found some functions that convert gray code to binary, then it is easy to convert it to decimal. However, these functions take input as string or int, and I have no idea about converting data value to int.
Any help would be greatly appreciated.
Thanks.

Merging two arduino sketches

I have been working on a project. I have two sketches. One is to get GPS location and one is send location via SMS (GSM Module). I want to combine both sketches.
GPS sketch:
#include <SoftwareSerial.h>
#include <TinyGPS.h>
//long lat,lon; // create variable for latitude and longitude object
float flat, flon;
SoftwareSerial gpsSerial(4, 3); // create gps sensor connection
TinyGPS gps; // create gps object
void setup(){
Serial.begin(9600); // connect serial
gpsSerial.begin(9600); // connect gps sensor
}
static void print_float(float val, float invalid, int len, int prec)
{
if (val == invalid)
{
while (len-- > 1)
Serial.print('*');
Serial.print(' ');
}
else
{
Serial.print(val, prec);
int vi = abs((int)val);
int flen = prec + (val < 0.0 ? 2 : 1); // . and -
flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
for (int i=flen; i<len; ++i)
Serial.print(' ');
}
// smartdelay(0);
}
void loop(){
while(gpsSerial.available()){ // check for gps data
if(gps.encode(gpsSerial.read())){ // encode gps data
// gps.get_position(&lat,&lon); // get latitude and longitude
gps.f_get_position(&flat, &flon);
String lat = String(flat,6);
String lon = String(flon,6);
Serial.print(lat);
Serial.print(' ');
Serial.println(lon);
}
}
}
GSM sketch:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(9, 10);
void setup()
{
mySerial.begin(9600); // Setting the baud rate of GSM Module
Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
delay(100);
}
int index=0;
long dlat=0,dlong=0;
char st[256],st1[256],st2[256];
void RecieveMessage()
{
mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
// mySerial.println("cheking");
// mySerial.println(string);
}
void loop()
{
if (Serial.available()>0)
RecieveMessage();
if (mySerial.available()>0)
{
//int st;
st[index++] = mySerial.read();
//Serial.write(st[index-1]);
if(index>=51&&index<=63){
st1[index-51]=st[index-1];
Serial.write(st1[index-51]);
}
if(index>=65&&index<=77){
st2[index-65]=st[index-1];
Serial.write(st2[index-65]);
}
/*if(index==77)
{
int i=0;
mySerial.print(st1);
for(i=0;i<13;i++)
{
if(st1[i]!='.')
dlat=dlat*10+(st1[i]-'0');
if(st2[i]!='.')
dlong=dlong*10+(st2[i]-'0');
//Serial.print(dlat);
}
//Serial.print(dlat);
//Serial.print(" ");
//Serial.print(dlong);
*/
}
}
I want to merge these two sketches so that I can send location via GSM sketch and receive location through GPS sketch.
Any help will be appreciated.
Thanks.
The following way you can merge your two sketches :
#include <AltSoftSerial.h>
#include <SoftwareSerial.h>
#include <TinyGPS.h>
//long lat,lon; // create variable for latitude and longitude object
float flat, flon;
SoftwareSerial gpsSerial(4, 3); // create gps sensor connection
TinyGPS gps; // create gps object
static const int RXPin = 8, TXPin = 9;
AltSoftSerial mySerial(RXPin, TXPin);
int index=0;
long dlat=0,dlong=0;
char st[256],st1[256],st2[256];
void RecieveMessage()
{
mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
// mySerial.println("cheking");
// mySerial.println(string);
}
void setup(){
Serial.begin(9600); // connect serial
gpsSerial.begin(9600); // connect gps sensor
mySerial.begin(9600); // Setting the baud rate of GSM Module
delay(100);
}
static void print_float(float val, float invalid, int len, int prec)
{
if (val == invalid)
{
while (len-- > 1)
Serial.print('*');
Serial.print(' ');
}
else
{
Serial.print(val, prec);
int vi = abs((int)val);
int flen = prec + (val < 0.0 ? 2 : 1); // . and -
flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
for (int i=flen; i<len; ++i)
Serial.print(' ');
}
// smartdelay(0);
}
void loop(){
while(gpsSerial.available()){ // check for gps data
if(gps.encode(gpsSerial.read())){ // encode gps data
// gps.get_position(&lat,&lon); // get latitude and longitude
gps.f_get_position(&flat, &flon);
String lat = String(flat,6);
String lon = String(flon,6);
Serial.print(lat);
Serial.print(' ');
Serial.println(lon);
if (Serial.available()>0)
RecieveMessage();
if (mySerial.available()>0)
{
//int st;
st[index++] = mySerial.read();
//Serial.write(st[index-1]);
if(index>=51&&index<=63){
st1[index-51]=st[index-1];
Serial.write(st1[index-51]);
}
if(index>=65&&index<=77){
st2[index-65]=st[index-1];
Serial.write(st2[index-65]);
}
/*if(index==77)
{
int i=0;
mySerial.print(st1);
for(i=0;i<13;i++)
{
if(st1[i]!='.')
dlat=dlat*10+(st1[i]-'0');
if(st2[i]!='.')
dlong=dlong*10+(st2[i]-'0');
//Serial.print(dlat);
}
//Serial.print(dlat);
//Serial.print(" ");
//Serial.print(dlong);
*/
}
}
}
}
P.S : I have changed the pins for GPS and rest part is same irrespective of adding AltSoftSerial it is a library same as SoftwareSerial (Download it from manage libraries and it requires pins 8 and 9)

Publishing a value through PubSubClient

I tried the following code to publish a value using Arduino onto Mosquitto broker. The code appears to be right but then as soon as I compile/verify, the following error is thrown. What's the cause and how do I overcome this problem?
#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>
#define CLIENTID "ArduinoSensor"
#define TOPICNAME "sensor/temperature"
#define POLLINTERVAL 120000
void callback(char topic, byte payload, unsigned int length){
//Do nothing as we are publishing ONLY.
}
byte mac [] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED} ;
byte server [] = { 85, 119, 83, 194 };
EthernetClient ethClient;
PubSubClient arduinoClient(server, 1883, callback, ethClient) ;
unsigned long boardTime = 0 ;
float sensedTemperature = 0;
char charTemperature [20];
void setup(void) {
Serial.begin(9600);
//Connect to the MQTT server - test.mosquitto.org
beginConnection() ;
}
//Initialise MQTT connection
void beginConnection() {
Serial.begin(9600);
Ethernet.begin(mac) ; //using the address assigned through DHCP
int connRC = arduinoClient.connect(CLIENTID) ;
if (!connRC) {
Serial.println(connRC) ;
Serial.println("Could not connect to MQTT Server");
Serial.println("Please reset the arduino to try again");
delay(100);
exit(-1);
}
else {
Serial.println("Connected to MQTT Server...");
}
}
void loop(void) {
boardTime = millis();
if ((boardTime % POLLINTERVAL) == 0) {
getTemp();
dtostrf(sensedTemperature,5,2,charTemperature) ;
arduinoClient.publish(TOPICNAME, charTemperature) ;
}
}
void getTemp() {
// Send the command to get temperatures
delay(100);
sensedTemperature = analogRead(2); //temperature sensor at analog pin 2 on Arduino.
delay(150);
}
Error Printed:
publisher:18: error: invalid conversion from 'void (*)(char, byte, unsigned int) {aka void (*)(char, unsigned char, unsigned int)}' to 'void (*)(char*, uint8_t*, unsigned int) {aka void (*)(char*, unsigned char*, unsigned int)}' [-fpermissive]
PubSubClient arduinoClient(server, 1883, callback, ethClient) ;
C:\Users\Chetan\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:98:4: error: initializing argument 3 of 'PubSubClient::PubSubClient(uint8_t*, uint16_t, void (*)(char*, uint8_t*, unsigned int), Client&)' [-fpermissive]
PubSubClient(uint8_t *, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);
^
exit status 1
invalid conversion from 'void (*)(char, byte, unsigned int) {aka void (*)(char, unsigned char, unsigned int)}' to 'void (*)(char*, uint8_t*, unsigned int) {aka void (*)(char*, unsigned char*, unsigned int)}' [-fpermissive]
In file included from C:\Users\Chetan\Desktop\publisher\publisher.ino:4:0:
Any suggestions?
The error message is telling you that the signature of the callback function you are passing to the constructor is incorrect.
You have:
void callback(char topic, byte payload, unsigned int length){
It should be:
void callback(char* topic, byte* payload, unsigned int length) {
Note the * for the topic and payload arguments.

Resources