2024年2月

        esp32系列是高性价比物联网节点设备的代表,速度够快,自带WIFI又可以使用Arduino IDE编程,最近试用了一种带有OV2640摄像头的ESP32-CAM只要很简单地设置就可以做很多种工作,以下是试验记录。

        Arduino IDE要在首选项中在其他开发板管理器地址中填入https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json,再去开发板管理器界面中找到ESP32,点击安装后才能使用ESP32系列单片机。注意要联网才能安装。

  • 用作延时相机

    #include "esp_camera.h"
    #include "FS.h"                // SD Card ESP32
    #include "SD_MMC.h"            // SD Card ESP32
    #include "soc/soc.h"           // Disable brownout problems
    #include "soc/rtc_cntl_reg.h"  // Disable brownout problems
    #include "driver/rtc_io.h"
    #include <WiFi.h>
    #include "time.h"
    
    
    // REPLACE WITH YOUR NETWORK CREDENTIALS
    const char* ssid = "XXXXXX";
    const char* password = "XXXXXX";
    
    
    // REPLACE WITH YOUR TIMEZONE STRING: https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv
    String myTimezone ="CST-8";
    
    
    // Pin definition for CAMERA_MODEL_AI_THINKER
    // Change pin definition if you're using another ESP32 camera module
    #define PWDN_GPIO_NUM     32
    #define RESET_GPIO_NUM    -1
    #define XCLK_GPIO_NUM      0
    #define SIOD_GPIO_NUM     26
    #define SIOC_GPIO_NUM     27
    #define Y9_GPIO_NUM       35
    #define Y8_GPIO_NUM       34
    #define Y7_GPIO_NUM       39
    #define Y6_GPIO_NUM       36
    #define Y5_GPIO_NUM       21
    #define Y4_GPIO_NUM       19
    #define Y3_GPIO_NUM       18
    #define Y2_GPIO_NUM        5
    #define VSYNC_GPIO_NUM    25
    #define HREF_GPIO_NUM     23
    #define PCLK_GPIO_NUM     22
    
    
    // Stores the camera configuration parameters
    camera_config_t config;
    
    
    // Initializes the camera
    void configInitCamera(){
    config.ledc_channel = LEDC_CHANNEL_0;
    config.ledc_timer = LEDC_TIMER_0;
    config.pin_d0 = Y2_GPIO_NUM;
    config.pin_d1 = Y3_GPIO_NUM;
    config.pin_d2 = Y4_GPIO_NUM;
    config.pin_d3 = Y5_GPIO_NUM;
    config.pin_d4 = Y6_GPIO_NUM;
    config.pin_d5 = Y7_GPIO_NUM;
    config.pin_d6 = Y8_GPIO_NUM;
    config.pin_d7 = Y9_GPIO_NUM;
    config.pin_xclk = XCLK_GPIO_NUM;
    config.pin_pclk = PCLK_GPIO_NUM;
    config.pin_vsync = VSYNC_GPIO_NUM;
    config.pin_href = HREF_GPIO_NUM;
    config.pin_sscb_sda = SIOD_GPIO_NUM;
    config.pin_sscb_scl = SIOC_GPIO_NUM;
    config.pin_pwdn = PWDN_GPIO_NUM;
    config.pin_reset = RESET_GPIO_NUM;
    config.xclk_freq_hz = 20000000;
    config.pixel_format = PIXFORMAT_JPEG; //YUV422,GRAYSCALE,RGB565,JPEG
    config.grab_mode = CAMERA_GRAB_LATEST;
    
    
    // Select lower framesize if the camera doesn't support PSRAM
    if(psramFound()){
      config.frame_size = FRAMESIZE_UXGA; // FRAMESIZE_ + QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA
      config.jpeg_quality = 5; //0-63 lower number means higher quality
      config.fb_count = 1;
    } else {
      config.frame_size = FRAMESIZE_UXGA;
      config.jpeg_quality = 5;
      config.fb_count = 1;
    }
    
    // Initialize the Camera
    esp_err_t err = esp_camera_init(&config);
    if (err != ESP_OK) {
      Serial.printf("Camera init failed with error 0x%x", err);
      return;
    }
    }
    
    
    // Connect to wifi
    void  initWiFi(){
    WiFi.begin(ssid, password);
    Serial.println("Connecting Wifi");
    while (WiFi.status() != WL_CONNECTED) {
      Serial.print(".");
      delay(500);
    }
    }
    
    
    // Function to set timezone
    void setTimezone(String timezone){
    Serial.printf("  Setting Timezone to %s\n",timezone.c_str());
    setenv("TZ",timezone.c_str(),1);  //  Now adjust the TZ.  Clock settings are adjusted to show the new local time
    tzset();
    }
    
    
    // Connect to NTP server and adjust timezone
    void initTime(String timezone){
    struct tm timeinfo;
    Serial.println("Setting up time");
    configTime(0, 0, "pool.ntp.org");    // First connect to NTP server, with 0 TZ offset
    if(!getLocalTime(&timeinfo)){
      Serial.println(" Failed to obtain time");
      return;
    }
    Serial.println("Got the time from NTP");
    // Now we can set the real timezone
    setTimezone(timezone);
    }
    
    
    // Get the picture filename based on the current ime
    String getPictureFilename(){
    struct tm timeinfo;
    if(!getLocalTime(&timeinfo)){
      Serial.println("Failed to obtain time");
      return "";
    }
    char timeString[20];
    strftime(timeString, sizeof(timeString), "%Y-%m-%d_%H-%M-%S", &timeinfo);
    Serial.println(timeString);
    String filename = "/picture_" + String(timeString) +".jpg";
    return filename; 
    }
    
    
    // Initialize the micro SD card
    void initMicroSDCard(){
    // Start Micro SD card
    Serial.println("Starting SD Card");
    if(!SD_MMC.begin()){
      Serial.println("SD Card Mount Failed");
      return;
    }
    uint8_t cardType = SD_MMC.cardType();
    if(cardType == CARD_NONE){
      Serial.println("No SD Card attached");
      return;
    }
    }
    
    
    // Take photo and save to microSD card
    void takeSavePhoto(){
    // Take Picture with Camera
    camera_fb_t * fb = esp_camera_fb_get();
    
    //Uncomment the following lines if you're getting old pictures
    //esp_camera_fb_return(fb); // dispose the buffered image
    //fb = NULL; // reset to capture errors
    //fb = esp_camera_fb_get();
    
    if(!fb) {
      Serial.println("Camera capture failed");
      delay(1000);
      ESP.restart();
    }
    
    
    // Path where new picture will be saved in SD Card
    String path = getPictureFilename();
    Serial.printf("Picture file name: %s\n", path.c_str());
    
    // Save picture to microSD card
    fs::FS &fs = SD_MMC; 
    File file = fs.open(path.c_str(),FILE_WRITE);
    if(!file){
      Serial.printf("Failed to open file in writing mode");
    } 
    else {
      file.write(fb->buf, fb->len); // payload (image), payload length
      Serial.printf("Saved: %s\n", path.c_str());
    }
    file.close();
    esp_camera_fb_return(fb); 
    }
    
    
    void setup() {
    WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); // disable brownout detector
    
    
    Serial.begin(115200);
    delay(2000);
    
    
    // Initialize Wi-Fi
    initWiFi();
    // Initialize time with timezone
    initTime(myTimezone);    
    // Initialize the camera  
    Serial.print("Initializing the camera module...");
    configInitCamera();
    Serial.println("Ok!");
    // Initialize MicroSD
    Serial.print("Initializing the MicroSD card module... ");
    initMicroSDCard();
    }
    
    
    void loop() {    
    // Take and Save Photo
    takeSavePhoto();
    delay(60000);
    }

            在程序中修改SSID、PASSWORD,myTimezone设置时区字符串,在https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv中查找到属于当地的时区字符串;config.frame_size设置拍摄分辨率,config.jpeg_quality设置图像质量,0~63,数字越小图像质量越高,但有可能造成图像拍摄出现问题。loop()中delay()函数内是延时时间。
            图像质量实在差劲,最高分辨率UXGA下图像质量设置为0时所拍照片偶有撕裂现象,我一般设置为5。模块上电后按一下reset键,可以确保系统正常工作。

  • 用作网络摄影机

    #include "esp_camera.h"
    #include <WiFi.h>
    
    //
    // WARNING!!! PSRAM IC required for UXGA resolution and high JPEG quality
    //            Ensure ESP32 Wrover Module or other board with PSRAM is selected
    //            Partial images will be transmitted if image exceeds buffer size
    //
    //            You must select partition scheme from the board menu that has at least 3MB APP space.
    //            Face Recognition is DISABLED for ESP32 and ESP32-S2, because it takes up from 15 
    //            seconds to process single frame. Face Detection is ENABLED if PSRAM is enabled as well
    
    // ===================
    // Select camera model
    // ===================
    //#define CAMERA_MODEL_WROVER_KIT // Has PSRAM
    //#define CAMERA_MODEL_ESP_EYE // Has PSRAM
    //#define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM
    //#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM
    //#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM
    //#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM
    //#define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM
    //#define CAMERA_MODEL_M5STACK_UNITCAM // No PSRAM
    #define CAMERA_MODEL_AI_THINKER // Has PSRAM
    //#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM
    //#define CAMERA_MODEL_XIAO_ESP32S3 // Has PSRAM
    // ** Espressif Internal Boards **
    //#define CAMERA_MODEL_ESP32_CAM_BOARD
    //#define CAMERA_MODEL_ESP32S2_CAM_BOARD
    //#define CAMERA_MODEL_ESP32S3_CAM_LCD
    //#define CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3 // Has PSRAM
    //#define CAMERA_MODEL_DFRobot_Romeo_ESP32S3 // Has PSRAM
    #include "camera_pins.h"
    
    // ===========================
    // Enter your WiFi credentials
    // ===========================
    const char* ssid = "XXXXXX";
    const char* password = "XXXXXX";
    
    void startCameraServer();
    void setupLedFlash(int pin);
    
    void setup() {
    Serial.begin(115200);
    Serial.setDebugOutput(true);
    Serial.println();
    
    camera_config_t config;
    config.ledc_channel = LEDC_CHANNEL_0;
    config.ledc_timer = LEDC_TIMER_0;
    config.pin_d0 = Y2_GPIO_NUM;
    config.pin_d1 = Y3_GPIO_NUM;
    config.pin_d2 = Y4_GPIO_NUM;
    config.pin_d3 = Y5_GPIO_NUM;
    config.pin_d4 = Y6_GPIO_NUM;
    config.pin_d5 = Y7_GPIO_NUM;
    config.pin_d6 = Y8_GPIO_NUM;
    config.pin_d7 = Y9_GPIO_NUM;
    config.pin_xclk = XCLK_GPIO_NUM;
    config.pin_pclk = PCLK_GPIO_NUM;
    config.pin_vsync = VSYNC_GPIO_NUM;
    config.pin_href = HREF_GPIO_NUM;
    config.pin_sccb_sda = SIOD_GPIO_NUM;
    config.pin_sccb_scl = SIOC_GPIO_NUM;
    config.pin_pwdn = PWDN_GPIO_NUM;
    config.pin_reset = RESET_GPIO_NUM;
    config.xclk_freq_hz = 20000000;
    config.frame_size = FRAMESIZE_UXGA;
    config.pixel_format = PIXFORMAT_JPEG; // for streaming
    //config.pixel_format = PIXFORMAT_RGB565; // for face detection/recognition
    config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
    config.fb_location = CAMERA_FB_IN_PSRAM;
    config.jpeg_quality = 5;
    config.fb_count = 1;
    
    // if PSRAM IC present, init with UXGA resolution and higher JPEG quality
    //                      for larger pre-allocated frame buffer.
    if(config.pixel_format == PIXFORMAT_JPEG){
      if(psramFound()){
        config.jpeg_quality = 5;
        config.fb_count = 2;
        config.grab_mode = CAMERA_GRAB_LATEST;
      } else {
        // Limit the frame size when PSRAM is not available
        config.frame_size = FRAMESIZE_SVGA;
        config.fb_location = CAMERA_FB_IN_DRAM;
      }
    } else {
      // Best option for face detection/recognition
      config.frame_size = FRAMESIZE_240X240;
    #if CONFIG_IDF_TARGET_ESP32S3
      config.fb_count = 2;
    #endif
    }
    
    #if defined(CAMERA_MODEL_ESP_EYE)
    pinMode(13, INPUT_PULLUP);
    pinMode(14, INPUT_PULLUP);
    #endif
    
    // camera init
    esp_err_t err = esp_camera_init(&config);
    if (err != ESP_OK) {
      Serial.printf("Camera init failed with error 0x%x", err);
      return;
    }
    
    sensor_t * s = esp_camera_sensor_get();
    // initial sensors are flipped vertically and colors are a bit saturated
    if (s->id.PID == OV3660_PID) {
      s->set_vflip(s, 1); // flip it back
      s->set_brightness(s, 1); // up the brightness just a bit
      s->set_saturation(s, -2); // lower the saturation
    }
    // drop down frame size for higher initial frame rate
    if(config.pixel_format == PIXFORMAT_JPEG){
      s->set_framesize(s, FRAMESIZE_QVGA);
    }
    
    #if defined(CAMERA_MODEL_M5STACK_WIDE) || defined(CAMERA_MODEL_M5STACK_ESP32CAM)
    s->set_vflip(s, 1);
    s->set_hmirror(s, 1);
    #endif
    
    #if defined(CAMERA_MODEL_ESP32S3_EYE)
    s->set_vflip(s, 1);
    #endif
    
    // Setup LED FLash if LED pin is defined in camera_pins.h
    #if defined(LED_GPIO_NUM)
    setupLedFlash(LED_GPIO_NUM);
    #endif
    
    WiFi.begin(ssid, password);
    WiFi.setSleep(false);
    
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }
    Serial.println("");
    Serial.println("WiFi connected");
    
    startCameraServer();
    
    Serial.print("Camera Ready! Use 'http://");
    Serial.print(WiFi.localIP());
    Serial.println("' to connect");
    }
    
    void loop() {
    // Do nothing. Everything is done in another task by the web server
    delay(10000);
    }

            在程序中修改SSID、PASSWORD,上传后打开串口监视器,按rst键,看模块IP地址,在浏览器中输入IP地址就进入网络摄像头界面,点Start Stream开始摄像头网络直播。各种参数可以在浏览器界面进行设置。
    esp32-cam.png

  • 人脸检测和人脸识别

            上面网络摄像头界面左边栏有人脸检测和人脸识别功能,把分辨率调整到320*240时可以开启,此时可以自动识别画面中出现的人脸,还可点击enroll face键预存需要识别的人脸。

        本记录将持续更新。

        clockworkpi属于极客玩具,自然不会像一般的消费电子产品那样面面俱到,你要喜欢它的极客属性,就要忍受极客的不便,比如键盘太硬等问题。我完全不同意有的人提出的这东西只是一个玩具完全没法拿来干活的观点,比如domoticz的自定义界面我就是在clockworkpi上安装的vscode上修改调试出来的,键盘太硬对我来说也完全不是问题,但还是有一些影响使用效率的问题,解决了就更加好用,以下就是一些clockworkpi特有的问题和解决方案,记录一下,以免以后忘了。

  • apt update和upgrade失败问题

            apt升级和更新是常规操作,但用所附TF的系统命令行操作时失败,修改源也没有用,发现是raw.githubusercontent.com无法解析导致。尝试了很多办法,有时行有时不行,最后是修改/etc/hosts解决问题,增加如下代码,直接告知这个网址的IP地址:

    151.101.72.249 github.ssl.fastly.net
    192.30.255.112 github.com
    185.199.109.133 raw.githubusercontent.com
    185.199.110.133 raw.githubusercontent.com
    185.199.111.133 raw.githubusercontent.com

            github在这个机器上也是几乎无法访问,把IP地址一并加进去。需要注意的是这些网址的IP地址可能是会变化,如果又连不上了就在网上查一下现在的IP地址,在这个文件里修改过来。修改后要重启dhcp服务。

  • 键盘背光问题

            clockworkpi的uConsole的键盘是有背光的,组装时就可以看到键盘上有LED。但怎么打开一直不得其法,官网上也没有明确说明,搜索后发现是Fn+space键控制开启。每次启动时背光是关闭的,用快捷键可以开启两档背光,但背光不均匀,有的字亮有的字暗,能看清,缺点就是橙色字体部分不透光,不过晚上不开灯使用是足够的。

  • 鼠标左键问题

            uConsole的鼠标设计和一般的笔记本不一样,中部靠右是一个黑莓手机那种微型轨迹球,中部靠左是四个光标间和LR两个键对应鼠标左键右键。轨迹球是可以按下去的,但是在菜单栏按下没有反应,在浏览器中按压链接会在新页面中打开链接,也不知道是怎么设置的。有大神找到了将轨迹球按下改为鼠标左键的办法,很简单,在命令行中输入一条指令即可:

    xinput set-button-map "ClockworkPI uConsole Mouse" 1 1 3 4 5 6 7 8 9 10 11 12

            但是这条命令在关机重启后就失效了,每次重启都要重新输入一遍还是麻烦,尝试过crontab中设置定时任务,没有成功,修改crontab -e和/etc/crontab都没有用,后来用了设置增加开机自启动程序解决的,在.config/autostart子目录下,增加一个比如叫keyboard.desktop文件,输入如下代码:

    [Desktop Entry]
    Type=Application
    Name=keyboard
    Comment=设置轨迹球按压为鼠标左键
    NoDisplay=true
    Exec=/usr/bin/xinput set-button-map "ClockworkPI uConsole Mouse" 1 1 3 4 5 6 7 8 9 10 11 12
    NotShowIn=GNOME;KDE;XFCE;

            这样每次重启就自动设置好了。修改后方便不少,右手可以完成除了鼠标右键的各种操作,左手摆在光标键上可以不动,不用在光标键与鼠标左键之间来回移动。

  • 连接蓝牙耳机问题

            uConsole是有两个内置微型喇叭的,还很精致,但不知道是不是因为组装后壳体没有开孔的缘故,声音很小,100%音量比笔记本30%的音量还小,更比不上手机外放时的音量,看论坛是通病,那就用蓝牙耳机代替喇叭吧,没想到树莓派的蓝牙设置还颇费周折,如此这般才连接成功:
            安装驱动(其实系统是有蓝牙驱动的,可能主要安装蓝牙的图形设置界面吧,用命令行也行,就是麻烦)

    sudo apt install bluetooth pi-bluetooth bluez blueman

            安装后菜单栏上就有一个蓝底白色蓝牙标志的图标,这就是蓝牙配置的GUI,点击后选择设备,打开设备发现界面,然后将蓝牙耳机设置为配对状态,在设备界面中出现后就可以点击完成配对。我的韶音AS800配对后并不能听见声音,播放视频时仍然是内部扬声器发声,要在菜单栏音量图标那里右键点击,选择将声音输出改为韶音耳机后才能听到声音。
            蓝牙耳机连接不算稳定。有时候重启可以自动重连耳机,有时候就连不上,需要进到设备发现界面,让耳机再进入配对状态,选中连接后才能重连。

  • 内置喇叭声音太小问题

            邮件询问clockworkpi官网,内置喇叭声音太小怎么办,回复如下:

    使用系统音量调节可以将音量调到超过100%。
    但是由于扬声器单元功率比较小,因此在非常嘈杂的环境下,建议使用蓝牙或有线耳机。
            但是无论是UI界面还是用alsamixer命令行命令都最多只能将音量调整为100%,搜索说音量要想调整为100%以上要安装音效插件:
    sudo apt install pavucontrol

            安装后在界面里找到pulseAudio音量控制进去,可以将音量调整到最大153%(11DB),声音确实比原来大了很多。
            邮件说的内置扬声器功率太小所以声音小我是不认同的,这两个喇叭任何一个都比手机里的外放扬声器大多了,但是音量却小多了。估计还是没有开孔的缘故。

        本文将不定期更新。

