Has anyone programmed ELEGOO UNO?

I bought the Smart Robot Car v4 with camera from ELEGOO. I started to vary the sketch of the camera card to allow the use of the ESP32 WROVER as a WiFi STA, i.e. not as a WiFi hot spot, but as a PC on the home network. Now I would like to write a C++ program using the ASIO library for TCP/IP communication with the robot (through the camera/ESP32 WROVER card), so that I can control it from a PC via WiFi. I noticed that the robot communicates via WiFi using commands in Json format. Can you help me write the message sending part in the Jason format? Here is the list of commands you should send:
{"H": "1", "N": 3, "D1": 3, "D2": 150} -> move forward
{"H": "2", "N": 3, "D1": 4, "D2": 150} -> move backward
{"H": "3", "N": 3, "D1": 1, "D2": 150} -> move left
{"H": "4", "N": 3, "D1": 2, "D2": 150} -> move right
{"H": "5", "N": 1, "D1": 0, "D2": 0, "D3":1} -> stop
{"H": "6", "N": 5, "D1": 1, "D2": 90} -> rotate 90 degree
{"H": "7", "N": 21, "D1": 2} -> measure distance
{"H": "8", "N": 23} -> check
Below I put the code I wrote, but that can't make the robot understand it (the json message string sent):

#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"

#define ASIO_STANDALONE
#define _WINSOCK_DEPRECATED_NO_WARNINGS

#include <asio.hpp>
#include <asio/ts/buffer.hpp>
#include <asio/ts/internet.hpp>
#include <json.hpp>

#include <fstream>
#include <iostream>

int main()
{
	// crea un contesto, ossia un'interfaccia specifica della piattaforma ASIO
	asio::io_context context;

	// variabile codice di errore di ASIO
	asio::error_code ec;

	// leggi l'indirizzo del server su cui vogliamo collegarci (mio robot alla porta 1500)
	asio::ip::tcp::endpoint endpoint(asio::ip::make_address("192.168.1.64", ec), 1500);

	// crea un socket, il contesto fornira' l'implementazione
	asio::ip::tcp::socket socket(context);

	// diciamo al socket di provare a connettersi
	socket.connect(endpoint, ec);

	// esito della connessione
	if (!ec)
	{
		std::cout << "Connesso al Robot!" << std::endl;
	}
	else
	{
		std::cout << "Connessione al Robot fallita all'indirizzo:\n" << ec.message() << std::endl;
	}

	if (socket.is_open())
	{
		// create object from string literal
		nlohmann::json j = "{ \"H\": \"1\", \"N\": 3, \"D1\": 3, \"D2\": 150}"_json;

		std::cout << "Messaggio inviato al server: " << j.dump() << std::endl;
		if (socket.write_some(asio::buffer(j.dump(), j.dump().size()), ec) == 0)
		{
			std::cout << "Errore invio messaggio!\n";
			return 1;
		}
	}

	socket.close();

	return 0;
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.