PTZ Control on ONVIF Standard in C#

Looking at highly price Camera SDK to handle ONVIF Standard, I decided to build some code to control PTZ camera movement using C#.

It it a nice tutorial video by Onvif Channel. That video describes basic step to make a C# project on visual studio. Unfortunately, I can’t get it work for my camera. I’m having YooSee camera GW-1113 which is already support PTZ Control.

There is another tutorial in CodeProject to use PTZ Control. My code is always get a closed connection message from the camera. Both using password or nor, it alway failed. Next, I got nice tool to cek my Onvif Camera. It can detect camera’s IP, port, display video stream and controlling camera using PTZ. You can get it here https://sourceforge.net/projects/onvifdm/ Afterward, I got IP, Port, and service.

With correct IP, Password, port and service address, it still error on getProfiles() command. I inisiate to find tool to debug Onvif request. I grab this tool in this forum https://support.yooseecamera.com/threads/233/ Nice step by step tutorial with pictures. I made my dummy service and dump post header request and then save it into textfile. Here is PHP code i got from // https://gist.github.com/magnetikonline/650e30e485c0f91f2f40 to dump request. I save it on http://localhost:5000/onvif/device_service/index.php

<?php

class DumpHTTPRequestToFile {

	public function execute($targetFile) {

		$data = sprintf(
			"%s %s %s\n\nHTTP headers:\n",
			$_SERVER['REQUEST_METHOD'],
			$_SERVER['REQUEST_URI'],
			$_SERVER['SERVER_PROTOCOL']
		);

		foreach ($this->getHeaderList() as $name => $value) {
			$data .= $name . ': ' . $value . "\n";
		}

		$data .= "\nRequest body:\n";

		file_put_contents(
			$targetFile,
			$data . file_get_contents('php://input') . "\n"
		);

		echo("Done!\n\n");
	}

	private function getHeaderList() {

		$headerList = [];
		foreach ($_SERVER as $name => $value) {
			if (preg_match('/^HTTP_/',$name)) {
				// convert HTTP_HEADER_NAME to Header-Name
				$name = strtr(substr($name,5),'_',' ');
				$name = ucwords(strtolower($name));
				$name = strtr($name,' ','-');

				// add to list
				$headerList[$name] = $value;
			}
		}

		return $headerList;
	}
}


(new DumpHTTPRequestToFile)->execute('./dumprequest.txt');
exit();

And here are resutl I got from C# and Device Test Tool

POST /onvif/device_service/index.php HTTP/1.1

HTTP headers:
Host: localhost
Expect: 100-continue
Accept-Encoding: gzip, deflate
Connection: Keep-Alive

Request body:
<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetCapabilities xmlns="http://www.onvif.org/ver10/device/wsdl" /></s:Body></s:Envelope>


POST /onvif/device_service/index.php HTTP/1.1

