1

I'm working on sending files instead of strings to another client via MQTTnet by using C#.
I want to send the files that contain delimited data.
Here is an example of the file:

Time Stamp  Time Zone   Fuel Category           Gen MW
05/09/2018  00:05:00    EDT  Dual Fuel          1400
05/09/2018  00:05:00    EDT  Natural Gas        2144
05/09/2018  00:05:00    EDT  Nuclear            4114
05/09/2018  00:05:00    EDT  Other Fossil Fuels 4
05/09/2018  00:05:00    EDT  Other Renewables   226
05/09/2018  00:05:00    EDT  Wind               41
05/09/2018  00:05:00    EDT  Hydro              3229
05/09/2018  00:10:00    EDT  Dual Fuel          1307
05/09/2018  00:10:00    EDT  Natural Gas        2092
05/09/2018  00:10:00    EDT  Nuclear            4115

Can someone show some simple examples on how to do that?

chelsea
  • 21
  • 3

1 Answers1

1

Just read your file as byte array and pass it in payload.

 byte[] payload = File.ReadAllBytes("your file path");
 messageBuilder = new MqttApplicationMessageBuilder()
                                .WithAtLeastOnceQoS()
                                .WithPayload(payload)
                                .WithTopic(topic)
                                .WithRetainFlag()
                                .Build();
CodingMytra
  • 2,234
  • 1
  • 9
  • 21