2023年一共看了153本书,下面这些书我很喜欢。

  • 《望向星空深处》
  • 《只讲故事不讲理》
  • 《请教机长:关于航空旅行你应该知道的事》
  • 《奇迹地图》
  • 《当我们不再理解世界》
  • 《这里是中国》
  • 《这里是中国2》
  • 《鱼翅与花椒》
  • 《英国故事》
  • 《寻味东西》
  • 《唐人时代:一部富有烟火气息的唐代生活史》
  • 《直言怪话》
  • 《人类世:务必矛盾和谐的生命笔记》
  • 《Arduino技术内幕》
  • 《太白金星有点烦》
  • 《再忙也要用心生活》
  • 《世说俗谈》
  • 《我们生活在南京》
  • 《12堂极简哲学生活课》
  • 《诸神退位:古希腊的日常》
  • 《古希腊罗马留下来了什么》
  • 《气候变迁与文明兴衰》
  • 《说笑:有效有范的表达技巧》

        骑单车环阳宗海,小红书看这里,路线不长,强度不低,坡度非常大,发夹弯多,需要注意安全。陪伴十多年的公路车头盔完成历史使命,以摔裂告终,迪卡侬900头盔虽轻但夹头,选了500大号。重,但有MIPS。头盔非常重要,无头盔不骑车!