HTTP headers:
Host: localhost
Accept: */*

Request body:
<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetCapabilities xmlns="http://www.onvif.org/ver10/device/wsdl" /></s:Body></s:Envelope>


Above was C# request, while next into it was Tool request You can see that the difference is only at HTTP headers section. Thus, I have to remove Expect:100-continue , gzip compression and Keep-Alive Connection (oprional). As well as add an Accept type.

            try
            {
                var messageElement = new TextMessageEncodingBindingElement()
                {
                    MessageVersion = MessageVersion.CreateVersion(
                      EnvelopeVersion.Soap12, AddressingVersion.None)
                };

                HttpTransportBindingElement httpBinding = new HttpTransportBindingElement()
                {
                    AuthenticationScheme = AuthenticationSchemes.Digest

                };
                //remove compression
                httpBinding.DecompressionEnabled = false;
                // remove keep alive
                httpBinding.KeepAliveEnabled = false;


                CustomBinding bind = new CustomBinding(messageElement, httpBinding);
                // Remove Expect
                ServicePoint servicePoint =
                    ServicePointManager.FindServicePoint(service_uri);
                servicePoint.Expect100Continue = false;

                if (searchServiceUri)
                {
                    // now execute some service operation 
                    Device.DeviceClient device = new Device.DeviceClient(bind,
                      new EndpointAddress(service_uri));
                    device.ClientCredentials.HttpDigest.AllowedImpersonationLevel =
                      System.Security.Principal.TokenImpersonationLevel.Impersonation;
                    device.ClientCredentials.HttpDigest.ClientCredential.UserName = userName;
                    device.ClientCredentials.HttpDigest.ClientCredential.Password = password;

                    Device.Capabilities cap = device.GetCapabilities(null);

                }

Later I got nice php script to controlling PTZ at https://github.com/sergejey/majordomo-onvif/blob/master/modules/onvif/class.ponvif.php

Penerima Waktu Tunda WiFi

#ifdef ESP32
#include <esp_now.h>
#include <WiFi.h>
#else
#include <espnow.h>
#include <ESP8266WiFi.h>
#define ESP_OK 0
#endif

#define lampPin 0

bool lampON = false;
bool lock = false;


// struktur untuk pengiriman data harus sama dengan struktur pada penerima
typedef struct struct_message {
  int id;     //id pengirim, lock counter
  int x;      //on interval counter
  int y;      //motion (>0)
} struct_message;

struct_message myData;

// Membuat struktur untuk tiap board
struct_message board1;

struct_message boardsStruct[3] = {board1};

volatile int counter = 0;
int max_counter = 0;
int lock_counter = 1;

// callback saat data diterima
#ifdef ESP32
void OnDataRecv(const uint8_t * mac_addr, const uint8_t *incomingData, int len)
#else
void OnDataRecv(uint8_t * mac_addr, uint8_t *incomingData, uint8_t len)
#endif
{
  char macStr[18];
  Serial.print("Paket diterima dari: ");
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
           mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
  Serial.println(macStr);
  memcpy(&amp;myData, incomingData, sizeof(myData));
  Serial.printf("Board ID %u: %u bytes\n", myData.id, len);
  // Update the structures with the new incoming data
  boardsStruct[myData.id - 1].x = myData.x;
  boardsStruct[myData.id - 1].y = myData.y;
  Serial.printf("x value: %d \n", boardsStruct[myData.id - 1].x);
  Serial.printf("y value: %d \n", boardsStruct[myData.id - 1].y);
  Serial.println();

  if (!lock) counter = 0;

}


void setup() {
  Serial.begin(74880);
  Serial.println();
  Serial.print("ESP Board MAC Address:  ");
  Serial.println(WiFi.macAddress());

  WiFi.mode(WIFI_STA);

  //Init ESP-NOW
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }

  //daftrakan callback
  esp_now_register_recv_cb(OnDataRecv);

  pinMode(lampPin, OUTPUT);
  Serial.println("Turn Off lamp");
  digitalWrite(lampPin, LOW);
  lampON = false;
}


void loop() {
  // Mengakses data dari setiap board
  //Serial.println(boardsStruct[0].x,DEC);
  //delay(1000);

  //update counter
  if (boardsStruct[0].x > 0)
    max_counter = boardsStruct[0].x;

  if (boardsStruct[0].id > 0)
    lock_counter = boardsStruct[0].id;

  //get motion information and restart counter?
  if (boardsStruct[0].y > 0 &amp;&amp; counter == 0) {
    if (!lampON) {
      Serial.println("Turn On lamp");
        digitalWrite(lampPin, HIGH);

      lampON = true;
    }
  }


  //stop counter turn off lamp
  if (counter >= max_counter &amp;&amp; lampON) {
    Serial.println("Turn Off lamp");
  digitalWrite(lampPin, LOW);
    lampON = false;
    lock = true;
    Serial.println("Lock");
    delay(lock_counter * 1000);
    Serial.println("Release");
    lock = false;
  }

  if (lampON) {
    counter++;
    Serial.print(max_counter - counter);
    delay(1000);
  }

}

Memulai Percobaan ESP-CAM

ESP-CAM memiliki LED pada pin GPIO33. LED ini akan kita gunakan untuk percobaan mati nyala kedip kedip.

Kode Blink pada Arduino

#define LED_BUILTIN 33    //LED ada di GPIO33

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   
  delay(1000);                       
  digitalWrite(LED_BUILTIN, LOW);    
  delay(1000);                       
}

Konfigurasi pilihan Board

Hubungkan USB-Serial atau dapat pula menggunakan Arduino (TX-TX, RX-RX)

Hubungkan GND dengan GPIO0 dan tekan reset.

Jika sudah berhasil Upload, lepas hubungan GND dengan GPIO0 (Kabel abu-abu) dan tekan reset.

Pengiriman Peer-to-Peer MCU ESP

Pengiriman dilakukan oleh LOLIN32 dengan MCU ESP32 sedangkan penerimaan dilakukan oleh ESP01 dengan MCU ESP8266. Potokol pengiriman menggunakan ESP-NOW. ESP-NOW adalah salah satu protokol hibungan WiFi yang dibesut oleh Espressif.

Skrip Pengiriman yang dibenamkan di LOLIN32

#ifdef ESP32
  #include <esp_now.h>
  #include <WiFi.h>
#else
  #include <espnow.h>
  #include <ESP8266WiFi.h>
#endif

 
// Ganti dengan MAC penerima
uint8_t broadcastAddress[] = {0xBC, 0xDD, 0xC2, 0x6B, 0x54, 0xC2};
 
// ID harus unik
const int id = 1;
 
// struktur untuk pengiriman data harus sama dengan struktur pada penerima
typedef struct struct_message {
    int id; 
    int x;
    int y;
} struct_message;
 
struct_message myData;
 
// callback saat data dikirim
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
  Serial.print("Status pengiriman:\t");
  Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Sukses" : "Gagal");
}
  
void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
 
  // Init ESP-NOW
  if (esp_now_init() != ESP_OK) {
    Serial.println("Gagal inisialisasi ESP-NOW");
    return;
  }
 
  // registrasi ke penerima dan cek status paket
  esp_now_register_send_cb(OnDataSent);
   
  // Registrasi peer
  esp_now_peer_info_t peerInfo;
  memcpy(peerInfo.peer_addr, broadcastAddress, 6);
  peerInfo.channel = 0;  
  peerInfo.encrypt = false;
   
  // Menambahkan diri peer        
  if (esp_now_add_peer(&amp;peerInfo) != ESP_OK){
    Serial.println("Gagal menambahkan diri ke peer");
    return;
  }
}
  
void loop() {
  // Nilai untuk dikirim
  myData.id = 1;
  myData.x = random(0,50);
  myData.y = random(0,50);

  Serial.print("x:");Serial.println(myData.x,DEC);
  Serial.print("y:");Serial.println(myData.y,DEC);
  // Kirim pesan
  esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &amp;myData, sizeof(myData));
    
  if (result == ESP_OK) {
    Serial.println("Permintaan pengiriman berhasil");
  }
  else {
    Serial.println("Gagal mengirim data");
  }
  delay(10000);
}

Skrip penerima yang dibenamkan di ESP01

#ifdef ESP32
  #include <esp_now.h>
  #include <WiFi.h>
#else
  #include <espnow.h>
  #include <ESP8266WiFi.h>
  #define ESP_OK 0
#endif

 // struktur untuk pengiriman data harus sama dengan struktur pada penerima
typedef struct struct_message {
  int id;
  int x;
  int y;
}struct_message;
 
struct_message myData;
 
// Membuat struktur untuk tiap board
struct_message board1;
 
struct_message boardsStruct[3] = {board1};
 
// callback saat data diterima
#ifdef ESP32
void OnDataRecv(const uint8_t * mac_addr, const uint8_t *incomingData, int len) 
#else
void OnDataRecv(uint8_t * mac_addr, uint8_t *incomingData, uint8_t len) 
#endif
{
  char macStr[18];
  Serial.print("Paket diterima dari: ");
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
           mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
  Serial.println(macStr);
  memcpy(&amp;myData, incomingData, sizeof(myData));
  Serial.printf("Board ID %u: %u bytes\n", myData.id, len);
  // Update the structures with the new incoming data
  boardsStruct[myData.id-1].x = myData.x;
  boardsStruct[myData.id-1].y = myData.y;
  Serial.printf("x value: %d \n", boardsStruct[myData.id-1].x);
  Serial.printf("y value: %d \n", boardsStruct[myData.id-1].y);
  Serial.println();
}

void setup(){
  Serial.begin(74880);
  Serial.println();
  Serial.print("ESP Board MAC Address:  ");
  Serial.println(WiFi.macAddress());

   WiFi.mode(WIFI_STA);
 
  //Init ESP-NOW
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }
   
  //daftrakan callback
  esp_now_register_recv_cb(OnDataRecv);
}
  
void loop() {
  // Mengakses data dari setiap board
  //Serial.println(boardsStruct[0].x,DEC); 
  delay(1000);  
}

Hasil proses pengiriman lewat seriam monitor

Konfigurasi Perangkat Keras

Cara memprogram ESP01

Wiring dengan Modul Serial

Hubungkan IO0 dengan GND

Wiring dengan USB-TTL (Gunakan yang support 3,3 Volt) atau dapat juga menggunakan Board Arduino

Hubungkan IO0 dengan GND ESP ke pin GND USBTTL. Hubungkan EN dengan 3V3 ESP ke 3V3 USBTTL. TX ESP ke RX USBTTL dan RX ESP ke TX USBTTL.
(Jika mengunakan board Arduino, hubungkan RX ke RX dan TX ke TX)

Pilihan Setting Board

Board: “Generic ESP Module”
Flash Mode: “DIO” (Gunakan DOUT jika checksum error)
Flash Frequency: “40MHz”
CPU Frequency: “80 MHz”
Flash Size: “1M (64K SPIFFS)”
Debug Port: “Disabled”
Debug Level: “None”
Reset Method: “ck”
Upload Speed: “115200”

Contoh kode untuk blink (LED pada GPIO0)

/* 
 *  ESP01
 *  Upload Configuration:
 *  Generic 8266
 *  Flash Mode: DOUT (Using: DIO --> checksum Error)
 *  Debug: None
 *  Reset: ck
 *  CPU: 80Mhz
 *  Flash: 1M (64K)
 *  Debug Port: Disable
 *  Flash: 40Mhz
 *  Upload Speed: 115200
 *  
 *  Flashing ESP-01 using Esp8266 Serial Module Board
 *  Connect GPIO0 to GND
 *  
 *  Flash ESP-01 using USB to TTL 
 *  Connect GPIO0 to GND, EN to 3V3, RX-TX, TX-RX
 */

