I am using an MKRNB1500 with an IoT T-mobile SIM card and I am able to send data to the T-Mobile page.
I would like to connect the T-mobile with the AzureHUB. How can I do that?
I followed the steps and created a FunctionApp, but when I copy and paste that long program in C# that is suggested from the website guide and run it…it creates an error message.
PROGRAMME
#r “Microsoft.WindowsAzure.Storage”
using System;
using System.Configuration;
using System.Net;
using System.Text;
using Microsoft.Azure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
HttpStatusCode result;
string contentType;
result = HttpStatusCode.OK;
contentType = req.Content.Headers?.ContentType?.MediaType;
if(contentType == "application/json")
{
string body;
body = await req.Content.ReadAsStringAsync();
if(!string.IsNullOrEmpty(body))
{
string name;
name = Guid.NewGuid().ToString("n");
await CreateBlob(name + ".json", body, log);
result = HttpStatusCode.OK;
}
}
return req.CreateResponse(result, string.Empty);
}
private async static Task CreateBlob(string name, string data, TraceWriter log)
{
string accessKey;
string accountName;
string connectionString;
CloudStorageAccount storageAccount;
CloudBlobClient client;
CloudBlobContainer container;
CloudBlockBlob blob;
accessKey = ConfigurationManager.AppSettings["StorageAccessKey"];
accountName = ConfigurationManager.AppSettings["StorageAccountName"];
connectionString = "DefaultEndpointsProtocol=https;AccountName=" + accountName + ";AccountKey=" + accessKey + ";EndpointSuffix=core.windows.net";
storageAccount = CloudStorageAccount.Parse(connectionString);
client = storageAccount.CreateCloudBlobClient();
container = client.GetContainerReference("nbiot");
await container.CreateIfNotExistsAsync();
blob = container.GetBlockBlobReference(name);
blob.Properties.ContentType = "application/json";
using (Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(data)))
{
await blob.UploadFromStreamAsync(stream);
}
}
ERROR MESSAGE:
2019-05-11T14:30:44 Welcome, you are now connected to log-streaming service.
2019-05-11T14:30:55.912 [Information] Executing ‘Functions.TmobileIoT’ (Reason=‘This function was programmatically called via the host APIs.’, Id=b2acae17-00ad-4d4b-9676-4d08d14c5e89)
2019-05-11T14:30:55.979 [Error] Function compilation error
Microsoft.CodeAnalysis.Scripting.CompilationErrorException : Script compilation failed.
at async Microsoft.Azure.WebJobs.Script.Description.DotNetFunctionInvoker.CreateFunctionTarget(CancellationToken cancellationToken) at C:\azure-webjobs-sdk-script\src\WebJobs.Script\Description\DotNet\DotNetFunctionInvoker.cs : 314
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.Azure.WebJobs.Script.Description.FunctionLoader`1.GetFunctionTargetAsync[T](Int32 attemptCount) at C:\azure-webjobs-sdk-script\src\WebJobs.Script\Description\FunctionLoader.cs : 55
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.Azure.WebJobs.Script.Description.DotNetFunctionInvoker.GetFunctionTargetAsync(Boolean isInvocation) at C:\azure-webjobs-sdk-script\src\WebJobs.Script\Description\DotNet\DotNetFunctionInvoker.cs : 183
2019-05-11T14:30:56.100 [Warning] run.csx(11,75): warning CS0618: ‘TraceWriter’ is obsolete: ‘Will be removed in an upcoming version. Use Microsoft.Extensions.Logging.ILogger instead.’
2019-05-11T14:30:56.101 [Warning] run.csx(41,64): warning CS0618: ‘TraceWriter’ is obsolete: ‘Will be removed in an upcoming version. Use Microsoft.Extensions.Logging.ILogger instead.’
2019-05-11T14:30:56.137 [Error] run.csx(38,16): error CS1501: No overload for method ‘CreateResponse’ takes 2 arguments
2019-05-11T14:30:56.207 [Error] Executed ‘Functions.TmobileIoT’ (Failed, Id=b2acae17-00ad-4d4b-9676-4d08d14c5e89)
Script compilation failed.
Also I do not really grasp the concept of sending regularly data from a sensor, since AT commands works if you type them and not automatically. Serial.printing them doesn’t work in the serial monitor of the arduino ide. Could you also help for this problem? If not it is also ok.