Ah,
Sorry about the mistake in my code. That's what comes of trying to write code without having a physical system to hand.
As a bit of explanation, my mistake arose because on the Python code that is running on the robot, the sensor reading object does have a member called 'data'. However, when it's transferred over the network, all of the sensor readings are converted to a string in a format called
JSON. Then when it gets to the py_websockets_bot library (i.e. your script), the JSON string is converted into a Python dictionary so that you can easily access the values.
Hope that makes a bit of sense. One thing you can do when learning about Python and dictionaries is to print them out, as this can make their structure a lot easier to understand. So for example try
- Code: Select all
print sensor_dict
Also, one thing I found very useful when learning Python was just to open up the interpreter by running 'python' on the command line and typing stuff in based on the
documentation and the excellent official
tutorial. I found Python quite a fun language to learn.
On a completely separate note, could I be cheeky and ask for you to vote for us in
this competition. Basically it's a chance to win £20,000 in funding which we're hoping to use to create freely available educational materials for schools giving lesson plans for the Raspberry Pi robot (although it should also be applicable to other Raspberry Pi robots as well). We need to reach 250 votes to make it to the next round, so any help is much appreciated.
Regards
Alan