Reputation: 1
Here is the code sent from Arduino:
void sendDescription() {
delayStart = millis();
delayRunning = true;
message = readStringFromEEPROM(0);
SerialDebug.print("{\"H\":[{\"Name\":\"Light\",\"ID\":\"00001\",\"Loca\":\"li\"}],\"F\":[{\"Name\":\"00000\",\"vR\":\"000000\"},{\"Name\":\"00001\",\"vR\":\"000000\"},{\"Name\":\"00100\",\"vR\":\"000000\"}],\"S\":[{\"stand\":\"AES\",\"ver\":\"128\"}],\"C\":[{\"stand\":\"blue\",\"ver\":\"4.0\"}]}");
while (!SerialDebug.available()) {
if (delayRunning && ((millis() - delayStart) >= 10000)) {
delayRunning = false; // Prevent this code being run more then once
SerialDebug.print("{\"H\":[{\"Name\":\"Light\",\"ID\":\"00001\",\"Loca\":\"li\"}],\"F\":[{\"Name\":\"00000\",\"vR\":\"000000\"},{\"Name\":\"00001\",\"vR\":\"000000\"},{\"Name\":\"00100\",\"vR\":\"000000\"}],\"S\":[{\"stand\":\"AES\",\"ver\":\"128\"}],\"C\":[{\"stand\":\"blue\",\"ver\":\"4.0\"}]}");
}
delay(1);
}
while (true) {
reply_mess = SerialDebug.readString();
if (reply_mess == "Resend") {
Serial.println(String(reply_mess));
//SerialDebug.print(EEPROM.readString(address));
//Serial.println(EEPROM.readString(address));
SerialDebug.print("{\"H\":[{\"Name\":\"Light\",\"ID\":\"00001\",\"Loca\":\"li\"}],\"F\":[{\"Name\":\"00000\",\"vR\":\"000000\"},{\"Name\":\"00001\",\"vR\":\"000000\"},{\"Name\":\"00100\",\"vR\":\"000000\"}],\"S\":[{\"stand\":\"AES\",\"ver\":\"128\"}],\"C\":[{\"stand\":\"blue\",\"ver\":\"4.0\"}]}");
while (!SerialDebug.available()) {
delay(1);
}
continue;
}
if (reply_mess == "OK") {
SerialDebug.print(String("O"));
break;
}
else {
Serial.println(String(reply_mess));
Serial.println(String("ERROR DESSCRIPTION"));
}
}
}
This is the code to receive the character string stored in the EEPROM sent from the Arduino of the Raspberry Pi
def receiveDescription():
while True:
while True:
rcv = ser.read();
sleep(0.03)
data_left = ser.inWaiting() # Check for remaining byte
rcv += ser.readline(data_left)
break
if chr(rcv[len(rcv)-1]) != '}': # chua toi uu
print("Decription: {}".format(str(rcv, 'utf-8')))
resend_desc = "Resend"
ser.write(str(resend_desc).encode('utf-8'))
continue
else:
print("Decription: {}".format(str(rcv, 'utf-8')))
resend_desc = "OK"
ser.write(str(resend_desc).encode('utf-8'))
while True:
rcv_ack = ser.read();
sleep(0.03)
ack_left = ser.inWaiting() # Check for remaining byte
rcv_ack += ser.readline(ack_left)
break
print("Reply: {}".format(str(rcv_ack, 'utf-8')))
with open("description.json", "w", encoding='utf-8') as outfile:
json.dump(json.loads(str(rcv, 'utf-8')), outfile, ensure_ascii=False)
break
I want the Raspberry Pi side to receive the following information: {"H":[{"Name":"Light","ID":"00001","Loca":"li"}],"F": [{"Name":"000000","vR":"000000"},{"Name":"00001","vR":"000000"},{"Name":"00100","vR": "000000"}],"S":[{"stand":"AES","ver":"128"}],"C":[{"stand":"blue","ver":"4.0 "}]}
Upvotes: 0
Views: 79