私は現在、Grove センサーと Windows IoT を備えた Raspberry Pi を使って実験しています。Raspberry Pi から Azure に情報を転送しようとすると、エラーが発生します (85 行目)。
コードは次のようになります。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Http;
using Windows.ApplicationModel.Background;
using GrovePi;
using GrovePi.I2CDevices;
using GrovePi.Sensors;
using GrovePi.Common;
using System.Threading.Tasks;
using Microsoft.Azure.Devices.Client;
using Newtonsoft.Json;
// The Background Application template is documented at http://go.microsoft.com/fwlink/?LinkID=533884&clcid=0x409
namespace GrooveTHS
{
public sealed class StartupTask : IBackgroundTask
{
IRgbLcdDisplay LCDDisplay;
public void Run(IBackgroundTaskInstance taskInstance)
{
IDHTTemperatureAndHumiditySensor sensor = DeviceFactory.Build.DHTTemperatureAndHumiditySensor(Pin.DigitalPin7, DHTModel.Dht11); // pinD7
LCDDisplay = DeviceFactory.Build.RgbLcdDisplay(); // pinI2C-1
IRotaryAngleSensor potentiometer = DeviceFactory.Build.RotaryAngleSensor(Pin.AnalogPin2); // pinA2
ILed red = DeviceFactory.Build.Led(Pin.DigitalPin5); // pinD5
ILed green = DeviceFactory.Build.Led(Pin.DigitalPin6); // pinD6
IUltrasonicRangerSensor dsensor = DeviceFactory.Build.UltraSonicSensor(Pin.DigitalPin4); // pin D4
double angle = 0;
double tmax = 0;
while (true)
{
Task.Delay(500).Wait();
angle = potentiometer.SensorValue();
sensor.Measure();
string sensortemp = sensor.TemperatureInCelsius.ToString();
tmax = Math.Floor(angle / 10);
string sensorvalue = dsensor.MeasureInCentimeters().ToString();
if (sensor.TemperatureInCelsius > tmax)
{
System.Diagnostics.Debug.WriteLine("Raumtemperatur: " + sensortemp + "C " + "Tmax: " + tmax.ToString() + "C");
red.AnalogWrite(Convert.ToByte(240));
green.AnalogWrite(Convert.ToByte(0));
}
else
{
System.Diagnostics.Debug.WriteLine("Raumtemperatur: " + sensortemp + "C" + "Tmax: " + tmax.ToString() + "C");
red.AnalogWrite(Convert.ToByte(0));
green.AnalogWrite(Convert.ToByte(240));
}
if (dsensor.MeasureInCentimeters() < 150)
{
LCDDisplay.SetBacklightRgb(BitConverter.GetBytes(990)[0], BitConverter.GetBytes(990)[0], BitConverter.GetBytes(990)[0]);
LCDDisplay.SetText("Raumtemperatur: " + sensortemp + "C " + "Tmax: " + tmax.ToString() + "C");
}
else
{
LCDDisplay.SetText("");
LCDDisplay.SetBacklightRgb(BitConverter.GetBytes(0)[0], BitConverter.GetBytes(0)[0], BitConverter.GetBytes(0)[0]);
}
}
}
static async void SendDeviceToCloudMessagesAsync(long inputDistance)
{
string iotHubUri = "IotHubAuburn.azure-devices.net"; // ! put in value !
string deviceId = "jb"; // ! put in value !
string deviceKey = "sHGJlQbLLMeMExNaqtvh8/7N7MHWlBZ0ESj2ePahSwQ="; // ! put in value !
DateTime time = DateTime.UtcNow;
var deviceClient = DeviceClient.Create(iotHubUri, AuthenticationMethodFactory.CreateAuthenticationWithRegistrySymmetricKey(deviceId, deviceKey), TransportType.Http1);
JSON jsonStr = new JSON();
jsonStr.distance = inputDistance;
jsonStr.time = time;
jsonStr.deviceId = deviceId;
var list = JsonConvert.SerializeObject(jsonStr);
System.Diagnostics.Debug.WriteLine(list);
var message = new Message(Encoding.UTF8.GetBytes(list));
await deviceClient.SendEventAsync(message);
}
}
}
そして、私が得ているエラーは次のとおりです(ドイツ語からの翻訳):
1) CS0246 型または名前空間名 "JSON" が見つかりませんでした (使用命令アセンブリまたは警告アセンブリが見つからない可能性があります)。
2) CS0246 型または名前空間名 "JSON" が見つかりませんでした (おそらく、使用命令または警告アセンブリが欠落しています)。
敬具、
アレックス