jaybdub / enes499

Files, programs, and project management for UMD's enes499 course.
0 stars 0 forks source link

Encode the simple example message #9

Closed jaybdub closed 10 years ago

jaybdub commented 10 years ago

Completed.

#include <pb.h>
#include <pb_decode.h>
#include <pb_encode.h>

#include <message.pb.h>

Simple msg;
uint8_t buffer[64];
pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));

void setup(){
  Serial.begin(9600);
  //Set the name field of the Simple struct to "Example Message", and 
  //set the has_name field to true.
  strncpy(msg.name,"Hello",sizeof(msg.name));
  msg.has_name = true;
  //Serialize the Simple message and pack it into the buffer.
  pb_encode(&stream, Simple_fields, &msg);
}

void loop(){
  int bytes_sent = Serial.write(buffer, stream.bytes_written);
  delay(3000);
}