Sending MAVLink commands from ESP8266 LoLin v3 to APM 2.6

Hello everyone! I’m newbie in copters and mavlink protocol.
I have two boards: lolin v3 and apm 2.6
And I would like to send mavlink commands from lolin to apm.
A read many articles about mavlink connection, tried many different source codes but I cannot make the easiest action - arming/disarming. This is my code which doesn’t work.

void mav_arm_pack() {
mavlink_message_t msg;
uint8_t buf[MAVLINK_MAX_PACKET_LEN];
mavlink_msg_command_long_pack(0xFF, 0xBE, &msg, 1, 1, 400, 1,1.0,0,0,0,0,0,0);
uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);
Serial.write(buf, len);
}    

Please, can someone explain how to connect lolin with apm via mavlink or may be provide me an easy example of this connection?

I’d start by reading here: http://ardupilot.org/copter/docs/common-esp8266-telemetry.html