微信图片_20240217082458.jpg

        跑步环草海绿道,小红书看这里海拔爬升很小,但高跷地段路线混乱,需要转到机动车道,绿道还未完成闭环,标志不清,需要注意安全。闷得发慌就去跑LSD,神清气爽。看来不求成绩的话,现在的体力抬腿半马没有任何问题。
微信图片_20240217082509.jpg

        在滇池南岸最美水边公路跑步,从太史村到高海高速入口,过年了反而人少。
微信图片_20240217082516.jpg

        Domoticz的网页显示适合管理,不适合展示数据内容,自定义显示方式十分有必要。Domoticz本身是可以自定义页面的,https://www.domoticz.cn/wiki/%E8%87%AA%E5%AE%9A%E4%B9%89%E7%8A%B6%E6%80%81%E9%A1%B5就讲了如何设置自定义页面的方法,但说得不清不楚,在试验成功的基础上,总结下自定义页面的做法。

        首先找一个喜欢的自定义页面,把页面html代码拷贝出来,比如下面这个:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Domoticz</title> 
<link href="http://fonts.googleapis.com/css?family=Orbitron:700" rel="stylesheet" type="text/css">
<script src="https://cdn.staticfile.org/jquery/1.12.0/jquery.min.js"></script>
<style type="text/css">
div#cnt {
    width: 990px;
    margin: 0 auto;
    text-align: center;
}
a, a:visited { text-decoration: none; color: #336699; }
a:hover { text-decoration: none; color: #003366; }
#frame {
    float: left;
    margin: 0px;
    padding: 0px 2px 0px 2px;
}
#label_lg {
    font-family: arial;
    font-weight: normal;
    color: #999;
    font-size: 17px;
    margin-top: -20px;
    height: 25px;
    line-height: 10px;
}
#itemp {
    font-family: Orbitron, serif;
    font-weight: bold;
    width: 570px;
    padding: 5px;
    border: 1px solid #666;
    height: 217px;    
    line-height: 210px; 
    font-size: 180px;    
    color: darkorange;
    margin: 0px ;
}
#oFloor, #purifier, #uv, #ihum, #astat, #astatw, #otemp, #crte,
#uv, #rain, #ohum, #ocld, #wtxt, #ctime, #brLight, #ctemp, #lrLight, 
#waterHeater, #eHeating, #tmpc, #crte, #whWatt, #wind, #hWatt, 
#cpuTemp, #ram, #space, #cpuUsage {
    font-family: Orbitron, serif;
    font-weight: bold;
    width: 162px;
    padding: 10px;
    border: 1px solid #666;
    height: 90px;
    line-height: 75px;         
    font-size: 90px;
    color: #999;
}
#ctime, #brLight, #lrLight, #waterHeater, #eHeating, #tmpc, #crte, #whWatt, #uv, 
#rain, #ohum, #ocld, #wtxt, #otemp, #wind, #astat, #awatt, 
#astatw, #hWatt, #cpuUsage, #cpuTemp, #ram, #space {
    height: 65px;
    line-height: 55px;
    color: #999;
}
#hWatt, #cpuUsage, #crte, #wind { 
    width: 184px; 
}
#wtxt { 
    width: 560px; 
    font-size: 40px;
    line-height: 55px;
    color: darkorange;
}
#al { 
    margin-left: -35px; 
    margin-top: 55px; 
    width: 1050px;height: 570px;    
}
</style>
</head>
<div id="images"></div>
<body bgcolor="#000">
<div id="cnt">
<div style="margin-bottom:5px;">
<div>
<div>
<div id="frame">
    <div id="ihum" style="color:lightblue;font-size:50px;">--</div>
    <div id="label_lg">室内湿度 (%)</div>
    <div id="purifier" style="font-size:35px;">--</div>
    <div id="label_lg">空气净化器</div>
