如何转播电视信号并通过网页观看

前几天给大家简单介绍了一下如何使用树莓派搭建一个RTMP直播服务,并可以通过vlc等工具观看。这几天,我又改进了一下整个系统,现在可以通过网页观看直播,并通过MQTT服务控制一个Arduino发送红外信号,控制机顶盒。

现在,整套系统有这么几个东西。

  • 机顶盒
    • 通过网络接受直播信号
  • 采集卡
    • 采集机顶盒信号,并推送给PC
  • PC
    • 接受来自采集卡的信号,并推送给RTMP直播服务
  • 树莓派
    • RTMP服务,接收并转发视频信号
    • MMQT服务,通过网络发送信息给Arduino
    • PHP服务,通过网页收看直播,发送MMQT信息
  • Ardunio
    • 接收MMQT的信息,并根据信息发送红外信号控制机顶盒

机顶盒,采集卡,PC方面的事情就不详细说了,今天主要说一下树莓派和Ardunio的东西。

树莓派方面,还是给大家写了一个script,大家修改后可以直接运行。我也加了一些comment在里面。注意替换<your ip>, <your port>, <your service>之类的位置,运行之前记得搜一下有没有“<your”开头的地方,还有没有没有替换的

#!/bin/bash

# Raspberry Pi 5 RTMP Streaming Server Setup Script
# Installs NGINX with RTMP, configures HLS, and sets up systemd service
# Installs PHP and MMQT service

set -e

echo "🚀 Updating system..."
apt update && apt upgrade -y

echo "📦 Installing dependencies..."
apt install -y build-essential libpcre3 libpcre3-dev libssl-dev zlib1g-dev git wget


echo "📦 Installing mosquitto and mosquitto-clients..."
apt install -y mosquitto mosquitto-clients

echo "🔁 Enabling and starting mosquitto service..."
systemctl enable mosquitto
systemctl start mosquitto

echo "⚙️  Configuring Mosquitto for WebSockets..."
MOSQ_CONF="/etc/mosquitto/mosquitto.conf"

# Backup original config
cp $MOSQ_CONF ${MOSQ_CONF}.bak

cat <<EOF > $MOSQ_CONF
# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

pid_file /run/mosquitto/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d

# MQTT listener
listener 1883
protocol mqtt

# WebSocket listener
listener 9001
protocol websockets

allow_anonymous true

# Optional authentication (uncomment below to enable)
# allow_anonymous false
# password_file /etc/mosquitto/passwd
EOF

echo "🔁 Restarting Mosquitto..."
systemctl restart mosquitto

echo "📦 Installing PHP and FPM..."
apt install -y php php-fpm php-cli

echo "✅ Ensuring PHP-FPM is running..."
# Double check the version of php
systemctl enable php8.2-fpm
systemctl start php8.2-fpm

echo "🌐 Downloading NGINX and RTMP module..."
cd /opt
git clone https://github.com/arut/nginx-rtmp-module.git
wget http://nginx.org/download/nginx-1.27.5.tar.gz
tar -zxvf nginx-1.27.5.tar.gz
cd nginx-1.27.5

echo "⚙️ Building NGINX with RTMP module..."
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module
make -j$(nproc)
make install

echo "📝 Writing NGINX config with RTMP + HLS..."
cat > /usr/local/nginx/conf/nginx.conf <<'EOF'
user www-data;
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    sendfile off;
    tcp_nopush on;
    directio 512;

    server {
        listen <your port>;
        root html;
    index index.php index.html index.htm;
        location / {
            try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;  # Update based on your PHP version
        }

        location /hls {
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            root /tmp;
            add_header Cache-Control no-cache;
            add_header 'Access-Control-Allow-Origin' '*';
        }

    }
}

rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application <your service> {
            live on;
            record off;
            hls on;
            hls_path /tmp/hls;
            hls_fragment 3s;
            hls_playlist_length 60s;
        }
    }
}
EOF

echo "📁 Creating HLS output directory..."
mkdir -p /tmp/hls

