Replies: 1 comment 1 reply
-
Check out the PlummersSoftwareLLC/NightDriverUnity project, which was written in C#. You don’t need the whoie thing, but check out the Assets/Scripts/LEDControllerChannel.cs file. About line 416 you’ll see a call to SendData.
The message to send is composed just out of byte arrays by LEDInterop.CombineByteArrays.
Here’s the code that gets the bytes you need from an array of CRGB objects, one per LED.
So, the actual data to send is a packet with:
Word: WIFI_COMMAND_PIXELDATA64
Word: Channel Number (or 0)
DWORD: Number of LEDs
ULONG: seconds
ULONG microseconds
[then the raw 3-byte triplets, one per LED, that is your color data]
I think you can get the seconds/micros to 0/0 and it’ll still work, you just won’t get buffering, Better if you do like it does, where it gets the current time and adds one second to it for buffering.
Hope this helps a little, let me know!
- Dave
protected override byte[] GetDataFrame(CRGB [] MainLEDs, DateTime timeStart)
{
// The old original code truncated 64 bit values down to 32, and we need to fix that, so it's a in a packet called PIXELDATA64
// and is only sent to newer flashes taht support it. Otherwise we send the old original foramt.
// The timeOffset is how far in the future frames are generated for. If the chips have a 2 second buffer, you could
// go up to 2 seconds, but I shoot for the middle of the buffer depth. Right now it's calculated as using
double epoch = (timeStart.Ticks - 621355968000000000 + (1.0 * TimeSpan.TicksPerSecond)) / (double)TimeSpan.TicksPerSecond;
double fraction = epoch - (Int64)epoch;
ulong seconds = (ulong)epoch; // Whole part of time number (left of the decimal point)
ulong uSeconds = (ulong)(fraction * 1000000); // Fractional part of time (right of the decimal point)
// Debug.Log("New Seconds: " + seconds + "uSec: " + uSeconds);
var data = GetPixelData(MainLEDs);
return LEDInterop.CombineByteArrays(LEDInterop.WORDToBytes(WIFI_COMMAND_PIXELDATA64), // Offset, always zero for us
LEDInterop.WORDToBytes((UInt16)Channel), // LED channel on ESP32
LEDInterop.DWORDToBytes((UInt32)data.Length / 3), // Number of LEDs
LEDInterop.ULONGToBytes(seconds), // Timestamp seconds (64 bit)
LEDInterop.ULONGToBytes(uSeconds), // Timestmap microseconds (64 bit)
data); // Color Data
…
On Jan 27, 2023, at 4:06 PM, mahirick ***@***.***> wrote:
Hello,
I've spent way to long trying to get this to work so thought I'd reach out here. Does anyone know how to form a packet to send to NightDriver in C#? I've got an M5 connected to WIFI and have enabled INCOMING_WIFI_ENABLED. It accepts packets on port 49152 and responds but something is wrong with my encoding or something because it's not recieving the right packet (viewed via Debug statements in socketserver.h).
Any ideas or advice?
Thanks,
-Rick
C# code that sends the packet but the server doesn't understand:
` Socket socket1 = new Socket(ipAddr.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
// Connect Socket to the remote endpoint using method Connect()
socket1.Connect(m5StickCPlus);
// We print EndPoint information that we are connected
Debug.WriteLine($"Socket connected to -> {socket1.RemoteEndPoint.ToString()}");
// Creation of message that we will send to Server
string sPacket = "030100010000000000000000255255255"; //String of the a 1 pixel packet
byte[] data1 = Encoding.Unicode.GetBytes(sPacket);
int byteSent = socket1.Send(data1);`
—
Reply to this email directly, view it on GitHub <#205>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AA4HCFYDM75RHOSXKD7SBITWURPIBANCNFSM6AAAAAAUJJYND4>.
You are receiving this because you are subscribed to this thread.
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
mahirick
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I've spent way to long trying to get this to work so thought I'd reach out here. Does anyone know how to form a packet to send to NightDriver in C#? I've got an M5 connected to WIFI and have enabled INCOMING_WIFI_ENABLED. It accepts packets on port 49152 and responds but something is wrong with my encoding or something because it's not recieving the right packet (viewed via Debug statements in socketserver.h).
Any ideas or advice?
Thanks,
-Rick
C# code that sends the packet but the server doesn't understand:
` Socket socket1 = new Socket(ipAddr.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
Beta Was this translation helpful? Give feedback.
All reactions