I am building an arduino project that requests status from raspberry pi server running django web application. The web app is simple, it stores status of one switch in database (True or False meaning On or Off). I have a view that returns simple string with the status in form "Status:1" or "Status:0".
The problem is that sometimes the response from the server is in a form of long string consisted of unicode characters. The characters are unknown to me when I copy-paste them from Arduino IDE Serial Monitor they look like this: '⸮'. The arduino code repeatly loads this page and checks for status to update the HW in my project. The length of this string is completely random and sometimes even infinite. The occurence is also random so I cannot predict when it happens therefore why it happens.
The problem it is causing me is that I am parsing the response from the server on my arduino and when this infinite string occurs the program on the board freezes because it is parsing it practicaly forever. That is simply unacceptable.
The code that reads the response from server on arduino is:
while(client.connected() || client.available()){
char c = client.read();
Serial.print(c);
}
It is not the code I use to parse the response, it is just code I used to find out what is the problem by outputing the response. I am attaching the screen of serial monitor window so you can see the problem (at the end of question). To parse response I use TextFinder.
The view code that creates the response in django:
def state(request, room_name):
room = Light.objects.get(light_name=room_name)
out = ""
if room.light_status:
out = "Status:1\t"
else:
out = "Status:0\t"
return HttpResponse(out)
Do any of you have any idea what could be causing this problem?
I also have one more problem that might be connected to this one but I am not sure. Sometimes the response value is wrong which causes the LED to blink (just for one iteration at random time, this might be caused by delay from server who knows).
EDIT: I thought the ASCII value of the character could be of some use. It is 255 (the last ASCII character).