echo "🔧 Creating systemd service for NGINX RTMP..."
cat > /etc/systemd/system/nginx-rtmp.service <<EOF
[Unit]
Description=NGINX RTMP Streaming Server
After=network.target

[Service]
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PIDFile=/usr/local/nginx/logs/nginx.pid
Type=forking
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

echo "🔁 Enabling and starting NGINX service..."
systemctl daemon-reexec
systemctl daemon-reload
systemctl enable nginx-rtmp
systemctl start nginx-rtmp


echo "📄 Creating MQTT PHP script..."
cat > /usr/local/nginx/html/send.php <<'EOF'
<?php
// Simple security token (optional)
$secret = $_POST['key'] ?? '';
if ($secret !== '<your key2>') {
    http_response_code(403);
    echo json_encode(['error' => 'Unauthorized']);
    exit;
}

$msg = $_POST['msg'] ?? '';

// Publish to Mosquitto
$cmd = escapeshellcmd("mosquitto_pub -h localhost -t 'tv/remote' -m '$msg'");
exec($cmd, $output, $retval);

echo json_encode([
    'status' => $retval === 0 ? 'sent' : 'error',
    'msg' => $msg
]);
?>
EOF

cat > /usr/local/nginx/html/index.php <<'EOF'
<?php
$key = $_GET['key'] ?? '';
if ($key !== '<your key1>') {
    http_response_code(403);
    echo json_encode(['error' => 'Unauthorized']);
    exit;
}
$channels = [
    '体育频道' => [
        ['msg' => 's00720', 'name' => '纬来体育'],
        ['msg' => 's00721', 'name' => '纬来体育 备用'],
        ['msg' => 's01420', 'name' => 'ELTA体育1'],
        ['msg' => 's01421', 'name' => 'ELTA体育1 备用'],
        ['msg' => 's01430', 'name' => 'ELTA体育2'],
        ['msg' => 's01431', 'name' => 'ELTA体育2 备用'],
        ['msg' => 's01440', 'name' => 'ELTA体育3'],
        ['msg' => 's01441', 'name' => 'ELTA体育3 备用1'],
        ['msg' => 's01442', 'name' => 'ELTA体育3 备用2'],
        ['msg' => 's01450', 'name' => 'ELTA体育4'],
        ['msg' => 's01451', 'name' => 'ELTA体育4 备用'],
    ],
    'Reboot' => [
        ['msg' => 'r', 'name' => 'Reboot TV Box'],
        ['msg' => 'a', 'name' => 'Reboot TV App']
    ]
];

$secretKey = '<your key2>';
$streamKey = '<your stream key>';
?>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TV Streaming Panel</title>
    <style>
        body {
            margin: 0;
            font-family: "Segoe UI", sans-serif;
            background: #1c1c1c;
            color: white;
            display: flex;
            flex-direction: row;
            height: 100vh;
        }

        #player-container {
            flex: 1;
            background: black;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        video {
            width: 100%;
            height: 100%;
            background: black;
        }

        #sidebar {
            width: 300px;
            background: #2b2b2b;
            border-left: 2px solid #444;
            overflow-y: auto;
            padding: 20px;
            box-shadow: -2px 0 10px rgba(0,0,0,0.5);
            transition: width 0.3s ease;
        }

        h2 {
            font-size: 20px;
            color: #00bfff;
            margin: 0 0 10px;
        }

        .category {
            margin-bottom: 10px;
        }

        .category-header {
            font-size: 16px;
            font-weight: bold;
            cursor: pointer;
            padding: 8px;
            background-color: #333;
            border-radius: 4px;
            user-select: none;
        }

        .category-header .arrow {
            display: inline-block;
            width: 1.2em;
        }

        .channel-list {
            display: none;
            margin-top: 5px;
            margin-left: 10px;
        }

        .channel-btn {
            display: block;
            width: 100%;
            margin: 6px 0;
            padding: 10px;
            background: #00bfff;
            color: #fff;
            border: none;
            border-radius: 6px;
            font-size: 14px;
            cursor: pointer;
            text-align: left;
        }

        .channel-btn:hover {
            background: #0099cc;
        }

        .status {
            margin-top: 20px;
            font-size: 14px;
            color: #ccc;
        }

        /* 📱 Responsive styles */
        @media screen and (max-width: 768px) {
            body {
                flex-direction: column;
            }

            #sidebar {
                width: 100%;
                border-left: none;
                border-top: 2px solid #444;
                padding: 10px;
            }

            h2 {
                font-size: 18px;
            }

            .channel-btn {
                font-size: 16px;
                padding: 12px;
            }

            .category-header {
                font-size: 18px;
                padding: 10px;
            }
        }
    </style>
