顯示具有 ESP8266 標籤的文章。 顯示所有文章
顯示具有 ESP8266 標籤的文章。 顯示所有文章

2022年12月1日 星期四

How to embed bootstrap in the SPIFFS disk of ESP8266

ESP8266 - How to embed bootstrap in the SPIFFS disk of ESP8266

This is a quick write up of me following the instruction at the link below to try out embedding bootstrap in the SPIFFS disk of ESP8266.

Embed bootstrap into an ESP8266 Web server with SPIFFS
https://www.techtinker.co.za/2018/08/28/fully-embed-bootstrap-into-an-esp8266-web-server/

Note that my Arduino IDE already has "ESP8266 Sketch Data Upload" installed from other projects, if you don't have it installed in your Arduino IDE, follow the instruction in the link below to install it.

https://www.instructables.com/id/Using-ESP8266-SPIFFS/

Uploading bootstrap to SPIFFS for off-line use

1. Create a "data" directory in the directory where the Arduino sketch is kept.

2. Download the bootstrap framework from this link https://getbootstrap.com/.

In the css and the js folder, find the highlighted files as shown below and create a compressed version of them using program such as 7zip and save them in the .gz format.

In the css folder

In the js folder

3. Copy the 4 .gz files to the "data" folder created in step 1 above.

Note, alternatively, you could just download the project which contains the main Arduino sketch and the 5 files shown below from the link below.

https://drive.google.com/drive/folders/1pxuUSQCHoMsyVPuX8-EfgiWuip-1YvfE.

- bootstrap.css.map.gz
- bootstrap.min.css.gz
- bootstrap.min.js.gz
- bootstrap.min.js.map.gz
- index.html.gz

The index.html.gz contains the web page that will be served by the webserver running on ESP8266. The content of this file is shown below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="/favicon.ico">

    <title>Fixed top navbar example for Bootstrap</title>

    <!-- Bootstrap core CSS -->
    <link href="/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="navbar-top-fixed.css" rel="stylesheet">
  </head>

  <body>

    <nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
      <a class="navbar-brand" href="#">Fixed navbar</a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbarCollapse">
        <ul class="navbar-nav mr-auto">
          <li class="nav-item active">
            <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#">Link</a>
          </li>
          <li class="nav-item">
            <a class="nav-link disabled" href="#">Disabled</a>
          </li>
        </ul>
        <form class="form-inline mt-2 mt-md-0">
          <input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
          <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
        </form>
      </div>
    </nav>
 <br><br><br>
    <main role="main" class="container">
      <div class="jumbotron">
        <h1>Navbar example</h1>
        <p class="lead">This example is a quick exercise to illustrate how fixed to top navbar works. As you scroll, it will remain fixed to the top of your browser's viewport.</p>
        <a class="btn btn-lg btn-primary" href="../../components/navbar/" role="button">View navbar docs &raquo;</a>
      </div>
    </main>

    <!-- Bootstrap core JavaScript
    ================================================== -->

    <script src="/bootstrap.min.js"></script>
  </body>
</html>

4. Connect ESP8266 to the computer, launch Arduino IDE. In Arduino IDE, click on "Tools", then click on "ESP8266 Sketch Data Upload" to upload the files in the "data" directory to the SPIFFS disk of ESP8266.

The upload progress will be displayed through the message window of the Arduino IDE.

5. Compile and upload the sketch below to ESP8266. Be sure to put the credential of your wifi network in the "ssid" and "password" fields.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Source: https://www.techtinker.co.za/2018/08/28/fully-embed-bootstrap-into-an-esp8266-web-server/

#include <FS.h> 
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
 
const char* ssid = "Your_Existing_AP";
const char* password = "password_of your_existing_wifi_network";

ESP8266WebServer server(80);

void setup() {
  
   Serial.begin(115200);
   
   WiFi.mode(WIFI_STA);
   WiFi.begin(ssid,password); 
   
   // Wait for connection
   while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
   }
   
   Serial.println(WiFi.localIP());
 
   server.begin(); 
   server.on("/", fileindex);
   server.on("/index.html", fileindex);
   server.on("/bootstrap.min.css", bootstrap);
   server.on("bootstrap.min.css", bootstrap);
   server.on("/popper.min.js", popper);
   server.on("/bootstrap.min.js", bootstrapmin);
   server.on("bootstrap.min.js", bootstrapmin);

   //NEW
   SPIFFS.begin(); 
}
 
void loop() {
   server.handleClient();
}
 