</div>
<div id="frame">
    <div id="itemp">--</div>
    <div id="label_lg" style="font-size:25px;margin-top:-30px;">卧室温度 (º<span class="degsign">C</span>)</div>
</div>
<div id="frame">
    <div id="oFloor" style="color:teal;font-size:50px;">--</div>
    <div id="label_lg">一楼温度 (º<span class="degsign">C</span>)</div>
    <div id="ctemp" style="color:#6666FF;font-size:50px;">--</div>
    <div id="label_lg">地下室温度 (º<span class="degsign">C</span>)</div>
</div>
</div>
<div>
<div id="frame">
    <div id="brLight" style="font-size:40px;">--</div>
    <div id="label_lg">卧室灯</div>
</div>
<div id="frame">
    <div id="lrLight" style="font-size:40px;">--</div>
    <div id="label_lg">客厅灯</div>
</div>
<div id="frame">
    <div id="eHeating" style="font-size:40px;">--</div>
    <div id="label_lg">电暖气</div>
</div>
<div id="frame">
    <div id="hWatt" style="font-size:40px;">--</div>
    <div id="label_lg">电暖气功率</div>
</div>
<div id="frame">
    <div id="waterHeater" style="font-size:40px;">--</div>
    <div id="label_lg">热水器</div>
</div>
</div>
<div>
<div id="frame">
    <div id="space" style="font-size:40px;;color:#3333cc;">--</div>
    <div id="label_lg">硬盘占用</div>
