/// <summary> /// Change the sensor's spread factor to 7, BW 125 kHz /// </summary> private static async Task SetSpreadFactor(string sensorId) { Console.WriteLine("Test /api/sensor/set-tx-spreading-factor"); Console.WriteLine("Set Tx Spread Factor to SF 7, BW 125 kHz (y/n)?"); string input = Console.ReadLine(); if (input == "y" || input == "Y") { try { // Sample JSON to send. Payload is an int (see API documentation) JObject json = new JObject { ["sensorId"] = sensorId, ["payload"] = 6 }; Console.WriteLine("Sending set Tx spreading factor..."); await SensorApi.SetTxSpreadingFactor(json.ToString()); Console.WriteLine("Set Tx spreading factor sent" + "\n"); } catch (Exception ex) { Console.WriteLine("Method Error: " + ex.Message + "\n"); } } }
/// <summary> /// Sets the sensor's wakeup interval to every 5 minutes. /// </summary> private static async Task SetWakeupInterval(string sensorId) { Console.WriteLine("Test /api/sensor/set-lora-wakeup-interval"); Console.WriteLine("Set LoRa wakeup interval to 5 minutes (y/n)?"); string input = Console.ReadLine(); if (input == "y" || input == "Y") { try { // Sample JSON to send. Payload is in minutes (integer) JObject json = new JObject { ["sensorId"] = sensorId, ["payload"] = 5 }; Console.WriteLine("Sending set LoRa wakeup interval..."); await SensorApi.SetLoraWakeupInterval(json.ToString()); Console.WriteLine("Set LoRa wakeup interval Sent" + "\n"); } catch (Exception ex) { Console.WriteLine("Method Error: " + ex.Message + "\n"); } } }
/// <summary> /// This will set the sensor's LoRa Tx power to ll dBs. /// </summary> private static async Task SetTxPower(string sensorId) { Console.WriteLine("Test /api/sensor/set-lora-tx-power"); Console.WriteLine("Set LoRa Tx Power to 11 (y/n)?"); string input = Console.ReadLine(); if (input == "y" || input == "Y") { try { // Sample JSON to send. Payload is between 1 and 30 inclusinve (integer) JObject json = new JObject { ["sensorId"] = sensorId, ["payload"] = 11 }; Console.WriteLine("Sending set LoRa Tx Power..."); await SensorApi.SetLoraTxPower(json.ToString()); Console.WriteLine("Set LoRa Tx Power sent" + "\n"); } catch (Exception ex) { Console.WriteLine("Method Error: " + ex.Message + "\n"); } } }
/// <summary> /// Fetch sensor history within the timespan and report the number of results. /// Check private variables 'startTime' and 'endTime' for the timespan /// and adjust these as needed! /// </summary> private static async Task GetSensorHistoryCount(string sensorId) { Console.WriteLine("Test /api/sensor/history"); Console.WriteLine("Get Sensor History (y/n)? "); string input = Console.ReadLine(); if (input == "y" || input == "Y") { // Sample JSON to send JObject json = new JObject { ["sensorId"] = sensorId, ["startTime"] = startTime, ["endTime"] = endTime }; try { List <SensorHistoryLog> logs = await SensorApi.SensorHistory(json.ToString()); Console.WriteLine("Number of results: " + logs.Count + "\n"); } catch (Exception ex) { Console.WriteLine("Method Error: " + ex.Message + "\n"); } } }
/// <summary> /// Send down a recalibrate request /// </summary> /// <returns></returns> private static async Task SendRecalibrate(string sensorId) { Console.WriteLine("Test /api/sensor/recalibrate"); Console.WriteLine("Recalibrate sensor (y/n)? "); string input = Console.ReadLine(); if (input == "y" || input == "Y") { // Sample JSON to send JObject json = new JObject { ["sensorId"] = sensorId }; try { Console.WriteLine("Sending Recalibrate request..."); await SensorApi.Recalibrate(json.ToString()); Console.WriteLine("Recalibrate Sent" + "\n"); } catch (Exception ex) { Console.WriteLine("Method Error: " + ex.Message + "\n"); } } }
public SampleAppOne(IHttpAsync http) { Driveways = new DrivewayApi(http); ParkingLots = new ParkingLotApi(http); Sensors = new SensorApi(http); Route = http.BaseRoute; }
public SampleAppOne(IHttpAsync http) { _drivewayApi = new DrivewayApi(http); _parkingLotApi = new ParkingLotApi(http); _sensorApi = new SensorApi(http); _route = http.BaseRoute; }
/// <summary> /// Set sensor's frequency sub band to 902.3 kHz - 903.7 kHz - 125k" /// </summary> private static async Task SetFrequencySubBand(string sensorId) { Console.WriteLine("Test /api/sensor/set-frequency-sub-band"); Console.WriteLine("Set Frequency sub band to 902.3 kHz - 903.7 kHz - 125k"); string input = Console.ReadLine(); if (input == "y" || input == "Y") { try { // Sample JSON to send. Payload is an int (see API documentation) JObject json = new JObject { ["sensorId"] = sensorId, ["payload"] = 1 }; Console.WriteLine("Sending set requency Sub Band..."); await SensorApi.SetFrequencySubBand(json.ToString()); Console.WriteLine("Set frequency sub band sent" + "\n"); } catch (Exception ex) { Console.WriteLine("Method Error: " + ex.Message + "\n"); } } }
public async Task GetAllSensorValues() { SensorApi api = new SensorApi(); var results = (await api.GetSensorValues(1, 60)).ToList(); Assert.IsTrue(results.Any(), "Count:" + results.Count); }
public async Task GetenvValues() { SensorApi api = new SensorApi(); var results = (await api.GetUserEnvironments(14)).ToList(); Assert.IsTrue(results.Any(), "Count:" + results.Count); }
/// <summary> /// Remove that updated sensor /// </summary> /// <param name="sensorId">The Id of the updated sensor</param> private static async Task RemoveSensor(string sensorId) { Console.WriteLine("Testing '/api/sensor/remove'"); // Sample JSON to send JObject json = new JObject { ["sensorId"] = sensorId }; await SensorApi.RemoveSensor(json.ToString()); Console.WriteLine("Sensor Remove Success\n"); }
/// <summary> /// Fetch all of the sensors and print them out /// </summary> private static async Task GetSensors() { Console.WriteLine("Testing '/api/sensors'"); List <Sensor> sensors = await SensorApi.GetSensors("{}"); Console.WriteLine("Got " + sensors.Count + " Sensors:"); foreach (Sensor sensor in sensors) { Console.WriteLine("--> " + sensor.SensorId + ": " + sensor.ParkingSpace + ", " + sensor.Status + ", " + sensor.ParkingLot); } Console.WriteLine(); }
/// <summary> /// Update that new sensor's name to "TEST: c#-api-sensor-update". Also update its location. /// </summary> /// <param name="sensorId">The Id of the inserted sensor</param> private static async Task UpdateSensor(string sensorId) { Console.WriteLine("Testing '/api/sensor/update'"); // Sample JSON to send JObject json = new JObject { ["sensorId"] = sensorId, ["parkingSpace"] = "TEST: c#-api-sensor-update", ["latitude"] = 33.810280507079874, ["longitude"] = -117.9189795255661 }; await SensorApi.UpdateSensor(json.ToString()); Console.WriteLine("Sensor Update Success\n"); }
/// <summary> /// Insert a new sensor named "TEST: c#-api-sensor-insert" /// </summary> /// <param name="sensorId">The Id of the sensor to insert</param> /// <param name="parkingLotId">The Id of the parking lot inserted earlier</param> private static async Task InsertSensor(string sensorId, string parkingLotId) { Console.WriteLine("Testing '/api/sensor/insert'"); // Sample JSON to send JObject json = new JObject { ["sensorId"] = sensorId, ["parkingSpace"] = "TEST: c#-api-sensor-insert", ["parkingLotId"] = parkingLotId, ["network"] = "PNI", ["appEui"] = "0000000000000000", ["appKey"] = "00000000000000000000000000000000", ["disabled"] = false, ["latitude"] = 33, ["longitude"] = -111 }; await SensorApi.InsertSensor(json.ToString()); Console.WriteLine("Sensor Insert Success\n"); }
/// <summary> /// Force the sensor's Car Presence to say occcupied /// </summary> private static async Task ForceOccupied(string sensorId) { Console.WriteLine("Test /api/sensor/force-occupied"); Console.WriteLine("Force car presence to occupied (y/n)?"); string input = Console.ReadLine(); if (input == "y" || input == "Y") { // Sample JSON to send JObject json = new JObject { ["sensorId"] = sensorId }; try { Console.WriteLine("Sending Force Occupied..."); await SensorApi.ForceOccupied(json.ToString()); Console.WriteLine("Force Occupied Sent" + "\n"); } catch (Exception ex) { Console.WriteLine("Method Error: " + ex.Message + "\n"); } } }
public async Task InsertSensorTemp() { SensorApi api = new SensorApi(); await api.StoreSensorData("50ea847f-ad7a-4a1a-a5be-438f94e1372086da0c1a-46b8-4428-b549-a7b6f7857831ee3dd4e2-db11-4ab6-acf1-5e77e2f8e4ce", 2, "temp", 99); }
public SampleAppTwo(IHttpAsync http) { _sensorApi = new SensorApi(http); _sensorLogApi = new SensorLogApi(http); _route = http.BaseRoute; }
/// <summary> /// First sends a BIST initialization request to the sensor, then checks /// for the sensor response every second over the course of 5 minutes. /// </summary> /// <returns></returns> private static async Task FullBist(string sensorId) { Console.WriteLine("Test /api/initialize-bist and /api/sensor/bist-response/{SensorId}/{LastUpdated}"); Console.WriteLine("Run basic internal self test (BIST) (y/n)?"); string input = Console.ReadLine(); if (input == "y" || input == "Y") { // Sample JSON to send JObject json = new JObject { ["sensorId"] = sensorId }; try { Console.WriteLine("Sending BIST request..."); string now = DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss"); // Initialize the test await SensorApi.InitializeBist(json.ToString()); Console.WriteLine("BIST Sent at UTC: " + now); List <BistResponse> responses = new List <BistResponse>(); // We want to call the bist-response every second for 5 minutes // or until a response comes back. int timer = 0; while (timer < 300) { responses = await SensorApi.BistResponse(sensorId, now); if (responses.Count > 0) { break; } Console.WriteLine("Waiting for Bist response " + (++timer)); await Task.Delay(1000); } if (timer >= 300) { Console.WriteLine("No response..."); } else { Console.WriteLine("BIST response recieved!"); foreach (BistResponse response in responses) { Console.WriteLine("--> " + response.SensorType + ": " + response.Status); } } Console.WriteLine(); } catch (Exception ex) { Console.WriteLine("Method Error: " + ex.Message + "\n"); } } }
public SampleAppTwo(IHttpAsync http) { Sensors = new SensorApi(http); SensorLogs = new SensorLogApi(http); Route = http.BaseRoute; }
/// <summary> /// Send down a Ping request and wait up to 5 minutes for the response /// </summary> /// <returns></returns> private static async Task FullPingTest(string sensorId) { Console.WriteLine("Test /api/sensor/ping and /api/sensor/ping-response/{SensorId}/{LastUpdated}"); Console.WriteLine("Ping sensor (y/n)?"); string input = Console.ReadLine(); if (input == "y" || input == "Y") { // Sample JSON to send JObject json = new JObject { ["sensorId"] = sensorId }; try { Console.WriteLine("Sending Ping request..."); string now = DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss"); // Send down the Ping request await SensorApi.InitializePing(json.ToString()); Console.WriteLine("Ping Sent at UTC: " + now); List <PingResponse> responses = new List <PingResponse>(); // We want to call the ping-response every second for 5 minutes // or until a response comes back. int timer = 0; while (timer < 300) { responses = await SensorApi.PingResponse(sensorId, now); if (responses.Count > 0) { break; } Console.WriteLine("Waiting for Ping response " + (++timer)); await Task.Delay(1000); } if (timer >= 300) { Console.WriteLine("No response..."); } else { Console.WriteLine("Ping response recieved!"); foreach (PingResponse response in responses) { Console.WriteLine("--> Ping RSSI: " + response.PingRssi + ", Ping SNR: " + response.PingSNR + ". Server time: " + response.ServerTime); } } Console.WriteLine(); } catch (Exception ex) { Console.WriteLine("Method Error: " + ex.Message + "\n"); } } }