Hi there,
I am trying to do a similar thing. I am trying to send data remotely from C# code to influx DB 2.0. The health status on connection gives success but the data is not getting inserted into influxDB when I check on localhost:8086
Here is my code:
usingIoTHubTrigger=Microsoft.Azure.WebJobs.EventHubTriggerAttribute;
usingMicrosoft.Azure.WebJobs;
usingMicrosoft.Azure.WebJobs.Host;
usingMicrosoft.Azure.EventHubs;
usingSystem.Text;
usingSystem.Net.Http;
usingMicrosoft.Extensions.Logging;
usingSystem;
usingSystem.Text.Json;
usingSystem.Collections.Generic;
usingNewtonsoft.Json;
usingInfluxDB.Client;
usingInfluxDB.Client.Api.Domain;
usingInfluxDB.Client.Core;
usingInfluxDB.Client.Writes;
usingSystem.Threading.Tasks;
namespaceWatlow.Function
{ββββββββ
publicclassObject{ββββββββ
publicstringserial_number{ββββββββget;set;}ββββββββ
publicfloatuniversal_input_1_mod_5{ββββββββget;set;}ββββββββ
publicfloatuniversal_input_2_mod_5{ββββββββget;set;}ββββββββ
publicfloatuniversal_input_3_mod_5{ββββββββget;set;}ββββββββ
publicfloatuniversal_input_4_mod_5{ββββββββget;set;}ββββββββ
publicstringdisplay_units{ββββββββget;set;}ββββββββ
publicDateTimets{ββββββββget;set;}ββββββββ
}ββββββββ
publicstaticclassIotHubDataProcessing
{ββββββββ
privatestaticHttpClientclient=newHttpClient();
[FunctionName(βIotHubDataProcessingβ)]
publicstaticvoidRun([IoTHubTrigger(βmessages/eventsβ,Connection=βConnectionStringβ)]EventDatamessage,ILoggerlog)
{ββββββββ
log.LogInformation($βC# IoT Hub trigger function processed a message: {ββββββββEncoding.UTF8.GetString(message.Body.Array)}βββββββββ);
Objectobj=JsonConvert.DeserializeObject(Encoding.UTF8.GetString(message.Body.Array));
WriteInflux(obj);
}ββββββββ
publicstaticasyncvoidWriteInflux(Objectobj)
{ββββββββ
conststringtoken=βpcSpeRibWx0XakβKpLI23kk52LZDbPcRjKKpmtPqZ8l47_mlUMsrgG69XeSmchQ_apOWwmgh8CpN1QQ2oQTuQ==β;
conststringbucket=βtimeseriesDBβ;
conststringorg=βxxxxβ;
conststringpassword=βxxxxxβ;
varclient=InfluxDBClientFactory.Create(βhttp://20.83.176.xxx:8086β,βxxxxβ,password.ToCharArray());
varhealth=awaitclient.HealthAsync();
if(health.Status.ToString()==βPassβ){ββββββββ
Console.WriteLine(βConnection success.β);
}ββββββββ
else{ββββββββ
Console.WriteLine($β{ββββββββhealth.Status}βββββββββ);
Console.WriteLine($βConnection failure: {ββββββββhealth.Message}ββββββββ!β);
}ββββββββ
varpoint=PointData
.Measurement(βtemperatureβ)
.Tag(βserialNumberβ,obj.serial_number)
.Field(βtc1β,obj.universal_input_1_mod_5)
.Field(βtc2β,obj.universal_input_2_mod_5)
.Field(βtc3β,obj.universal_input_3_mod_5)
.Field(βtc4β,obj.universal_input_4_mod_5)
.Timestamp(DateTime.UtcNow,WritePrecision.Ns);
using(varwriteApi=client.GetWriteApi())
{ββββββββ
writeApi.WritePoint(bucket,org,point);
}ββββββββ
}ββββββββ
}ββββββββ
}ββββββββ
β