</head>
<body>

<div id="player-container">
    <video id="video" controls autoplay muted></video>
</div>

<div id="sidebar">
    <h2>Channel List</h2>

    <?php foreach ($channels as $category => $items): ?>
        <div class="category">
            <div class="category-header" onclick="toggleCategory(this)">
                <span class="arrow">▶</span> <?php echo htmlspecialchars($category); ?>
            </div>
            <div class="channel-list">
                <?php foreach ($items as $channel): ?>
                    <button class="channel-btn" onclick="changeChannel('<?php echo $channel['msg']; ?>')">
                        <?php echo htmlspecialchars($channel['name']); ?>
                    </button>
                <?php endforeach; ?>
            </div>
        </div>
    <?php endforeach; ?>

    <div class="status" id="status">Status: Ready</div>
</div>

<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<script>
    const streamKey = "<?php echo $streamKey; ?>";
    const secretKey = "<?php echo $secretKey; ?>";
    const video = document.getElementById('video');
    const statusBox = document.getElementById('status');
    const src = 'http://<your ip>:<your port>/hls/' + streamKey + '.m3u8';

    if (Hls.isSupported()) {
        const hls = new Hls();
        hls.loadSource(src);
        hls.attachMedia(video);
    } else if (video.canPlayType('application/vnd.apple.mpegurl')) {
        video.src = src;
    }

    function changeChannel(msg) {
        statusBox.textContent = "Sending msg: " + msg + "...";

        fetch('send.php', {
            method: 'POST',
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
            body: new URLSearchParams({
                msg: msg,
                key: secretKey
            })
        })
        .then(res => res.json())
        .then(data => {
            if (data.status === 'sent') {
                statusBox.textContent = "✅ Msg sent: " + msg;
            } else {
                statusBox.textContent = "❌ Failed: " + (data.error || 'Unknown error');
            }
        })
        .catch(err => {
            statusBox.textContent = "❌ Network error: " + err.message;
        });
    }

    function toggleCategory(header) {
        const list = header.nextElementSibling;
        const arrow = header.querySelector('.arrow');
        const open = list.style.display === 'block';

        list.style.display = open ? 'none' : 'block';
        arrow.textContent = open ? '▶' : '▼';
    }

    // Auto-expand the first category on load
    document.addEventListener("DOMContentLoaded", () => {
        const firstHeader = document.querySelector(".category-header");
        if (firstHeader) toggleCategory(firstHeader);
    });
</script>

</body>
</html>
EOF

echo ""
echo "✅ All done!"
echo ""
echo "🎥 Set OBS to stream to: rtmp://<your ip>/<your service>/<your stream key>"
echo "📺 Watch via VLC or player: rtmp://<your ip>/<your service>/<your stream key>"
echo "🌐 Or in browser (HLS): http://<your ip>:<your port>/hls/<your stream key>.m3u8"
echo "✅ Setup complete. Visit http://<your ip>:<your port>/index.php?key=<your key1> to test."

总体来讲,这个script会安装nginx,并且设置php,rtmp,mmqt服务。并通过一个简单的网页实现从网页上观看直播信号,并通过mmqt发送一些信息出去。不过网页的安全性不是很高,基本授权是通过get发送一个密码,并检查这个强密码和script里hard code的密码一样不一样。另外一个事就是,因为网页端使用的HLS服务,会有大概30秒的延迟。如果用VLC直接观看rtmp信号的话,延迟会小很多。

