Copyright © https://mongoose-os.com

Mongoose OS Forum

frame
ATTENTION! This forum has moved to:

https://community.mongoose-os.com

Do not post any new messages.

Bugs in rpc-service-i2c?

ulsoulso Stockholm

I have been trying the I2C services and there seems to be a bug in i2c_read_reg_handler as it always returns an error message when used with the I2C.ReadRegB and I2C.ReadRegW services.

Looking in https://github.com/mongoose-os-libs/rpc-service-i2c/blob/master/src/mgos_i2c_service.c, around line 135, it seems that a successfully read value is never reported, just the error message.

Also - I have found that, on the CC3200, I2C.Scan doesn't work. That's because the I2C scan loop uses zero length writes, which doesn't seem to be supported by the CC3200. Maybe it would be better to use one byte reads in the scan loop?

Comments

  • ulsoulso Stockholm

    The i2c_read_reg_handler actually always returns the message "No result" in the web ui, and Call complete, error: <nil> in the log.

  • ulsoulso Stockholm

    I think the bug in i2c_read_reg_handler was introduced in the June 13 commit. For some reason the following change was made:

    out:
     -  if (err_code != 0) {
     -    mg_rpc_send_errorf(ri, err_code, "%s", err_msg);
     -  } else {
     -    mg_rpc_send_responsef(ri, "{value: %d}", value);
     -  }
     +  mg_rpc_send_errorf(ri, err_code, "%s", err_msg);
     +  ri = NULL;
    

    So, now it returns an error message even if the read was successful.

  • SergeySergey Dublin, Ireland
    edited June 2017

    Ah, that was me. Apologies, let me fix that. "no error" condition must never add an error object to the reply frame.
    Also, we don't have I2C RPC service in the CI.

  • SergeySergey Dublin, Ireland

    That has been fixed.

  • ulsoulso Stockholm

    Thanks Sergey. But, the I2C.ReadReg(B|W) always return "null" on successful reads. It should return something like { "value" : <the value> }, I think?

  • ulsoulso Stockholm

    At line 145 of https://github.com/mongoose-os-libs/rpc-service-i2c/blob/master/src/mgos_i2c_service.c you should probably replace

    mg_rpc_send_responsef(ri, NULL);
    

    with

    mg_rpc_send_responsef(ri, "{value: %d}", value);
    
    Thanked by 1Sergey
  • SergeySergey Dublin, Ireland

    @ulso doh ;) fixed, thank you.

Sign In or Register to comment.