Hi am trying to use to 2 arduino UNO each is connected to nrf24l01 and am trying to send an array of char from other to the other
and on the other am trying to (ajson) to get the value for (red, green , blue).
The problem was at the beginning it work correct but after while the json stop working.
code for transmitter
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
static char message[28] = {"{\"Blue\":255,\"Red\":255}"};
RF24 radio(9,10);
// Network uses that radio
RF24Network network(radio);
// Address of our node
const uint16_t this_node = 1;
// Address of the other node
const uint16_t other_node = 0;
void setup() {
Serial.begin(9600);
Serial.println("RF24Network/examples/helloworld_tx/");
SPI.begin();
radio.begin();
network.begin(/*channel*/ 90, /*node address*/ this_node);
}
void loop() {
// Pump the network regularly
network.update();
Serial.print("Sending...");
RF24NetworkHeader header(/*to node*/ other_node);
bool ok = network.write(header,&message,sizeof(message));
if (ok){
Serial.println(message);
Serial.println("ok");
}
else{
Serial.println("failed.");
}
delay(1000);
}
Code for Recevier
#include <Adafruit_NeoPixel.h>
#include <MirfHardwareSpiDriver.h>
#include <aJSON.h>
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#define PIN 6
#include "pitches.h"
#include <avr/pgmspace.h>
//aJsonObject* root = aJson.createObject();
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
int noteDurations[] = {1,2,3,4,5,6,7,8,9,9,8,7,6,5,4,3,2,1};
int melody[] = { NOTE_A3};
//aJsonObject* AfterReceive;
aJsonObject* AfterReceive = aJson.createObject();
//Red
aJsonObject* query;
//Green
aJsonObject* query1;
static char message[30];
// CE, CSN
RF24 radio(9,10);
// Network uses that radio
RF24Network network(radio);
// Address of our node
const uint16_t this_node = 0;
// Address of the other node
const uint16_t other_node = 1;
void setup()
{
Serial.begin(9600);
Serial.println("Hello");
//--- Setup ALL rf radios
SPI.begin();
radio.begin();
network.begin(/*channel*/ 90, /*node address*/ this_node);
strip.begin();
strip.show();
}
void loop()
{
// Pump the network regularly
network.update();
// Is network available?
while(network.available())
{
RF24NetworkHeader header;
network.read(header,message,sizeof(message));
Serial.println("Received: ");
Serial.println(message);
AfterReceive = aJson.parse(message);
Serial.println("After Json parse");
if (AfterReceive != NULL){
Serial.println("Inside if");
query = aJson.getObjectItem(AfterReceive , "Red");
int string =int( aJson.print(query));
Serial.print(query->valueint);
Serial.println("");
strip.setPixelColor(0,int(query),0,0);
query1 = aJson.getObjectItem(AfterReceive , "Blue");
char* string1 = aJson.print(query1);
Serial.print(query1->valueint);
aJson.deleteItem(query1);
strip.setPixelColor(1,0,0,int(query1));
strip.setPixelColor(2,int(query),0,int(query1));
strip.show();
query = NULL;
query1 = NULL;
delay(1000);
Serial.println("");
break;
delay(2000);
}}}
Thanks in advanced