အနုပညာ
အလှအပနှင့် ကျန်းမာရေး
လက်မှုအနုပညာ
ယဉ်ကျေးမှုနှင့် သမိုင်း
ဖျော်ဖြေရေး
ပတ်ဝန်းကျင်
အစားအစာနှင့် အချိုရည်
ပြောင်းပြန်အင်ဂျင်နီယာပညာ
သိပ္ပံပညာများ
အားကစား
နည်းပညာ
ဝတ်ဆင်နိုင်သောပစ္စည်းများ
Temperature Logger in a Web Page: Web Bluetooth Reads, Plots and Saves a BLE Thermometer
Ed

ဖန်တီးသူ

Ed

4. ဒီဇင်ဘာ 2026FI
၀
၀
၀
၀
၀

Temperature Logger in a Web Page: Web Bluetooth Reads, Plots and Saves a BLE Thermometer

One HTML file that turns a browser into a temperature logger: it connects to any Bluetooth LE thermometer using the standard Environmental Sensing service, shows the reading, draws the history and saves it as a CSV file. No install and no server code.
အစပြု
20 minutes

ညွှန်ကြားချက်များ

1

The page

Save this as thermo-logger.html.
thermo-logger.htmlhtml
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>BLE temperature logger</title>
<style>
  body { font-family: system-ui, sans-serif; margin: 1.5rem; max-width: 760px; }
  #now { font-size: 3rem; font-weight: bold; margin: .5rem 0; }
  canvas { width: 100%; height: 260px; border: 1px solid #ccc; }
  button { font-size: 1rem; padding: .5rem 1rem; margin-right: .5rem; }
</style>
</head>
<body>
<h1>BLE temperature logger</h1>
<p>Reads any device with the Environmental Sensing service (0x181A) and its Temperature characteristic (0x2A6E).</p>
<button id="connect">Connect</button><button id="csv" disabled>Download CSV</button>
<div id="now">-- °C</div>
<div id="status">Not connected.</div>
<canvas id="chart" width="1200" height="400"></canvas>
<script>
const ESS = 0x181A, TEMP = 0x2A6E;
const log = [];                                   // [time (ms), °C]
const $ = id => document.getElementById(id);

function onValue(event) {
  const raw = event.target.value.getInt16(0, true); // sint16, little-endian, 0.01 °C
  if (raw === -32768) { $('status').textContent = 'Device says: value not known (0x8000).'; return; }
  const c = raw / 100;
  log.push([Date.now(), c]);
  $('now').textContent = c.toFixed(2) + ' °C';
  $('csv').disabled = false;
  draw();
}

function draw() {
  const cv = $('chart'), g = cv.getContext('2d'), W = cv.width, H = cv.height;
  g.clearRect(0, 0, W, H);
  if (log.length < 2) return;
  const ys = log.map(p => p[1]), lo = Math.min(...ys) - 0.5, hi = Math.max(...ys) + 0.5;
  const t0 = log[0][0], t1 = log[log.length - 1][0];
  g.strokeStyle = '#c0392b'; g.lineWidth = 3; g.beginPath();
  log.forEach(([t, c], i) => {
    const x = 40 + (W - 60) * (t - t0) / (t1 - t0), y = H - 30 - (H - 60) * (c - lo) / (hi - lo);
    i ? g.lineTo(x, y) : g.moveTo(x, y);
  });
  g.stroke();
  g.fillStyle = '#333'; g.font = '22px sans-serif';
  g.fillText(hi.toFixed(1) + ' °C', 4, 24); g.fillText(lo.toFixed(1) + ' °C', 4, H - 6);
}

$('connect').onclick = async () => {
  try {
    const device = await navigator.bluetooth.requestDevice({ filters: [{ services: [ESS] }] });
    device.addEventListener('gattserverdisconnected', () => { $('status').textContent = 'Disconnected.'; });
    $('status').textContent = 'Connecting to ' + device.name + '…';
    const server = await device.gatt.connect();
    const service = await server.getPrimaryService(ESS);
    const ch = await service.getCharacteristic(TEMP);
    ch.addEventListener('characteristicvaluechanged', onValue);
    await ch.startNotifications();
    $('status').textContent = 'Connected to ' + device.name + '; logging.';
  } catch (e) {
    $('status').textContent = 'Error: ' + e.message;
  }
};

$('csv').onclick = () => {
  const rows = ['time,temperature_c', ...log.map(([t, c]) => new Date(t).toISOString() + ',' + c.toFixed(2))];
  const a = document.createElement('a');
  a.href = URL.createObjectURL(new Blob([rows.join('\n')], { type: 'text/csv' }));
  a.download = 'temperature.csv'; a.click();
};
</script>
</body>
</html>

လိုအပ်သော ကိရိယာများ:

စားပွဲတင်ကွန်ပျူတာစားပွဲတင်ကွန်ပျူတာ
2

Serve it and connect

Web Bluetooth only runs on secure pages: open the file through https or from localhost, for example run python3 -m http.server in its folder and open http://localhost:8000/thermo-logger.html in a browser that supports Web Bluetooth. Press Connect, pick the thermometer, and leave the page open while it logs. Download CSV saves every reading with its time.

လိုအပ်သော ကိရိယာများ:

စားပွဲတင်ကွန်ပျူတာစားပွဲတင်ကွန်ပျူတာ
SmartphoneSmartphone
Bluetooth ThermometerBluetooth Thermometer

လိုအပ်သော ကိရိယာများ

3

အခြေခံထားသည်: ယခင် အသေးစိတ်ပုံစံများမှ ကုန်ကြမ်းများ

ဤအသေးစိတ်ပုံစံက ပြုလုပ်သည်

CC0 အများပိုင်

ဤအစီအစဉ်ကို CC0 အောက်တွင် ထုတ်ဝေထားသည်။ ခွင့်ပြုချက်မလိုဘဲ ကူးယူ၊ ပြင်ဆင်၊ ဖြန့်ဝေ နှင့် အသုံးပြုနိုင်သည်။

အစီအစဉ်မှတစ်ဆင့် ကုန်ပစ္စည်းများဝယ်ယူ၍ လက်မှုပညာရှင်ကို ပံ့ပိုးပါ လက်မှုပညာရှင် ကော်မရှင် ရောင်းချသူက သတ်မှတ်သည်၊ သို့မဟုတ် ဤအစီအစဉ်၏ ဗားရှင်းအသစ်ဖန်တီး၍ ဝင်ငွေခွဲဝေရန် သင့်အစီအစဉ်တွင် ချိတ်ဆက်မှုအဖြစ် ထည့်သွင်းပါ။

ဆွေးနွေးချက်

(0)

ဝင်ရောက် ဆွေးနွေးချက်တွင် ပါဝင်ရန်

မှတ်ချက်များ ရယူနေသည်...