void fileindex(){
   File file = SPIFFS.open("/index.html.gz", "r"); 
   size_t sent = server.streamFile(file, "text/html");
}

void bootstrap(){
   File file = SPIFFS.open("/bootstrap.min.css.gz", "r"); 
   size_t sent = server.streamFile(file, "text/css");
}

void popper(){
   File file = SPIFFS.open("/popper.min.js.gz", "r"); 
   size_t sent = server.streamFile(file, "application/javascript");
}

void bootstrapmin(){
   File file = SPIFFS.open("/bootstrap.min.js.gz", "r"); 
   size_t sent = server.streamFile(file, "application/javascript");
}

6. Launch the Serial Monitor of the Arduino IDE to find the IP assigned to the ESP8266. Here, the IP assigned is 192.168.31.9.

7. Launch a web browser then enter the IP address obtained from above in the URL field to connect to the ESP8266.

A neat thing about using bootstrap is that it's responsive..

Reference - UI Design:

Bootstrap: create a beautiful Web Interface for your projects ESP8266
https://diyprojects.io/bootstrap-create-beautiful-web-interface-projects-esp8266/

Using ESP8266 SPIFFS
https://www.instructables.com/id/Using-ESP8266-SPIFFS/

Embed bootstrap into ESP8266
https://mybroadband.co.za/forum/threads/embed-bootstrap-into-esp8266.972617/

Bootstrap Tutorial for Beginners
https://www.youtube.com/watch?v=FMFm9GxB_Eo

Bootstrap Glyphicon Components
https://www.w3schools.com/bootstrap/bootstrap_ref_comp_glyphs.asp

======================================================================

Icons and symbols that could be used for artworks

GLYPHICONS®
https://www.glyphicons.com/

A library of precisely prepared monochromatic icons and symbols, created with an emphasis to simplicity and easy orientation. 

資料來源:http://wei48221.blogspot.com/2020/03/esp8266-how-to-embed-bootstrap-in.html

2022年8月23日 星期二

NodeMCU 開發套件/板

 

介紹

NodeMCU 開發套件/板由 ESP8266 wifi 芯片組成。ESP8266芯片具有GPIO引腳、串行通信協議等特性。

ESP8266 是樂鑫開發的一款低成本的 Wi-Fi 芯片,採用 TCP/IP 協議。有關 ESP8266 的更多信息,您可以參考 ESP8266 WiFi 模塊。

ESP8266 的特性是在 NodeMCU 開發板上提取的。NodeMCU(基於LUA的固件)與由 ESP8266(啟用 wifi 的芯片)芯片組成的開發板/套件結合了 NodeMCU 開發板,使其成為物聯網應用中的獨立設備。

讓我們看看 NodeMCU 開發套件的第一個版本及其引腳,如下圖所示。

NodeMCU 開發套件 v0.9

NodeMCU 開發套件 v0.9

NodeMCU開發板v0.9(版本1)

NodeMCU 開發板 v0.9 引腳分配

NodeMCU 開發套件 v0.9(V1) 引腳分配

NodeMCU 開發套件的第二版及其引腳如下圖所示。

NodeMCU 開發套件 v1.0

Amica NodeMCU 開發套件 v1.0(Version2)

NodeMCU 開發套件 v1.0 引腳分配

NodeMCU 開發套件 v1.0(V2) 引腳分配

NodeMCU 開發套件 v1.0 引腳說明

GPIO(通用輸入輸出)引腳:

NodeMCU 在其板上具有通用輸入輸出引腳,如上圖所示。我們可以將其設為數字高/低,並控制 LED 之類的東西或打開它。此外,我們可以在這些 GPIO 引腳上生成 PWM 信號。

有關 NodeMCU GPIO 的更多信息,請參閱此鏈接

有關 NodeMCU PWM 的更多信息,請參閱此鏈接

ADC(模數轉換器)通道(A0):

NodeMCU 的板上有一個 ADC 通道/引腳。

有關 NodeMCU ADC 的更多信息,請參閱此鏈接

SPI(串行外設接口)引腳:

基於 NodeMCU 的 ESP8266 具有硬件 SPI (HSPI),其中四個引腳可用於 SPI 通信。它還具有用於 Quad-SPI 通信的 SPI 引腳。通過這個 SPI 接口,我們可以將任何支持 SPI 的設備與 NodeMCU 連接,並使其通信成為可能。

有關 NodeMCU SPI 的更多信息,請參閱此鏈接

I2C(內部集成電路)引腳:

NodeMCU 在 ESP8266 GPIO 引腳上支持 I2C 功能。由於 ESP-12E 的內部功能,我們不能將其所有 GPIO 用於 I2C 功能。因此,在將任何 GPIO 用於 I2C 應用之前進行測試。

有關 NodeMCU I2C 的更多信息,請參閱此鏈接

UART(通用異步收發器)引腳:

基於 NodeMCU 的 ESP8266 有兩個 UART 接口,UART0 和 UART1。由於 UART0 (RXD0 & TXD0) 用於將固件/代碼上傳到開發板,因此在上傳固件/代碼時我們不能在應用程序中使用它們。

有關 NodeMCU UART 的更多信息,請參閱此鏈接

 

第一版和第二版 NodeMCU Board 的區別

我們可以通過其開發板的設計和其上的 ESP 模塊在 NodeMCU 開發板的第 1 版和第 2 版中有所作為。

  • 在 NodeMCU Dev Kit v0.9 的第一個版本中,使用了 CH341SER USB 到串行轉換器,而在 NodeMCU Dev Kit v1.0 的第二個版本中,使用了 CP2102 USB 到串行轉換器。
  • 第一版使用 ESP-12,第二版使用 ESP-12E(增強版)。
  • ESP-12E 版本的 ESP-12 模塊上引出了額外的 6 個引腳(MTDO、MTDI、SD_3、MTMS、MTCK、SD_2),如下圖所示。雖然 Quad SPI 引腳被引出,但它們在內部用於閃存訪問。
  • 此外,ESP12-E 和 ESP-12F 等 ESP-12 版本的天線設計略有不同,如下圖所示。

ESP-12 模塊

ESP-12 模塊

ESP8266 模塊系列

我們還可以查看各種 ESP 模塊及其 FCC 批准的esp8266 模塊系列和摘要,如下圖所示。

ESP 模塊總結

市場中的 NodeMCU 開發套件

NodeMCU 硬件是開源的,任何人都可以編輯/修改/生產它並銷售他們修改後的 NodeMCU 開發板。一般來說,我們可以看到 NodeMCU 開發板

阿米卡

多伊特

Lolin & D1 mini /Wemos 等在市場上。

Amica 生產具有設計硬件規格的 NodeMCU ESP8266 開發板 v1.0(Version2)。大多數 V2 板由 Amica 生產。

DoIt NodeMCU 開發套件

DOIT NodeMCU 開發套件 v1.0(Version2)

NodeMCU 硬件規格

我們可以從以下對所有人開放的鏈接中查看 NodeMCU Dev Kit v0.9 硬件規格和設計。

NodeMCU DevKit v0.9

NodeMCU 開發套件示意圖

NodeMCU 開發套件 v0.9 原理圖

此外,NodeMCU Dev Kit v1.0 硬件規格和設計在以下鏈接中給出

NodeMCU DevKit v1.0

注意: -兩個版本的 ADC 模塊都使用電阻分壓器網絡(220K 和 100K)來調整 ESP8266 ADC 輸入電壓範圍從 0-1V 到 0-3.3V。由於 ESP8266 ADC 引腳的輸入模擬電壓範圍為 0-1.0V(同時讀取外部模擬電壓),NodeMCU 開發板使用此電阻分壓器網絡將其擴展到 0-3.3V。

 

ESP8266 開發板

此外,我們可以看到設計上與上述 NodeMCU 開發板不同的 ESP8266 開發板/分線板,我們可以將它們與 NodeMCU 固件一起用於物聯網應用。

以下是市場上提供的具有不同尺寸、引腳排列和規格的 NodeMCU 替代板。

Adafruit Huzzah

Adafruit Huzzah ESP8266 開發板

Adafruit HUZZAH ESP8266 突破

Adafruit 羽毛 Huzzah

Adafruit 羽毛 huzzah ESP8266 板

帶有 ESP8266 WiFi 的 Adafruit Feather HUZZAH

有趣的東西

Sparkfun 的東西 ESP8266 板

SparkFun ESP8266 東西

RobotDyn NodeM ESP8266

robotsdyn NodeMCU

RobotDyn WIFI NodeM ESP8266

WeMos D1 迷你

WeMos D1 Mini ESP8266 開發板

WeMos D1 迷你

WeMos D1 mini Pro

WeMos D1 mini Pro

WeMos D1 mini Pro

WeMos D1 迷你精簡版

WeMos D1 Mini Lite ESP8266 開發板