Ardunio方面,要做两件事,第一件事是通过IR receiver来学习遥控器的信号。

#include <IRremote.h>

void setup() {
  Serial.begin(9600);
  IrReceiver.begin(8, ENABLE_LED_FEEDBACK); // Receiver connected to pin 8
  Serial.println("Ready to receive IR signal...");
}

void loop() {
  if (IrReceiver.decode()) {
    // Print full raw dump for replay later
    IrReceiver.printIRResultShort(&Serial);
    IrReceiver.printIRSendUsage(&Serial);
    Serial.println();
    IrReceiver.resume(); // Ready to receive the next
  }
}

首先,我是把接收器安装在了Ardunio的8号接口,这时,就可以用这个接收器看遥控器发出来的信号是什么了。比如,当我按确认键,就会收到一下信息

Protocol=NEC Address=0xFF40 Command=0xD Raw-Data=0xF20DFF40 32 bits LSB first Gap=1940000us Duration=68650us
	Send with: IrSender.sendNEC(0xFF40, 0xD, <numberOfRepeats>);

这时我们就知道,可以发送什么样的信号了。当学习完所有的需要按的信号后,就可以进入下一步。简单来说,就是连接WIFI(我用的Arduino 4 withi wifi),然后连接MMQT的服务(搭设在树莓派上的)。通过MMQT接收到什么信息,就解析出来,并执行相应的操作。比如我这里,s开头的信息,表示要选台,他会输入台号,并执行一些其他的操作。如果收到r,表示重启机顶盒,他会模拟遥控器的几次操作。这边可能就不能直接抄了,需要你自己修改一下。另外,当发送什么按键的时候,Arduino的灯就会亮起一个相应的数字或者按键,方便我知道发送的啥信号。

#include "Arduino_LED_Matrix.h"
#include <IRremote.h>
#include <PubSubClient.h>
#include "WiFiS3.h"
#include "secrets.h" 

ArduinoLEDMatrix matrix;
char ssid[] = <your wifi ssid>;        // your network SSID (name)
char pass[] = <your wifi pwd>;    // your network password (use for WPA)
int status = WL_IDLE_STATUS;

// MQTT broker settings
const char* mqtt_server = "<your ip>"; // your Raspberry Pi IP address
const int mqtt_port = 1883;
const char* mqtt_topic = "tv/remote";

WiFiClient wifiClient;
PubSubClient client(wifiClient);

void setup() {
  Serial.begin(9600);      // initialize serial communication

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to Network named: ");
    Serial.println(ssid);                   // print the network name (SSID);

    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
  }
  printWifiStatus();                        // you're connected now, so print out the status
  
  client.setServer(mqtt_server, mqtt_port);
  client.setCallback(callback);

  matrix.begin();
  IrSender.begin(7); // Transmitter LED connected to pin 7
}

void loop() {
  // Reconnect Wi-Fi if disconnected
  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("WiFi disconnected. Attempting reconnection...");
    while (WiFi.status() != WL_CONNECTED) {
      status = WiFi.begin(ssid, pass);
      delay(10000); // Wait for connection
    }
    printWifiStatus(); // Print new status once connected
  }

  // Reconnect MQTT if needed
  if (!client.connected()) {
    reconnect();
  }
  client.loop();
}

void callback(char* topic, byte* message, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("]: ");
  for (int i = 0; i < length; i++) {
    Serial.print((char)message[i]);
  }
  Serial.println();

  execute(String((char*)message));
}

void reconnect() {
  unsigned long startAttemptTime = millis();
  
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    if (client.connect("arduinoClient")) {
      Serial.println("connected");
      client.subscribe(mqtt_topic);
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      delay(2000);

      // Timeout after 30 seconds
      if (millis() - startAttemptTime > 30000) {
        Serial.println("MQTT reconnect timeout");
        break;
      }
    }
  }
}