#define D3  0 //GPIO0
#define D4  2 //GPIO2
void setup() {
  //GPIO0
  pinMode(D3, OUTPUT);
  Serial.begin(74880);
}
void loop() {
  digitalWrite(D3, LOW); // turn the LED on (HIGH is the voltage level)
  delay(1000); // wait for a second
  digitalWrite(D3, HIGH); // turn the LED off by making the voltage LOW Serial.println("LOW");
  delay(1000); // wait for a second
  Serial.println("OK");
}

Untuk menjalankan hasil programming, lepas kabel IO0 terhadap GND dan lalukan reset (atau cabut pasang modul)

sumber: https://www.diyhobi.com/flash-program-esp-01-using-usb-serial-adapter/

Mengirim Date ke Banyak Board dengan ESP_NOW

Mencari alamat MAC penerima

#ifdef ESP32
  #include <WiFi.h>
#else
  #include <ESP8266WiFi.h>
#endif

void setup(){
  Serial.begin(115200);
  Serial.println();
  Serial.print("ESP Board MAC Address:  ");
  Serial.println(WiFi.macAddress());
}
 
void loop(){

}

Pengirim Data

#include <esp_now.h>
#include <WiFi.h>

// Ganti dengan MAC address penerima
uint8_t broadcastAddress1[] = {0x3C, 0x71, 0xBF, 0xC3, 0xBF, 0xB0};
uint8_t broadcastAddress2[] = {0x24, 0x0A, 0xC4, 0xAE, 0xAE, 0x44};
uint8_t broadcastAddress3[] = {0x80, 0x7D, 0x3A, 0x58, 0xB4, 0xB0};

