I have a sender that has a bitmap array that represents an image I've downloaded, the sender sends the pixels to the receiver, the receiver then should receive the pixels insert them into another bitmap array and display the same picture
below is my sender sketch:
static const unsigned char PROGMEM myBitmap[] ={
0x00, 0x00, 0x00, 0x00, 0x11, 0xff, 0xff, 0xff, 0xff, 0xdf, 0x07, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x21, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xc7, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc1, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xe3, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x31, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xf2, 0x71, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x11, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x31, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x31, 0xff, 0xff, 0xc0, 0x3f, 0xff, 0xfc, 0x7f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x71, 0xff, 0xff, 0xe0, 0x1f, 0xff, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x71, 0xff, 0xff, 0xf0, 0x07, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf3, 0xff, 0xff, 0xf0, 0x03, 0xef, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xff, 0xff, 0xf0, 0x03, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xff, 0xff, 0xf8, 0x01, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xff, 0xff, 0xf0, 0x00, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xff, 0xff, 0xe0, 0x00, 0x7f, 0x8f, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xff, 0xff, 0x80, 0x00, 0x7f, 0x0f, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf9, 0xfe, 0xff, 0x80, 0x00, 0x3c, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xfe, 0xff, 0xc0, 0x00, 0x10, 0x0f, 0xe0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xfe, 0xff, 0xc0, 0x00, 0x00, 0x0f, 0xe0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xfe, 0xff, 0xc0, 0x00, 0x00, 0x0f, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xfe, 0x7f, 0xe0, 0x00, 0x00, 0x1f, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xfe, 0x7f, 0xff, 0x38, 0x00, 0xdf, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xfe, 0x7f, 0xff, 0xf8, 0x01, 0xbf, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xfe, 0x7f, 0xff, 0xf0, 0x07, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xfe, 0x3f, 0xff, 0xe0, 0x1c, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xff, 0x3f, 0xff, 0xc0, 0x39, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xff, 0x3f, 0xff, 0x80, 0x3f, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xff, 0x3f, 0xff, 0x00, 0x3f, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xff, 0xff, 0xfe, 0x00, 0x1f, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xff, 0xff, 0xfc, 0x00, 0x1f, 0xf8, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xff, 0xff, 0xf8, 0x70, 0x1f, 0xf8, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xff, 0xff, 0xf0, 0xf8, 0x7f, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xff, 0xff, 0xf1, 0xfc, 0xff, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xfd, 0xff, 0xe3, 0xdc, 0xff, 0xf0, 0x1f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xff, 0xff, 0xe7, 0xdc, 0xff, 0xe0, 0x38, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xff, 0xff, 0xcf, 0xdc, 0xff, 0xe0, 0x70, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf9, 0xff, 0xff, 0xde, 0x0c, 0x7f, 0xe0, 0xe0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf9, 0xff, 0xff, 0xbf, 0x1e, 0x7d, 0xe3, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf9, 0xff, 0xff, 0xbf, 0x1e, 0xff, 0xc7, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf9, 0xff, 0xff, 0x7f, 0xbe, 0xff, 0xc7, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xcf, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xdf, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xff, 0xfb, 0xff, 0xf8, 0xff, 0x9f, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xff, 0xe7, 0xff, 0xff, 0xff, 0x8f, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xff, 0xef, 0xff, 0xfb, 0xff, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xff, 0xef, 0xff, 0xff, 0xfe, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf9, 0xff, 0xef, 0xff, 0xf3, 0xfe, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf9, 0xff, 0xff, 0xff, 0xe3, 0xfe, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf1, 0xff, 0xff, 0xff, 0xf3, 0xfe, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xf8, 0x7f, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf9, 0xff, 0xff, 0xff, 0xf8, 0x3f, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xb8, 0xff, 0xff, 0xff, 0xf0, 0x0f, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xb9, 0xff, 0xff, 0xff, 0xf8, 0x0f, 0xfe, 0x3f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x99, 0xff, 0xff, 0xff, 0xf8, 0x07, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xd9, 0xff, 0xff, 0xff, 0xfc, 0x06, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xd8, 0xff, 0xff, 0xff, 0xfc, 0x07, 0xf8, 0x7f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xd8, 0xff, 0xff, 0xff, 0xfc, 0x03, 0xfc, 0x7f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xd8, 0xff, 0xff, 0xff, 0xfe, 0x03, 0xfc, 0x7f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xd8, 0xff, 0xff, 0xff, 0xfe, 0x03, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xd9, 0xff, 0xff, 0xff, 0xff, 0x01, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xd9, 0xff, 0xff, 0xff, 0xff, 0x01, 0xf9, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xd8, 0xff, 0xff, 0xff, 0xff, 0x01, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc8, 0xff, 0xff, 0xff, 0xff, 0x81, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc9, 0xff, 0xff, 0xff, 0xff, 0x80, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
};
void setup() {
//initialize Serial Monitor
Serial.begin(115200);
while (!Serial);
Serial.println("LoRa Sender");
//setup LoRa transceiver module
LoRa.setPins(ss, rst, dio0);
//replace the LoRa.begin(---E-) argument with your location's frequency
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
while (!LoRa.begin(915E6)) {
Serial.println(".");
delay(500);
}
// Change sync word (0xF3) to match the receiver
// The sync word assures you don't get LoRa messages from other LoRa transceivers
// ranges from 0-0xFF
LoRa.setSyncWord(0xF3);
Serial.println("LoRa Initializing OK!");
}
void loop() {
LoRa.beginPacket();
Serial.print("Sending packet");
LoRa.printf("0xx\n",myBitmap[i]);
i=i 1;
LoRa.endPacket();
ID=ID 1;
below is my receiver sketch:
void setup() {
//initialize Serial Monitor
Serial.begin(115200);
while (!Serial);
Serial.println("LoRa Receiver");
//setup LoRa transceiver module
LoRa.setPins(ss, rst, dio0);
//replace the LoRa.begin(---E-) argument with your location's frequency
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
while (!LoRa.begin(915E6)) {
Serial.println(".");
delay(500);
}
// Change sync word (0xF3) to match the receiver
// The sync word assures you don't get LoRa messages from other LoRa transceivers
// ranges from 0-0xFF
LoRa.setSyncWord(0xF3);
Serial.println("LoRa Initializing OK!");
}
void loop() {
char buff[4]={0};
char c;
// try to parse packet
static unsigned char PROGMEM myBitmap [200]={};
int packetSize = LoRa.parsePacket();
uint8_t ix = 0;
if (packetSize) {
char buff[4] = {0};
while (LoRa.available()) {
Serial.print("this is the data");
buff[ix]=(char)LoRa.read();
}
Serial.print("this is the string\n");
Serial.print(finall);
// print RSSI of packet
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
}
}
the problem that is at the receiver side, I am unable to create an array and put in it the pixels that are succesfully sent from the sender Any help would be appreciated Thank You
CodePudding user response:
Your message-reading loop doesn't increment the index counter:
buff[ix]=(char)LoRa.read();
should be
buff[ix ]=(char)LoRa.read();
In case there may be more than 255 chars in one read, I'd declare ix
at least 16-bit:
uint16_t ix = 0;
Also, you are declaring buff
twice.
Also, to be safe, are you sure 4 bytes is enough?
CodePudding user response:
If you mean you don't know how to create an array, you can first make your program send the size of the array and do dynamic memory allocation.
unsigned char *arr = malloc(size);
Then you can copy the received buffer to here