void execute(String message) {
  char c = message[0];
  int i;
  int j;
  int num;
  switch(c) {
    case 's': // channel selection
      for (i = 1; i < message.length(); i++) {
        c = message[i];
        if (i < 5) { // channel number, 4 digits
          sendSignal(c);
          delay(500);
        }
        if (i == 5) { // process the last digit
          sendSignal('o'); // press ok
          num = c - '0'; // convert char to int
          delay(3000);
          for (j = 0; j < num; j++) {
            sendSignal('d'); // press 'down' based on the last digit
            delay(500);
          }
          if (num > 0) { // if 'down' is pressed, press 'ok'
            sendSignal('o');
          } else {
            sendSignal('b'); // close menu
          }
        }
      }
      break;
    case 'r': // restart tv box
      sendSignal('p'); // open power menu
      delay(1000);
      sendSignal('d'); // press down
      delay(1000);
      sendSignal('d'); // select reboot
      delay(1000);
      sendSignal('o'); // reboot
      delay(45000);
      sendSignal('o');
      delay(2000);
      sendSignal('r');
      delay(1000);
      sendSignal('r');
      delay(1000);
      sendSignal('o'); // select tv app
      delay(1000);
      sendSignal('o'); // enter tv app
      delay(10000);
      sendSignal('b'); // enter tv
      break;
    case 'a': // restart tv app
      sendSignal('b'); // back
      delay(1000);
      sendSignal('u'); // select quit
      delay(1000);
      sendSignal('o'); // confirm quit
      delay(3000);
      sendSignal('o'); // select tv
      delay(1000);
      sendSignal('o'); // enter tv
      delay(10000);
      sendSignal('b'); // enter tv
      break;
  }
  
  delay(1000);
  clearScreen();
}

void sendSignal(char c) {
  switch(c) {
    case '0':
      show0();
      IrSender.sendNEC(0xFF40, 0x0, 1);
      break;
    case '1':
      show1();
      IrSender.sendNEC(0xFF40, 0x1, 1);
      break;
    case '2':
      show2();
      IrSender.sendNEC(0xFF40, 0x2, 1);
      break;
    case '3':
      show3();
      IrSender.sendNEC(0xFF40, 0x3, 1);
      break;
    case '4':
      show4();
      IrSender.sendNEC(0xFF40, 0x4, 1);
      break;
    case '5':
      show5();
      IrSender.sendNEC(0xFF40, 0x5, 1);
      break;
    case '6':
      show6();
      IrSender.sendNEC(0xFF40, 0x6, 1);
      break;
    case '7':
      show7();
      IrSender.sendNEC(0xFF40, 0x7, 1);
      break;
    case '8':
      show8();
      IrSender.sendNEC(0xFF40, 0x8, 1);
      break;
    case '9':
      show9();
      IrSender.sendNEC(0xFF40, 0x9, 1);
      break;
    case 'o':
      showOK();
      IrSender.sendNEC(0xFF40, 0xD, 1);
      break;
    case 'b':
      showBack();
      IrSender.sendNEC(0xFF40, 0x42, 1);
      break;
    case 'p':
      showPower();
      IrSender.sendNEC(0xFF40, 0x4D, 1);
      break;
    case 'u':
      showUp();
      IrSender.sendNEC(0xFF40, 0xB, 1);
      break;
    case 'd':
      showDown();
      IrSender.sendNEC(0xFF40, 0xE, 1);
      break;
    case 'l':
      showLeft();
      IrSender.sendNEC(0xFF40, 0x10, 1);
      break;
    case 'r':
      showRight();
      IrSender.sendNEC(0xFF40, 0x11, 1);
      break;
  }
}

void show0() {
  byte frame[8][12] = {
    { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0 },
    { 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0 },
    { 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0 },
    { 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0 },
    { 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0 },
    { 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 }
  };
  matrix.renderBitmap(frame, 8, 12);
}

void show1() {
  byte frame[8][12] = {
    { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0 }
  };
  matrix.renderBitmap(frame, 8, 12);
}

