encode messages to send to device