typedef struct test_struct {
  int x;
  int y;
} test_struct;

test_struct test1;
test_struct test2;
test_struct test3;

// callback saat pengiriman data
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
  char macStr[18];
  Serial.print("Ditujukan : ");
  // Copies the sender mac address to a string
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
           mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
  Serial.print(macStr);
  Serial.print(" status:\t");
  Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Sukses" : "Gagal");
}
 
void setup() {
  Serial.begin(115200);
 
  WiFi.mode(WIFI_STA);
 
  if (esp_now_init() != ESP_OK) {
    Serial.println("Gagal inisialisasi ESP-NOW");
    return;
  }
  
  esp_now_register_send_cb(OnDataSent);
   
  // pendaftaran peer
  esp_now_peer_info_t peerInfo;
  peerInfo.channel = 0;  
  peerInfo.encrypt = false;
  
  // peer  pertama
  memcpy(peerInfo.peer_addr, broadcastAddress1, 6);
  if (esp_now_add_peer(&amp;peerInfo) != ESP_OK){
    Serial.println("Gagal menambahkan peer");
    return;
  }
  //  peer kedua 
  memcpy(peerInfo.peer_addr, broadcastAddress2, 6);
  if (esp_now_add_peer(&amp;peerInfo) != ESP_OK){
    Serial.println("Gagal menambahkan peer");
    return;
  }
  /// peer ketiga
  memcpy(peerInfo.peer_addr, broadcastAddress3, 6);
  if (esp_now_add_peer(&amp;peerInfo) != ESP_OK){
    Serial.println("Gagal menambahkan peer");
    return;
  }
}
 