</div>
<div id="frame">
    <div id="ram" style="font-size:40px;color:#009933;">--</div>
    <div id="label_lg">内存占用</div>
</div>
<div id="frame">
    <div id="cpuUsage" style="font-size:40px;color:#ff3333;">--</div>
    <div id="label_lg">CPU使用率</div>
</div>
<div id="frame">
    <div id="cpuTemp" style="font-size:40px;color:#ff3333;">--</div>
    <div id="label_lg">CPU温度 (º<span class="degsign">C</span>)</div>
</div>
<div id="frame">
    <div id="whWatt" style="font-size:40px;color:#ff3333;">--</div>
    <div id="label_lg">热水器功率</div>
</div>
</div>
<div>
<div id="frame">
    <div id="rain" style="font-size:40px;">--</div>
    <div id="label_lg">日降雨量 (MM)</div>
</div>
<div id="frame">
    <div id="uv" style="font-size:40px;color:#C34A2C;">--</div>
    <div id="label_lg">紫外线指数 (UVI)</div>
</div>
<div id="frame">
    <div id="wind" style="font-size:40px;">--</div>
    <div id="label_lg">风速 (<span class="windsign">km/h</span>)</div>
</div>
<div id="frame">
    <div id="otemp" style="font-size:40px;color:darkorange;">--</div>
    <div id="label_lg">户外温度 (º<span class="degsign">C</span>)</div>
