Closed oussama415 closed 2 years ago
Hi @oussama415,
Which sample program are you referring to?
Best regards, Benoit
Hi @bblanchon Thanks for your fast reply This is a simple code for transmitting
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#include <ArduinoJson.h>
RF24 radio(7, 8); // nRF24L01 (CE,CSN) (7,8)
RF24Network network(radio); // Include the radio in the network
const uint16_t this_node = 00; // Address of this node in Octal format
const uint16_t node01 = 01;
void setup()
{
Serial.begin(115200);
SPI.begin();
radio.begin();
network.begin(90, this_node);
radio.setDataRate(RF24_2MBPS);
}
void loop()
{
network.update();
StaticJsonDocument<300> doc;
doc["var1"] = 50;
RF24Adapter radioForArduinoJson(radio); // Not sending
serializeJson(doc, radioForArduinoJson); // I get nothing like this : {}
//---------------------- Sending normally char type----------------------------//
// RF24NetworkHeader header1(node01); // (Address where the data is going)
// network.write(header1, &json1, sizeof(json1));
//---------------------- Sending normally char type----------------------------//
}
i have nothing in return for the line : serializeJson(doc, radioForArduinoJson); i want to serialize in JSON Format and send it by radio
I see you have already make a class for RF24Adapter, i don't know when exactly i copy it !!!
This is the class :
class RF24Adapter {
public:
RF24Adapter(RF24 &radio) : _radio(&radio) {}
int read() {
char buf[1];
_radio->read(buf, 1);
return buf[0];
}
size_t readBytes(char *buffer, size_t length) {
_radio->read(buffer, static_cast<uint8_t>(length));
return length;
}
size_t write(uint8_t c) {
return _radio->write(&c, 1) ? 1 : 0;
}
size_t write(const uint8_t *buffer, size_t length) {
return _radio->write(buffer, static_cast<uint8_t>(length)) ? length : 0;
}
private:
RF24 *_radio;
};
Thanks for your help !
Hi @oussama415,
I have no experience with RF24Network and I cannot spot any obvious mistake in the code, so I cannot help you. Here are a few ideas to troubleshoot this issue:
String
RF24Adapter
Please let me know how you solve your issue, so other users can find the answer in this conversation. If there is enough material, I will add a dedicated page on arduinojson.org
Best regards, Benoit
Any progress, @oussama415?
No progress, the solution is to make a message with JSON format a with a char and send it by RF24 but the problem is the maximum we can send but RF24 is 32 bytes !!!
Le ven. 1 oct. 2021 à 07:26, Benoît Blanchon @.***> a écrit :
Any progress, @oussama415 https://github.com/oussama415?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/bblanchon/ArduinoJson/issues/1653#issuecomment-931945768, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANWNOHF2PK3U2J4HFNMTMY3UEVIBXANCNFSM5EAQJ77A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
--
KHOURIBACHE OUSSAMA
Ingénieur en Génie Electrique et Contrôle Industriel - FST Mohammedia
Email : @.***
Tel : 06.08.28.23.47
I didn't know RF24 was limited to 32 bytes. That makes it a very bad candidate for JSON.
I recommend that you send binary structures instead. If you don't know what I'm talking about, please watch the first part of this video.
Hi, I have a problem when i use ArduinoJson with the RF24 library I want to serialize it in JSON Format and after that sending it with RF24 !!!!
When i copy a sample code in my RF24 code, before sending by RF24, the function serialize return nothing {} : what it return !!!
Can you help me please 👍