Good day everyone. My very first post here. I hope I place all the needed information right, and please correct me if I’m wrong.
I’m trying to setup a simple PJON network. In this network I’m using an ESP-32 as a command module, and several Arduino nano’s as worker modules that control single parts of the escape box I’m building. The Arduinos only have to send their state to the ESP-32, and the ESP-32 is telling the nano’s what to do. To make this possible I make use of the PJON SerialBitBang library. The PJON documentation is really good and I love the single wire communication.
To make the communication possible, I want to make use of a simple struct consisting of an integer and a small character array.
struct payLoad {
uint8_t cmd;
char msgLine[20];
};
When I let the receiver print the struct, the integer gets printed fine. However, when I want to print the msgLine char array, I see the following:
Serial Monitor output:
10
1{
The integer (10) shows as sent.
The character array “12345” however is not. Only the 1 is shown.
So my question: Can someone please point out to me what I am doing wrong here?
I'm near 100% sure that this is not a PJON related issue, but rather me missing a detail here.
Code that can be used to reproduce the issue:
Arduino worker:
#include <PJONSoftwareBitBang.h>
PJONSoftwareBitBang bus(19);
struct payLoad {
uint8_t cmd;
char msgLine[20];
};
payLoad pl;
void send_command(uint8_t id, uint8_t cmd, char msgLine[20]) {
payLoad pl;
strcpy(pl.msgLine , msgLine);
pl.cmd = cmd;
bus.send(id, &pl, sizeof(&pl));
};
void setup() {
bus.strategy.set_pin(8);
bus.begin();
}
void loop() {
send_command(20,10,"12345");
bus.update();
delay(2000);
}
Code for the receiving ESP-32:
// Command module running on an ESP32.
#include <PJONSoftwareBitBang.h>
PJONSoftwareBitBang bus(20);
// STRUCTS
struct payLoad {
uint8_t cmd;
char msgLine[20];
};
payLoad pl;
void receiver_function(uint8_t *payload, uint16_t length, const PJON_Packet_Info &packet_info) {
memcpy(&pl, payload, sizeof(pl));
Serial.println(pl.cmd);
Serial.println(pl.msgLine);
};
void setup() {
Serial.begin(9600);
bus.strategy.set_pin(25);
bus.set_receiver(receiver_function);
bus.begin();
}
void loop() {
bus.receive(10000);
}
Cursieve tekst