WeMos D1 迷你精簡版

還有一些基於應用程序的板的修改設計可用。例如,

  • D-duino V3 板,板載 OLED 顯示屏。
  • AI-Thinker A20 Plus 板帶有 GPRS+Camera 功能。

D-Duino ESP8266 開發套件

D-duino V3 ESP8266 開發套件

 

AI-Thinker A20 Plus GPRS+ESP8266(wifi)+攝像頭

AI-Thinker A20 Plus GPRS + WiFi + 攝像頭

在這裡,我們可以說市場上沒有獨特的 NodeMCU 開發板設計。如果我們遇到他們的官方板,那麼我們可以意識到 Amica 板看起來像官方版本,而其他板則不是(因為它們是應用程序設計的)。

Amica 在其 Twitter 頁面上提供了一些關於改進其開發板的要點,如下圖所示。

amica 的 NodeMCU 開發套件改進


資料來源:https://www.electronicwings.com/nodemcu/nodemcu-development-kitboard

NodeMCU 入門

 

介紹

ESP8266是樂鑫開發的  一款低成本的 Wi-Fi 芯片,採用 TCP/IP 協議。

有關 ESP8266 的更多信息,您可以參考 ESP8266 WiFi 模塊。

NodeMCU 是一個基於LUA的固件,我們需要下載到 ESP8266 芯片上。

要下載 NodeMCU 固件,請訪問  https://nodemcu-build.com/

  • 輸入你的電子郵箱。

進入電子郵件窗口

  • 選擇要構建的分支

選擇分支構建窗口

  • 選擇要安裝的模塊。

例如,如果您想在 NodeMCU 中使用模擬傳感器,則選擇將提供對內置 ADC 訪問的 ADC 模型。

選擇要包含窗口的模塊

  • 我們可以為 TLS/SSL 支持、調試以及 FatFS 支持選擇其他選項,如下所示

其他選項窗口

  • 單擊開始構建。

開始構建窗口

  • 構建完成後,您將收到一封電子郵件,其中包含下載自定義固件的鏈接。點擊鏈接下載。
  • 請注意,您將獲得兩個自定義固件鏈接,一個是支持浮動的 NodeMCU,第二個是不支持浮動的 NodeMCU,即整數。
  • 如果不需要浮動支持,請下載整數支持固件 bin 文件,否則,下載浮動支持固件 bin 文件。

我們需要在 ESP8266 芯片上刷入上面下載的自定義固件。有一個名為 ESP8266Flasher 的工具,用於刷寫 ESP8266 芯片。

  • 下載ESP8266Flasher.exe從

            32位:https ://github.com/nodemcu/nodemcu-flasher/tree/master/Win32/Release

            64位:https ://github.com/nodemcu/nodemcu-flasher/tree/master/Win64/Release

  • 打開ESP8266Flasher.exe並點擊配置。

安裝 NodeMCU 固件

  • 單擊設置圖標,然後選擇在第一步中下載的固件

安裝 NodeMCU 固件

  • 選擇 COM 端口(在我的情況下是 COM 7)

安裝nodemcu固件

  • 將 USB 線連接到 NodeMCU 模塊,如下圖所示

NodeMCU 與 PC 的連接

NodeMCU 與 PC 的連接

然後點擊 Flash

  • 安裝固件後會出現一個綠色勾號

安裝nodemcu固件

  • 你好!ESP8266 與 Node-MCU 固件的設置已完成!

用 Node-MCU 固件設置 ESP 後,我們來看看開發 NodeMCU 所需的 IDE(集成開發環境)。

帶有 ESPlorer 的 NodeMCU

Lua腳本通常用於對 NodeMCU 進行編碼。Lua 是一種建立在 C 編程語言之上的開源、輕量級、可嵌入的腳本語言。

有關如何為 NodeMCU 編寫 Lua 腳本的更多信息,請參閱 使用 ESPlorerIDE 開始使用 NodeMCU

帶 Arduino 的 NodeMCU

這是使用眾所周知的 IDE(即 Arduino IDE)開發 NodeMCU 的另一種方法。我們還可以使用 Arduino 開發環境在 NodeMCU 上開發應用程序。這使得 Arduino 開發人員比學習 NodeMCU 的新語言和 IDE 更容易。

有關如何為 NodeMCU 編寫 Arduino 草圖的更多信息,請參閱 使用 ArduinoIDE 開始使用 NodeMCU

 

資料來源:https://www.electronicwings.com/nodemcu/getting-started-with-nodemcu