Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mirobot throws Jason parse error after first command. #2

Open
janislejins opened this issue Jul 3, 2017 · 4 comments
Open

Mirobot throws Jason parse error after first command. #2

janislejins opened this issue Jul 3, 2017 · 4 comments

Comments

@janislejins
Copy link

I'm a student at the royal college of art looking to extend the core functionality of Mirobot for a project.

Unfortunately after sending the first command (like mirobot forward, pen down etc) I get a Jason error and the whole process stalls. Is there a work around(?) can post code if required.

@janislejins
Copy link
Author

*Json error (sorry on phone)

@orgicus
Copy link

orgicus commented Aug 10, 2017

@janislejins Having a read through the library I spotted this section.
For every message sent, if there are any errors, they will be raised/thrown.

One option could be to wrap each call within a try/except block.
The other is to setup an errorNotify callback so you can simply print these errors to the console instead of halting the program execution:

e.g.

from mirobot import Mirobot

def onMirobotError(x, msg, timeout,mirobotInstance):
	print x,msg,timeout,mirobotInstance

# Connect to Mirobot
mirobot = Mirobot()
mirobot.autoConnect()
# pass error notifications to the callback above instead of halting execution
mirobot.errorNotify(onMirobotError)

# Move forward 100mm
mirobot.forward(100)

bare in mind the above is Python 2 syntax, use print() for Python 3 (or simply pass if you don't really case :P)

@tobiasbp
Copy link

tobiasbp commented May 3, 2018

I also get errors when using this library (And I don't know how to make code pastes like right here?).

tbp@vaio:~/Documents/opfinderklubben/mirobot/python$ ./ok.py {u'devices': [{u'id': u'Mirobot-d2f5', u'updated': u'2018-05-03T13:32:55.254Z', u'name': u'Mirobot-d2f5', u'address': u'192.168.1.239'}, {u'id': u'Mirobot-e6ef', u'updated': u'2018-05-03T13:30:24.240Z', u'name': u'Mirobot-e6ef', u'address': u'192.168.1.161'}]} {"msg":"2.0.9","id":"cCgm0001","status":"complete"} {"msg":"JSON parse error","status":"error"} Traceback (most recent call last): File "./ok.py", line 14, in <module> mirobot.forward(10) File "/home/tbp/.local/lib/python2.7/site-packages/mirobot/__init__.py", line 107, in forward return self.__send('forward', distance, distance/20) File "/home/tbp/.local/lib/python2.7/site-packages/mirobot/__init__.py", line 144, in __send return self.__send_or_raise(msg, timeout) File "/home/tbp/.local/lib/python2.7/site-packages/mirobot/__init__.py", line 176, in __send_or_raise raise IOError("Received message ID (%s) does not match expected (%s)" % (rx_id, msg_id)) IOError: Received message ID (???) does not match expected (cCgm0002) {"id":"cCgm0002","status":"accepted"} {"msg":"JSON parse error","status":"error"} {"id":"cCgm0002","status":"complete"} Terminated

This is the programme I'm running:
from mirobot import Mirobot mirobot = Mirobot() mirobot.autoConnect('Mirobot-d2f5') mirobot.forward(10)

@orgicus
Copy link

orgicus commented May 4, 2018

@tobiasbp for now, can you try something like this:

from time import sleep
from mirobot import Mirobot

def onMirobotError(x, msg, timeout,mirobotInstance):
	print x,msg,timeout,mirobotInstance

# Connect to Mirobot
mirobot = Mirobot()
mirobot.autoConnect('Mirobot-d2f5')
# pass error notifications to the callback above instead of halting execution
mirobot.errorNotify(onMirobotError)

# try to move forward 10mm
mirobot.forward(10)

#wait 3s
sleep(3)
#try again
mirobot.forward(10)

Hopefully the program won't crash but display the error message instead and maybe work on the following commands ¯_(ツ)_/¯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants