is-centre / udp-ue4-plugin-win64

A simple UDP communication plugin based on freely available code
MIT License
50 stars 20 forks source link

Sending Mavlink Data with msg_act_bytes = str(controls).encode('utf-8') #24

Open MyatToe opened 5 days ago

MyatToe commented 5 days ago

@extall Recently I tried to send with the Socket which is Data from Mavlink. def send_data(data, ip='127.0.0.1', port=12345):

Create a UDP socket

    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

    try:
        # Send data
        sock.sendto(data, (ip, port))
    finally:
        # Close the socket
        sock.close()
msg_act_bytes = str(controls).encode('utf-8')
send_data(msg_act_bytes)
print('msg_act_bytes:', msg_act_bytes)

And it is printing Well inside the program as msg_act_bytes: b'[-1.2000000476837158, -1.2000000476837158, -1.2000000476837158, -0.10000000149011612, -1.2000000476837158, -1.2000000476837158, -1.2000000476837158, -1.2000000476837158, -1.2000000476837158, -1.2000000476837158, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]'


By Following the Tutorial, I change data from

pragma once

include "Serialization/Archive.h"

include "UDPData.generated.h"

USTRUCT(BlueprintType) struct FUDPData { GENERATED_USTRUCT_BODY() UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication") float float1 = 0.0f; UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication") float float2 = 0.0f; UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication") float float3 = 0.0f; UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication") float float4 = 0.0f; UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication") float float5 = 0.0f; UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication") float float6 = 0.0f; UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication") float float7 = 0.0f; UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication") float float8 = 0.0f; UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication") float float9 = 0.0f; UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication") float float10 = 0.0f; UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication") float float11 = 0.0f; UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication") float float12 = 0.0f; UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication") float float13 = 0.0f; UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication") float float14 = 0.0f; UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication") float float15 = 0.0f; UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication") float float16 = 0.0f; UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication") float float17 = 0.0f; UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication") float float18 = 0.0f; UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication") float float19 = 0.0f; UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication") float float20 = 0.0f; UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication") uint8 uint1 = 0; UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication") uint8 uint2 = 0; UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication") uint8 uint3 = 0; UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication") TArray controls; FUDPData() { controls.Init(0.0f, 20); } };

FORCEINLINE FArchive& operator<<(FArchive &Ar, FUDPData &Structure) { Ar << Structure.float1; Ar << Structure.float2; Ar << Structure.float3; Ar << Structure.float4; Ar << Structure.float5; Ar << Structure.float6; Ar << Structure.float7; Ar << Structure.float8; Ar << Structure.float9; Ar << Structure.float10; Ar << Structure.float11; Ar << Structure.float12; Ar << Structure.float13; Ar << Structure.float14; Ar << Structure.float15; Ar << Structure.float16; Ar << Structure.float17; Ar << Structure.float18; Ar << Structure.float19; Ar << Structure.float20; Ar << Structure.uint1; Ar << Structure.uint2; Ar << Structure.uint3; Ar << Structure.controls; return Ar; }

And I tried to build UDP connection error

I would like to recieve the data msg_act_bytes: b'[-1.2000000476837158, -1.2000000476837158, -1.2000000476837158, -0.10000000149011612, -1.2000000476837158, -1.2000000476837158, -1.2000000476837158, -1.2000000476837158, -1.2000000476837158, -1.2000000476837158, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]' and print it. I will be glad it you can help me with your plugin for this issue.

MyatToe commented 5 days ago

@extall can you help me this issue? I search almost all documentation including https://nerivec.github.io/old-ue4-wiki/pages/udp-socket-sender-receiver-from-one-ue4-instance-to-another.html#Post_4.12

I am new for unreal engine as well as plugin. Could you help me for this issue? Thanks~