void show2() {
  byte frame[8][12] = {
    { 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0 },
    { 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 }
  };
  matrix.renderBitmap(frame, 8, 12);
}

void show3() {
  byte frame[8][12] = {
    { 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0 },
    { 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0 },
    { 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0 }
  };
  matrix.renderBitmap(frame, 8, 12);
}

void show4() {
  byte frame[8][12] = {
    { 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 },
    { 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 }
  };
  matrix.renderBitmap(frame, 8, 12);
}

void show5() {
  byte frame[8][12] = {
    { 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 },
    { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0 },
    { 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0 }
  };
  matrix.renderBitmap(frame, 8, 12);
}

void show6() {
  byte frame[8][12] = {
    { 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0 },
    { 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
    { 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0 }
  };
  matrix.renderBitmap(frame, 8, 12);
}

void show7() {
  byte frame[8][12] = {
    { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 }
  };
  matrix.renderBitmap(frame, 8, 12);
}

void show8() {
  byte frame[8][12] = {
    { 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0 },
    { 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0 },
    { 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0 }
  };
  matrix.renderBitmap(frame, 8, 12);
}

void show9() {
  byte frame[8][12] = {
    { 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0 },
    { 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0 },
    { 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0 }
  };
  matrix.renderBitmap(frame, 8, 12);
}

void showOK() {
  byte frame[8][12] = {
    { 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0 },
    { 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0 },
    { 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0 },
    { 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0 },
    { 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0 },
    { 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0 },
    { 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0 },
    { 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0 }
  };
  matrix.renderBitmap(frame, 8, 12);
}

void showBack() {
  byte frame[8][12] = {
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
    { 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 },
    { 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  };
  matrix.renderBitmap(frame, 8, 12);
}

void showPower() {
  byte frame[8][12] = {
    { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0 },
    { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0 },
    { 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0 },
    { 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0 },
    { 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0 },
    { 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0 }
  };
  matrix.renderBitmap(frame, 8, 12);
}

void showUp() {
  byte frame[8][12] = {
    { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 }
  };
  matrix.renderBitmap(frame, 8, 12);
}

void showDown() {
  byte frame[8][12] = {
    { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 }
  };
  matrix.renderBitmap(frame, 8, 12);
}

void showLeft() {
  byte frame[8][12] = {
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
    { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  };
  matrix.renderBitmap(frame, 8, 12);
}

void showRight() {
  byte frame[8][12] = {
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 },
    { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  };
  matrix.renderBitmap(frame, 8, 12);
}

void clearScreen() {
  byte frame[8][12] = {
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  };
  matrix.renderBitmap(frame, 8, 12);
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

然后就没然后……不过下一步可能看看如何让网页的声音可以在后台播放。我现在用iOS和chrome,如果把直播画面放到画中画,就可以在后台继续听直播。但是如果不用画中画,当我把屏幕关闭的时候,声音就会中断了,体验挺不好的,反正……

棒球日记

最近MLB中国在搞活动,想要征集一些棒球方面的up主,打算建立一个棒球自媒体生态圈的样子。因为以前也做过一些相关的视频,所以就也报了个名。于是,突然想总结一些自己这些年为了棒球都做过些什么?

如果说第一件事,我觉得就是成立UIC棒球社了。肉壳接触棒球是很早的事情了,因为棒球在天津的发展是相当不错的,所以肉壳很小的时候就大致了解了棒球规则,也玩过一些FC和Genesis上的棒球游戏。不过第一次在现实中打棒球是10年暑假,在外院和老毕玩了玩。后来11年寒假的时候,借着去日本旅游的机会,买了个棒球手套,回到学校就成立了UIC棒球社。就算是在校内为棒球做了一个小宣传。

后来一件比较大的事情是13年在香港念书的时候,在网上看到了一个用白板解释棒球规则的视频,觉得很好玩,就花了点时间把这个视频传到了优酷上。可惜的是,那个账号因为我后来也不维护了,目前视频都被暂时屏蔽了。不过网上至今流传着很多未经授权的转载。差不多同一个时间段,13,14年的时候吧,我还从YouTube上搬运了一些台湾的棒球教学视频。如今也被暂时屏蔽中,哈哈哈。

在15年寒假的时候,我在家呆着无聊,正好那会儿新浪云的二级开发者可以免费试用一些资源。于是,我就用爬虫写了一个网站,用来爬取几个台湾网站的棒球专栏和棒球新闻。当时在朋友圈还小火了一阵,甚至还有朋友来找我谈合作,不过后来不了了之了。再后来,新浪云把二级开发者的每月免费额度取消了,我试着充值维持运营,但是成本有点高,就hold不住了。

再后来,17年底,冬天那会儿,不知道想起啥了,突然想搞搞游戏直播(其实第一次入坑是15年底,刚来美国那会儿),于是就借机在哔哩哔哩和微信公众号上,传了几个视频。恰逢那会儿是MLB世界大赛期间,于是传了几场我用MLB the Show打模拟赛的视频,以及用MLB the Show讲解比赛规则的视频。尤其是那个讲解规则的视频,还是挺受大家欢迎的。只不过,17年底,我又开始做播客了,所以游戏视频这部分就停掉了。还好播客还一直坚持做到现在,虽然听的人不多,但是就算是多个业余爱好。

19年底的时候,因为想要给播客做个网站,于是又买了个网站空间。然后发现新的空间其实权限还挺高,所以就把之前做的棒球新闻聚合站,改了改又上线了。但是上线了几个月,就出bug了。时至今日还没有修好。要不在此立个flag吧……尽快修……

基本上,这就是我在公共领域,为宣传棒球做的贡献了。其实19年买了个GoPro,想说有过有机会可以做做棒球相关的vlog,比如去球场的见闻等等,然后就疫情了……找谁说理去……

这是旧闻

之前说发现了https://archive.org/会自动对各种网站做snapshot。所以,我在里面也找到肉壳的胡思八道的几个旧版本。所以趁着有空,打算建立一个新分类,我们就叫他旧世界吧。把以前博客里的文章搬过来。自己留个存档。现在这些文章看起来确实很幼稚,但这确实是我自己的人生。就算是给自己的一点回忆。另外,文章会保留原始的发表时间,所以如果你看到的是10年前的文章,并且跟我有不同意见。就不要跟小时候的我计较了……

棒球聚合更新日志

昨天个自己的棒球聚合http://baseball.sinaapp.com 又多加了一个网站的MLB和CPBL的新闻和专栏 -> Sportsv的内容……

我也是挺拼的,网站里有些图片是引自墙外的图片,我还得想办法通过国外的服务器下载图片再保存下来……如果连那个服务器都下载不下来,就只能原地址奉送了,随缘了……另外,gif和视频嵌入没有做处理,如果你们能翻墙就能看了……

肉壳的私人棒球资讯聚合

肉壳已经懒到家了,居然整整一年没有发布任何新文章,最后一篇文章居然是13年12月,而如今,已经是15年1月了……时间过得好快啊……

最近,肉壳放假回家,利用业余时间,做了一个有关棒球资讯的聚合。目的就是只要访问自己的这个网站,或者订阅Rss就可以直接阅读台湾几个新闻站点的有关棒球的新闻。有兴趣的话,大家戳这里->http://baseball.sinaapp.com

目前,这个网站只有4个板块,分别是MLB和中华职棒的新闻和专栏。当然,新闻几乎天天都会有很多更新。专栏的话,就慢一点了,这要看作者心情了……

这个站点的原理很简单,通过爬虫,从各个网站上爬来数据,保存在数据库。然后再通过页面展示出来就好了。爬虫框架使用的是吹水的Phpfether,感谢吹水编写的如此好用的爬虫框架。rss方面,我是自己根据rss语法规则自己编写的一个页面,其实我后来在网上找到过一个生成rss feed的类,不过懒得套用了。网页,数据库,存储是放在Sinaapp上的。具体的技术不做深究,有兴趣的朋友可以留言交流……

大概就是这样……