void loop() {
  //masukkan data padda struktur
  test1.x = random(0,20);
  test1.y = random(0,20);
  test2.x = random(0,20);
  test2.y = random(0,20);
  test3.x = random(0,20);
  test3.y = random(0,20);
 
  //kirim paket data test1 ke semua board
  esp_err_t result = esp_now_send(0, (uint8_t *) &amp;test1, sizeof(test_struct));

  if (result == ESP_OK) {
    Serial.println("Terkirim ke semua board");
  }
  else {
    Serial.println("Gagal mengirim");
  }

  //kirim paket data test1,test2, test3 ke maing-masing board
  result = esp_now_send(broadcastAddress1, (uint8_t *) &amp;test1, sizeof(test_struct));
  if (result == ESP_OK) {
    Serial.println("Terkirim ke board 1");
  }
  else {
    Serial.println("Gagal mengirim board 1");
  }

  result = esp_now_send(broadcastAddress2, (uint8_t *) &amp;test2, sizeof(test_struct));
  if (result == ESP_OK) {
    Serial.println("Terkirim ke board 2");
  }
  else {
    Serial.println("Gagal mengirim board 2");
  }

  result = esp_now_send(broadcastAddress3, (uint8_t *) &amp;test3, sizeof(test_struct));
   
  if (result == ESP_OK) {
    Serial.println("Terkirim ke board 3");
  }
  else {
    Serial.println("Gagal mengirim board 3");
  }
  
  delay(2000);
}

Penerima Data

#include <esp_now.h>
#include <WiFi.h>

typedef struct test_struct {
  int x;
  int y;
} test_struct;

test_struct myData;

void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
  memcpy(&amp;myData, incomingData, sizeof(myData));
  Serial.print("Bytes diterima: ");
  Serial.println(len);
  Serial.print("x: ");
  Serial.println(myData.x);
  Serial.print("y: ");
  Serial.println(myData.y);
  Serial.println();
}
 
void setup() {
  Serial.begin(115200);
  
  WiFi.mode(WIFI_STA);

  //Init ESP-NOW
  if (esp_now_init() != ESP_OK) {
    Serial.println("Gagal inisialisasi ESP-NOW");
    return;
  }
  //daftarkan callback
  esp_now_register_recv_cb(OnDataRecv);
}
 
void loop() {

}

sumber: https://randomnerdtutorials.com/esp-now-one-to-many-esp32-esp8266/

Menerima Data dari Banyak Board dengan ESP_NOW

Mendapatkan informasi MAC Address ESP Penerima

//Mendapatkan MAC Address penerima
#ifdef ESP32
  #include <WiFi.h>
#else
  #include <ESP8266WiFi.h>
#endif

void setup(){
  Serial.begin(115200);
  Serial.println();
  Serial.print("ESP Board MAC Address:  ");
  Serial.println(WiFi.macAddress());
}
 
void loop(){

}

ESP Pengirim Data

#include <esp_now.h>
#include <WiFi.h>

// Ganti dengan MAC penerima
uint8_t broadcastAddress[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};

// ID harus unik
const int id = 1;

// struktur untuk pengiriman data harus sama dengan struktur pada penerima
typedef struct struct_message {
    int id; 
    int x;
    int y;
} struct_message;

struct_message myData;

// callback saat data dikirim
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
  Serial.print("\r\nStatus pengiriman sebelumnya:\t");
  Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Sukses" : "Gagal");
}
 
void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);

  // Init ESP-NOW
  if (esp_now_init() != ESP_OK) {
    Serial.println("Gagal inisialisasi ESP-NOW");
    return;
  }

  // registrasi ke penerima dan cek status paket
  esp_now_register_send_cb(OnDataSent);
  
  // Registrasi peer
  esp_now_peer_info_t peerInfo;
  memcpy(peerInfo.peer_addr, broadcastAddress, 6);
  peerInfo.channel = 0;  
  peerInfo.encrypt = false;
  
  // Menambahkan diri peer        
  if (esp_now_add_peer(&amp;peerInfo) != ESP_OK){
    Serial.println("Gagal menambahkan diri ke peer");
    return;
  }
}
 
void loop() {
  // Nilai untuk dikirim
  myData.id = 1;
  myData.x = random(0,50);
  myData.y = random(0,50);

  // Kirim pesan
  esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &amp;myData, sizeof(myData));
   
  if (result == ESP_OK) {
    Serial.println("Terkirim dengan sukses");
  }
  else {
    Serial.println("Gagal mengirim data");
  }
  delay(10000);
}

