2026年4月2日木曜日

paiza cloudで外部公開サーバを立てる方法(golang)

 PaizaCloud で Go 言語の HTTP サーバを立てて外部からアクセスできるようにするには、

「0.0.0.0」で待ち受けることと、PaizaCloud のポート公開設定を行う必要があります。

以下に手順とサンプルコードを示します。

1. Go HTTP サーバのサンプルコード

package main

import (
	"fmt"
	"log"
	"net/http"
)

// ハンドラ関数
func helloHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintln(w, "Hello from Go HTTP Server on PaizaCloud!")
}

func main() {
	http.HandleFunc("/", helloHandler)

	// PaizaCloud では 0.0.0.0 で待ち受ける必要がある
	addr := "0.0.0.0:8080"

	log.Printf("Starting server on %s ...", addr)
	if err := http.ListenAndServe(addr, nil); err != nil {
		log.Fatalf("Server failed: %v", err)
	}
}

2. PaizaCloud 側の設定

  1. PaizaCloud のエディタで上記コードを作成(例: main.go)。
  2. ターミナルで以下を実行してビルド&実行:
    go run main.go
    
  3. PaizaCloud の右側メニューにある 「Port」または「公開ポート」設定 を開く。
  4. 8080 ポートを追加して公開する。
  5. 表示される 外部アクセス用 URL(例: https://<your-id>.paiza.....)にアクセスすると、ブラウザからサーバに接続できる。login-browerでurlを確認する!

3. 注意点

  • localhost や 127.0.0.1 では外部からアクセスできないため、必ず 0.0.0.0 を指定。
  • PaizaCloud の無料プランではサーバは一定時間で停止するため、長時間稼働には向きません。
  • HTTPS は PaizaCloud 側で自動的に付与されます(Go 側で TLS 設定不要)。

✅ この方法で、PaizaCloud 上の Go HTTP サーバを外部公開できます。

2026年3月29日日曜日

Kalumajs again (ウィンドウズでも成功)

 

kaluma ide on chromeではconnectでピコとつないで左画面のコードがflashで書き込まれた! third-party packageは組み込み不可だった
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
uartはビルトインパッケージだった
const { UART } = require('uart');
const serial0 = new UART(0, { baudrate: 9600});

setInterval(() => {
  console.log("1秒経過");
  serial0.write('Hello, world\r\n');
}, 1000);
// serial0.close(); ATからみで必要かも。。。。
// teratermで成功 kaluma shellで一秒経過が1秒ごとに表示繰り返しあった
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
Total: 34 packages
  • npm i https://github.com/niklauslee/7-segment
    Kaluma library for multi-digit 7-segment display (aka. FND - flexible numeric display)
  • npm i https://github.com/niklauslee/active-buzzer
    Kaluma library to generate beep sound with active buzzer
  • npm i https://github.com/rossdoker/bh1750
    Kaluma library for BH1750 light sensor
  • npm i https://github.com/niklauslee/buzzer-music
    Kaluma library to play music with passive buzzer.
  • npm i https://github.com/niklauslee/dht
    Kaluma library for DHT humidity and temperature sensor 成功した!
  • github installしてreadmeの例文をindex.jsにしてkaluma flash ./index.js --bundleして
  • kaluma shell & .load で成功した
  • npm i https://github.com/rossdoker/ds1307
    Kaluma library for DS1307 RTC module
  • npm i https://github.com/niklauslee/esp8266-driver
    ESP8266 network device driver for Kaluma
  • npm i https://github.com/niklauslee/esp8266-http-client
    A simple Kaluma HTTP client library for ESP8266 module
  • npm i https://github.com/niklauslee/hc-sr04
    Kaluma library for HC-SR04 ultrasonic distance measurement module
  • i2c-lcd  成功した! npm install i2cとこのサイトのnpm installが必要だった
    npm i https://github.com/slashinfty/i2c-lcd
    Kaluma library for liquid crystal display with PCF8574 I2C port expander (LCM1602 module)
  • const LCD = require('i2c-lcd');
    const lcd = new LCD();
    lcd.begin();
    lcd.clear();
    //lcd.cursor();
    //lcd.blink();
    lcd.home();
    lcd.print('hello world');
    lcd.setCursor(0,1); // 2行目
    lcd.print('from fseigojp');
    lcd.setCursor(0,2);  // 3行目
    lcd.print('at kagawa prefecture');
    lcd.setCursor(0,3); // 4行目
    lcd.print('in japan');
    lcd.display(); // これが必須であった!
  • 別の例c
  • onst LCD = require('i2c-lcd');
  • const lcd = new LCD();
  • let count = 0;
    lcd.begin();
    setInterval(()=>{
      lcd.clear();
      lcd.home();
      count++;
      lcd.print(count);
      lcd.display();
    },1000)
  • Kaluma library for IR (Infra-red) receiver.
  • npm i https://github.com/niklauslee/joystick
    Kaluma library for joystick module
  • kaluma-eink そもそも所持してない
    npm i https://gitlab.com/kobaj/kaluma-eink
    A library for controlling e-ink and e-paper displays (mostly from Waveshare) with Kaluma and an RP2040.
  • npm i https://github.com/niklauslee/lcd
    Kaluma library for liquid crystal display (HD44780 driver)
  • lm35 成功したが、手持ちのそれが怪しい
    npm i https://github.com/niklauslee/lm35
    Kaluma library for LM35 temperature sensor
  • lp50xx そもそも所持していない
    npm i https://github.com/AlexK-99/lp50xx
    This is an Kaluma library for interaction with the LP5009 and LP5012 constant current RGB driver from Texas Instrument
  • npm i https://github.com/niklauslee/max7219
    A library for MAX7219/MAX7221 (LED matrix)
  • npm i https://github.com/alexander-daniel/mcp3008
    Kaluma library for MCP3008 8-Channel ADC
  • npm i https://github.com/niklauslee/micro-jest
    A tiny testing framework for Kaluma
  • npm i https://github.com/niklauslee/mpu6050
    Kaluma library for MPU6050 6-axis motion sensor
  • npm i https://github.com/niklauslee/neopixel
    Kaluma library for NeoPixel (ws2812) based on RP2 PIO (Programmable I/O)
  • npm i https://github.com/niklauslee/pcd8544
    Kaluma library for PCD8544, a.k.a Nokia 5110 (Monochrome LCD Display)
  • npm i https://github.com/niklauslee/picosystem
    Kaluma library for Pimoroni's PicoSystem
  • npm i https://github.com/niklauslee/rotary-encoder
    Kaluma library for rotary encoder with a push switch (KY-040)
  • npm i https://github.com/niklauslee/servo
    Kaluma library to control servo motors
  • npm i https://github.com/niklauslee/simple-fonts
    Simple bitmap fonts for Kaluma :: モノクロOLEDでトライ!
  • npm i https://github.com/niklauslee/ssd1306
    Kaluma library for SSD1306 (Monochrome OLED Display)
  • ssd1351 つぎに上記をトライ
    npm i https://github.com/niklauslee/ssd1351
    Kaluma library for SSD1351 (16-bit Color OLED Display)
  • st7735 そもそも持っていない
    npm i https://github.com/niklauslee/st7735
    Kaluma library for ST7735 (Color TFT LCD Display)
  • st7789 そもそも持っていない
    npm i https://github.com/niklauslee/st7789
    Kaluma library for ST7789 (Color TFT/IPS LCD Display)
  • npm i https://github.com/niklauslee/stepper
    Kaluma library to control stepper motors
  • npm i https://github.com/niklauslee/tm1637
    Kaluma library for 7-segment LED Display
  • vl53l0x そもそも持っていない
    npm i https://github.com/haraldkubota/vl53l0x
    Time-of-Flight Sensor VL53L0X
  • npm i https://github.com/pankleks/picomqtt
    MQTT   一回は成功している。。。。
WSL2をWindowsと同一LAN(ネットワーク)で通信させるには、Windows 11(22H2以降)の「ネットワークミラーモード」が最も簡単で推奨されます.wslconfigファイルで設定し、WSL2がホストPCと同じIPアドレスを使用できるようにすることで、LAN内の別端末から直接接続可能になります。
設定方法と詳細:
  • 推奨:ネットワークミラーモード (Windows 11 22H2以降)
    • ユーザーフォルダ(C:\Users\用户名)に.wslconfigファイルを作成または編集し、以下を記述してWSLを再起動(wsl --shutdown)します。
      ini
      [wsl2]
      networkingMode=mirrored
      
    • この設定により、WSL2のLinuxディストリビューションが、Windowsホストと同一のIPアドレスを共有し、LAN内からポートが直接見えるようになります。
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
WSL2(Windows Subsystem for Linux 2)環境でKalumaJS(カルマJS)を動作させるための一般的な手順と注意点を解説します。KalumaJSは、Raspberry Pi Picoなどのマイコンボード向けに設計されたJavaScriptランタイムです。
WSL2でKalumaJSをセットアップする手順
  1. Node.jsのインストール (WSL2)
    KalumaJSはnpmを使用してインストールします。まず、UbuntuなどのWSL2ディストリビューションにNode.jsをインストールします。
    bash on wsl
    sudo apt update
    sudo apt install nodejs npm
    
  2. Kaluma CLIのインストール
    npm経由でKaluma CLIをグローバルにインストールします。
    bash on wsl
    sudo npm install -g kaluma
    
  3. USBシリアルポートの権限設定 (重要)
    WSL2はデフォルトでUSBデバイスに直接アクセスできません。Windows側のUSBシリアルポート(Pico)をWSL2に渡す必要があります。
    • USBIPD-WIN のインストール (Windows側): Windows上でターミナルを管理者権限で開き、以下を実行します。
      powershell
      winget install --interactive --exact dorssel.usbipd-win
      
    • Picoのバインド: USBでPicoを接続し、Windows側でポート番号を確認してバインドします。
      powershell
      usbipd list
      # PicoのBUSIDを確認 (例: 2-1)
      usbipd bind --busid 2-1
      usbipd attach --wsl --busid 2-1

      よく連絡をうしないがちで都度上記2行を実行すべし!
      • WSL側でシリアルポート確認:
        bash
        ls /dev/ttyACM* これでttyACM0とでた!
        kaluma flash index.js --port /dev/ttyACM0で成功!
        その後kaluma flash index.jsでも成功した!