I am trying to encode some accelerometer data using nanopb, but this error pops up no matter which data type I try to encode:

no match for 'operator=' (operand types are 'pb_callback_t {aka pb_callback_s}' and 'String')

I have tried with ints and strings with the same result, only with ints I get Int instead of String in the error message. My proto file looks like this:

syntax = "proto2";
message accelMessage {
    repeated string values = 1;

and my code on Arduino is:

#include "pb_encode.h"
#include "accel.pb.h"

String accelString;
uint8_t buffer[120];
size_t message_length;
bool status;
_accelMessage message = accelMessage_init_zero;
/* Create a stream that will write to our buffer. */
pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
message.values = accelString;

status = pb_encode(&stream, accelMessage_fields, &message);
message_length = stream.bytes_written;

/* Then just check for any errors.. */
if (!status)
    printf("Encoding failed: %s\n", PB_GET_ERROR(&stream));
    return 1;

The error is raised on the line

message.values = accelString;

UPDATE: According to nanopb docs i should have something like

typedef struct {
   int32_t value;
} Example; 

instead i get

typedef struct _accelMessage {
    pb_callback_t values;
/* @@protoc_insertion_point(struct:accelMessage) */
} accelMessage;

in my accel.pb.h file generated by protoc

  • The message.values obviously expects some pb_callback_t callback (union over encode/decode function pointer) and not some empty String. – KIIV Nov 30 at 10:27
  • @KIIV The string in question is not empty it has accelerometer values in it. Can you please give me some pointers as to how to encode this string properly? – m.umar Nov 30 at 11:20
  • Hint: Avoid using the Arduino String class, and instead use a c-string. – Mikael Patel Nov 30 at 12:06

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.