</div>
<div id="frame">
    <div id="ohum" style="font-size:40px;color:teal;">--</div>
    <div id="label_lg">户外湿度 (%)</div>
</div>
</div>
<div>
<div id="frame">
    <div id="astat" style="font-size:40px;">--</div>
    <div id="label_lg">净化器功率</div>
</div>
<div id="frame">
    <div id="wtxt">--</div>
    <div id="label_lg">天气</div>
</div>
<div id="frame">
    <div id="astatw" style="font-size:40px;">--</div>
    <div id="label_lg">气压 (hPa)</div>
</div>
</div>
</div>
<div id="all"></div><br>
</div>
</div>
<script type="text/javascript" charset="utf-8">
$.roomplan=0;
$.domoticzurl="http://127.0.0.1:8080";
function RefreshData(){
    clearInterval($.refreshTimer);
    var jurl=$.domoticzurl+"/json.htm?type=devices&plan="+$.roomplan+"&jsoncallback=?";
    $.getJSON(jurl,
        {
            format: "json"
        },
        function(data) {
            if (typeof data.result != 'undefined') {
                if (typeof data.WindSign != 'undefined') {
                    $('.windsign').html(data.WindSign);
                }
                if (typeof data.TempSign != 'undefined') {
                    $('.degsign').html(data.TempSign);
                }
                $.each(data.result, function(i,item){
                    for( var ii = 0, len = $.PageArray.length; ii < len; ii++ ) {
                        if( $.PageArray[ii][0] === item.idx ) {
                            var vtype=$.PageArray[ii][1];
                            var vlabel=$.PageArray[ii][2];
                            var vdata=item[vtype];
                            if (typeof vdata == 'undefined') {
                                vdata="??";
                            }
                            else {
                                vdata=new String(vdata).split(" ",1)[0];
                            }
                            $('#'+vlabel).html(vdata);
                        }
                    }
                });
            }
        });
    $.refreshTimer = setInterval(RefreshData, 10000);
}
$(document).ready(function() {
    $.PageArray = [
        //格式: idx, value, label, comment
        ['19','Temp','itemp','woonkamer'],        //卧室温度
        ['0','Humidity','ihum','woonkamer'],    //室内湿度
        ['4','Barometer','astatw','woonkamer'],    //气压
        ['9','ForecastStr','wtxt','woonkamer'],    //天气
        ['4','Temp','otemp','buiten'],            //户外温度
        ['17','Humidity','ohum','buiten'],        //户外湿度
        ['0','Temp','oFloor','room setpoint'],    //一楼温度
        ['15','Data','cpuTemp','cputemp'],        //CPU温度
        ['16','Data','cpuUsage','cpuusage'],    //CPU占用
        ['7','Rain','rain','rain'],                //降雨量
        ['12','Data','ram','ram'],                //内存占用
        ['6','UVI','uv','uv'],                    //紫外线
        ['8','Data','wind','wind'],                //风速
        ['2','Status','brLight','light'],        //卧室灯
        ['3','Status','lrLight','light'],        //客厅灯
        ['14','Data','space','HardDriver']        //硬盘占用
    ];
    RefreshData();
});  
</script>
</body>
</html>

        修改html当中的一些参数:

        首先修改房间号:设置了多个房间的下面改为对应的编号,跨多个房间的数据要显示的,选择0

