2025年4月9日水曜日

Kaluma(3)-esp01-AT (tutorial:connecting to internet)

 https://javascript.plainenglish.io/physical-computing-with-javascript-8-8-connecting-to-internet-151ba3dfce59

ーーーapp.js for node まずこれでip,portを確認ーーーー

const express = require('express');

const app = express();

const ip = require('ip');

const addr = ip.address();

const port = 3000

const html = `

  <html>

  <head></head><body>

  <h1>{{t}}@deg-celsius</h1>

  <h2>{{h}}@rel-percent</h2>

  </body></html>

`


let temperature = '0.0';

let humidity = '0.0';


app.get('update',(req,res) => {

   temperature = req.query.t

   humidity = res.query.h

   res.status(200).send('ok')

})


app.get('/',(req,res) => {

  res.setHeader('content-type','text/html');

  res.send(html.replace('{{t}}',temperature).replace('{{h}}',humidity));

  })



app.listen(port,() => {

  console.log(`app listening at http://${addr}:${port}`);

})

ーーーkaluma shellでcredentialsをセット----------

> storage.setItem('WIFI_SSID', 'xxxxxxx');
> storage.setItem('WIFI_PASSWORD', 'xxxxxxxx');
> storage.setItem('ADDRESS', 'xxx.xxx.x.xx');
> storage.setItem('PORT', '3000');

-------次のindex.jsをflash(no bundle needed if you not use dht)--------

0 件のコメント:

コメントを投稿