ESP Penerima data

#include <esp_now.h>
#include <WiFi.h>

// struktur untuk pengiriman data harus sama dengan struktur pada penerima
typedef struct struct_message {
  int id;
  int x;
  int y;
}struct_message;

struct_message myData;

// Membuat struktur untuk tiap board
struct_message board1;
struct_message board2;
struct_message board3;

struct_message boardsStruct[3] = {board1, board2, board3};

// callback saat data diterima
void OnDataRecv(const uint8_t * mac_addr, const uint8_t *incomingData, int len) {
  char macStr[18];
  Serial.print("Paket diterima dari: ");
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
           mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
  Serial.println(macStr);
  memcpy(&amp;myData, incomingData, sizeof(myData));
  Serial.printf("Board ID %u: %u bytes\n", myData.id, len);
  // Update the structures with the new incoming data
  boardsStruct[myData.id-1].x = myData.x;
  boardsStruct[myData.id-1].y = myData.y;
  Serial.printf("x value: %d \n", boardsStruct[myData.id-1].x);
  Serial.printf("y value: %d \n", boardsStruct[myData.id-1].y);
  Serial.println();
}
 
void setup() {
  Serial.begin(115200);
  
  WiFi.mode(WIFI_STA);

  //Init ESP-NOW
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }
  
  //daftrakan callback
  esp_now_register_recv_cb(OnDataRecv);
}
 
void loop() {
  // Mengakses data dari setiap board
  /*
  int board1X = boardsStruct[0].x;
  int board1Y = boardsStruct[0].y;
  int board2X = boardsStruct[1].x;
  int board2Y = boardsStruct[1].y;
  int board3X = boardsStruct[2].x;
  int board3Y = boardsStruct[2].y;
  */

  delay(1000);  
}

Sumber: https://randomnerdtutorials.com/esp-now-many-to-one-esp32/

Percobaan cloud4pi dengan PHP

<!--?php
// A sample PHP Script to POST data using cURL
// Data in JSON format

$json= '&#91;{"name":"Temperature","type":"numeric"},{"name":"LEDOn","type":"bool"}&#93;';
$arr=json_decode($json, false);

echo '

<pre-->';
print_r($arr);
echo '


';

$employee_object = new stdClass;
$employee_object-&gt;name = "Temperature";
$employee_object-&gt;type = "numeric";
$employee_object1 = new stdClass;
$employee_object1-&gt;name = "LEDOn";
$employee_object1-&gt;type = "bool"; 

$data = array
  (
  $employee_object,
  $employee_object1
);

$payload = json_encode($data);
echo "==&gt;".$payload;

$token = '2HSmdfzsEAXB3puVUTi6ZoirV';

// Prepare new cURL resource
$ch = curl_init('https://cloud4rpi.io/api/devices/'.$token.'/config');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);

// Set HTTP Header for POST request
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($payload))
);

// Submit the POST request
$result = curl_exec($ch);

echo $result;
// Close cURL session handle
curl_close($ch);

$json = '{"ts":"date","payload":{"Temperature":24,"LEDOn":true}}';
$arr=json_decode($json, true);

echo '









<pre>';
print_r($arr);
echo '</pre>
';

$dt = date(DateTime::ISO8601);

$carss = array
(
"ts"=&gt;$dt,
"payload"=&gt;array("Temperature"=&gt;22,"LEDOn"=&gt;0)
);

$payload = json_encode($carss);
echo "==&gt;".$payload;

$token = '2HSmdfzsEAXB3puVUTi6ZoirV';

// Prepare new cURL resource
$ch = curl_init('https://cloud4rpi.io/api/devices/'.$token.'/data');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);

// Set HTTP Header for POST request
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($payload))
);

// Submit the POST request
$result = curl_exec($ch);

echo $result;
// Close cURL session handle
curl_close($ch);

?&gt;

Setting printer USB di Raspberry Pi

sudo chown www-data:www-data etc
sudo chmod 775 etc
sudo chown www-data:www-data /dev/usb/lp0

source:
https://www.howtogeek.com/169679/how-to-add-a-printer-to-your-raspberry-pi-or-other-linux-computer/
https://kernelmastery.com/enable-regular-users-to-add-printers-to-cups/
https://maker.pro/raspberry-pi/projects/how-to-turn-a-usb-printer-into-a-wireless-printer-with-raspberry-pi-zero-w