$.roomplan=0;

        其次改domoticz地址,在内网部署的话,一般是

$.domoticzurl="http://192.168.1.XXX:8080";

        然后观察图片
Frontpage.jpg
中各个数据显示块的内容,把对应位置的名称改为自己想要展示的数据名称

<div id="label_lg">室内湿度 (%)</div>

        数据命名行中的id记清楚,然后到$.PageArray中修改或加入对应的JSON格式数据

['19','Temp','itemp','woonkamer'],        //卧室温度

        第一个单引号内是domoticz中相关硬件设备的idx,第二个单引号内是对应硬件设备反馈JSON数据中要显示哪个栏目的内容,第三个单引号内是对应数据命名行中的id,第四个单引号内是描述,可以不用管它。每个要显示的数据栏需要有这么一行数据。

        其中容易出问题的是第二个单引号的填写内容,如果错误或没有对应栏目,数据处会显示??。用http://192.168.1.XXX:8080/json.htm?type=devices&plan=0来看所有设备的状态数据,找到对应idx设备的数据,在{}之间的json数据中找到要展示的栏目,把栏目名称填进去。对传感器而言,温度一般是Temp,湿度一般是Humidity,气压一般是Barometer,其他自己定义的传感器如果没有具体的栏目可以填写Data。开关状态显示填Status。

        这个html文件修改调试好后,比如叫a.html,把它移动到/home/pi/domoticz/www/views目录下,这样在浏览器中输入网址http://192.168.1.XXX:8080/views/a.html就可以在浏览器中显示自定义页面内容了。我调整过的页面如下:
domoticz自定义页面.png

可以设置开机自动显示,在终端界面中输入指令:

cd /home/pi/.config/
mkdir autostart
cd /autostart
sudo nano my.desktop

输入如下指令:

[Desktop Entry]
Type=Application
Exec=chromium-browser  --disable-popup-blocking --no-first-run --disable-desktop-notifications  --kiosk "http://192.168.1.XXX:8080/views/a.html"

重启生效。因为是全屏模式,遮蔽了菜单界面等,如要退出按Alt+F4。

