Fish
Published © CC BY-NC

Dempsey - Over the pond (Using the S2104)

With our sensors in place, we can now start to use some of the data to help create the haven that Dempsey is attempting to manufacture.

BeginnerFull instructions provided6 minutes652

Things used in this project

Hardware components

SenseCAP S2104 - LoRaWAN Soil Moisture and Temperature Sensor
Seeed Studio SenseCAP S2104 - LoRaWAN Soil Moisture and Temperature Sensor
×1
SenseCAP M1 LoRaWAN Indoor Gateway - EU868
Seeed Studio SenseCAP M1 LoRaWAN Indoor Gateway - EU868
×1
Seeed Studio SenseCAP Outdoor Enclosure
×1

Software apps and online services

Microsoft Visual Studio Code
Seeed Studio SenseCAP - Mate
Seeed Studio SenseCAP - Hotspot App
Helium Wallet App

Story

Read more

Code

getSoilTemp.js

JavaScript
// Set $APIKey, $APIValue & $DevEUI
// Set $APIKey, $APIValue & $DevEUI
function getSoilTemp () {
      var soilTemp = "https://sensecap.seeed.cc/openapi/view_latest_telemetry_data?device_eui=$DevEUI&measurement_id=4102&channel_index=1";
      var creds = btoa("$APIKey:$APIValue");
// Get Data     
      fetch (soilTemp, {
        headers: {
          "Authorization": `Basic ${creds}`
        }
      })
// Error Handling
      .then((result) => {
        if (result.status != 200) { throw new Error("Bad Server Response"); }
        return result.text();
      })
// Parse Data
      .then((response) => {
        document.getElementById("Temperature").innerHTML = response;
        $.getJSON( response, {
            measurement_value: "",
            tagmode: "any",
            format: "json"
          })
      })
// Error Handling
      .catch((error) => { console.log(error); });
    }

SenseFetch.html

HTML
Run from the same folder as getSoilTemp.js
<!DOCTYPE html>
<html>
    <script type="text/javascript" src="GetSoilTemp.js"></script>
<body> 	
    <h1>Get Soil Temperature:</h1>
        <div id="Temperature"></div>
        	<input type="button" value="Fetch Soil Temperature" onclick="getSoilTemp()"/>
</body>
</html>

Sense-API-Fetch

Simple HTTP fetch requests made to the sense.seeed.cc dashboard

Credits

Fish

Fish

4 projects • 10 followers
Trying to make sense of it all and helping others along the way..
Thanks to Dempsey.

Comments