为了实现内网穿透,几年前买了一个花生壳盒子,能用,慢,不另外花钱只能用两个链接,虽然很不满意,因为还能用,也就将就着用下来了。

然后半年前忽然就无法访问了,进到官网一看,修改了协议,要补充这个那个,补充完了还是不行,逼着我付费?不惯它,宁可不用。但是不用还是不方便,网上查了一圈,用ddns-go可以实现内网穿透,IPV6真正派上用场,原来我以为的IPV6光打雷不下雨是我错怪了它。这个方法不用额外花钱,速度极快,而且能够穿透的设备数和端口数没有限制,让那些付费的工具见鬼去吧!

先注册一个域名;
在域名服务商那里申请API,获得ID和TOKEN;
树莓派上部署:
安装docker:
sudo curl -sSL https://get.docker.com | sh
检查是否安装正确:
docker -v
设置开机自启动docker:
sudo systemctl enable docker
拉取图形界面镜像:
sudo docker pull portainer/portainer-ce
创建相关卷:
sudo docker volume create portainer_data
启动图形界面容器:
sudo docker run -d -p 9000:9000 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce
拉取ddns-go镜像:
sudo docker pull jeessy/ddns-go
启动ddns-go容器:
sudo docker run -d --name ddns-go --restart=always --net=host -p 192.168.1.XXX:9876:9876 jeessy/ddns-go -l :9876 -f 1400
进入界面设置:
192.168.1.XXX:9876
填写dnspod,ID,token,选择IPV6,通过网卡获取地址,240X为公网IPV6地址,填写域名,访问:域名:XXXX(根据你的应用而定)

避坑指南:一个API只能对应一台硬件,因为它是解析该硬件的公网IPV6地址,如果内网有多个设备需要穿透,需要申请多个API,一一对应才能成功,一个硬件设置后,该硬件上所有端口都可以使用,比如用22进行SSH等。

        clockworkpi是一家中国公司生产的可以独立运行的树莓派掌上电脑,集成了CM4核心卡,一块720P的屏幕,一个全键盘,以及微型轨迹球,两节18650电池等,工业朋克风的设计风格让人爱不释手。一直想用树莓派做个微型电脑,用来学习linux和对家里的诸多树莓派进行一些命令行的操作,然而工作量不是一般的大,合适的屏幕和配件就很难找到,而这种东西一旦凑合用了通用的配件,一下子格调就降下来了,变成手工耿那样的手工粗糙DIY了。clockworkpi设计很不错,外壳框架都是铝合金CNC出来的,看得出来成本不低,虽然块头大但考虑了人体工学设计,双手端着操作熟练了倒也相当舒服。不枉我等了八个月啊!
微信图片_20240209124339.jpg

        疫情过后,云南星空大会终于回来。还是在抚仙湖星空小镇,加入了云南省中小学天文知识竞赛的决赛和颁奖环节,比往常更累了。好的一方面是协会在抚仙湖星空小镇体验店重新选址装修开张,几百平米两层加一个夹层,望远镜等器材有了摆放的地方且推出去就可以在廊桥上观测,胶囊仓可以住宿,还有一台辣妈咖啡机可以自己做咖啡......我已经将多数望远镜存放在此,家里只留两只折射镜和一台小赤道仪。回归目视,回归初心。

微信图片_20240209102658.jpg
微信图片_20240209102710.jpg
微信图片_20240209102717.jpg
微信图片_20240209102723.jpg
微信图片_20240209102729.jpg
微信图片_20240209102734.jpg
微信图片_20240209102739.jpg
微信图片_20240209102744.jpg
微信图片_20240209104727.jpg

        2023年12月,实在累得头昏眼花了,于是请了公休一个人开车去了怒江。怒江是一直想去的地方,很好奇为什么一个地方会以一条愤怒的江水命名?再加上知子罗,我从来都对废城有一种执着和渴望,站在废城中遥想以前的热闹与辉煌,是一种难以言表的体验与感受。那么我喜欢怒江吗?非常喜欢,小红书看这里怒江印象

        怒江的风景,是你把车停在路边,站在江边就可以看很久那种风景。经常有人问我哪里好玩,我总要反问他你想玩什么,你对什么感兴趣,一道风景对上了不感兴趣的人,就是一句不好玩和一个不高兴。所以旅游本身是很自我的事情,我感兴趣的别人不一定感兴趣,我想驻足观望的别人可能急着要走,所以和别人分享风景不是不可能,而是要找对人。不必期待别人与你同频共振,自己喜欢就好。

        旅游为什么?为了看到和平时不一样的风景。如果你能够放慢脚步,走进平日匆匆路过的街巷,仔细看每一棵树,每一朵花,每座建筑和每个小店,那平素平淡的生活也就有了旅游的兴味。旅游看什么?看自己想看的,也许是风景,也许是古迹,也许是市井风情,你想看的不必与别人一样。
微信图片_20240209102759.jpg