วันเสาร์ที่ 18 กันยายน พ.ศ. 2564
คำสั่ง Netstat ที่น่าสนใจ ถ้าเป็น mac ใช้ lsof
วันพฤหัสบดีที่ 9 กันยายน พ.ศ. 2564
ให้ Mongodb connect จาก Remote ได้
เมื่อลง Mongodb เป็น Local host แล้ววิธี แก้ให้ Mongodb connect จาก ด้านนอก
1. add user admin และ password ก่อน
mongo
use admin
db.createUser( { user: "name", pwd: "pass", roles: [{ role: "root", db:"admin"}] } )
2 แก้ mongod.conf เพื่อ ให้ access จาก network อื่นได้
sudo vi /usr/local/etc/mongod.confsystemLog: destination: file path: /usr/local/var/log/mongodb/mongo.log logAppend: true storage: dbPath: /usr/local/var/mongodb net: bindIp: 127.0.0.1 -> 0.0.0.0 หรือ IP ที่ต้องการ3 Reboot หรือ restart services mongod
วันพฤหัสบดีที่ 1 กรกฎาคม พ.ศ. 2564
Window Server ไป เปิด Port มากกว่า 5000 เช่น Mongodb ใช้ 27017 ข้ามเครื่อง
Window server กัน การเปิด Port มากกว่า 5000 ใน registry
https://docs.microsoft.com/en-US/troubleshoot/windows-client/networking/connect-tcp-greater-than-5000-error-wsaenobufs-10055
Regedit
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
On the Edit menu, click New, and then add the following registry entry:
Value Name: MaxUserPort
Value Type: DWORD Value data: 65534
วันพฤหัสบดีที่ 27 พฤษภาคม พ.ศ. 2564
การใช้ Powershell run program และ kill program ร่วมกับ regex
File powershell จะนามสกุล .ps1
comment ใช้ # นำหน้า
การเรียก process ใช้ & นำหน้า
มี argument ใช้ param($ตัวแปร)
ตัวอย่าง เป้นการ list process ทีเปิดport ใว้
การ filter ให้ใช้ regex
# kill process select port
Write-Output "Kill process at port"
param ($port)
$foundProcesses = netstat -ano | findstr :$port
$activePortPattern = ":$port\s.+LISTENING\s+\d+$"
# search between number and string
$pidNumberPattern = "\d+$"
# if search between number use "\d+\d"
#If
IF ($foundProcesses | Select-String -Pattern $activePortPattern -Quiet) {
$matches = $foundProcesses | Select-String -Pattern $activePortPattern
$firstMatch = $matches.Matches.Get(0).Value
#Match by regex
$pidNumber = [regex]::match($firstMatch, $pidNumberPattern).Value
taskkill /pid $pidNumber /f
}
วันจันทร์ที่ 17 พฤษภาคม พ.ศ. 2564
pull sql server Docker และ Push กลับ
วีธีการ get Sql Server ของ MyHub
ติดตั้ง Docker
ครั้งแรก
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=yourStrong(!)Password' -e 'MSSQL_PID=Express' -p 1433:1433 -d mcr.microsoft.com/mssql/server:2017-latest-ubuntu
docker container list -a จะได้ระหัส containerid 0cf1dfafff39
เอา data mydb เข้า docker
docker cp D:/SQLData/myDb.mdf 0cf1dfafff39:/var/opt/mssql/data
docker cp D:/SQLData/myDb_log.ldf 0cf1dfafff39:/var/opt/mssql/data
ไป Attach ด้วย SQL Management
การ Push กลับ ที่ Docker Hub hub.docker.com สร้าง user เช่น MyHub
สร้าง Repository เช่น sqldata
แล้วทำการCommit เป็นชื่อ hub/repository:comment
docker container commit 0cf1dfafff39 MyHub/sqldata:latest
จะได้ เลขมาใหม่
docker login --username=MyHub
ใส่ Password
docker push MyHub/sqldata
จะ push ขึ้น hub ได้
จะเปลี่ยน สถานะจาก public เป็น private ก็ได้ แก้ที่ setting ใน Web hub.docker.com
กรณีนำมาใช้
docker pull MyHub/sqldata
แล้ว Run กรณี เป็น SQL Server ต้อง ระบุ forward port ด้วย -P 1433:1433 ใน docker run
หรือ ดุจาก Dash board image -> new container และ ระบุที่ Port เป็น 1433
docker run -p 1433:1433 -d MyHub/sqldata:latest
ไม่นั้น Sqlmanagement จะหาไม่เจอ
วันอังคารที่ 13 เมษายน พ.ศ. 2564
Arduino 2560
การออกแบบ ใช้Arduino 2560 ต้องทำตามหลัก นี้
1. ถ้าต้องการความเร็วในการติดต่อเช่น Stepper motor, Servo ให้ใช้ digital port, Analog port จะมี หน่วง
ถ้าไม่พอให้ใช้ คำสั่ง Drive แต่คำสั่ง Enable ที่ไม่บ่อยใช้ Analog ได้
2. ห้ามใช้ เป็น digital port พวก Communication device , SCL, SDA , MOSI สำหรับ TX RX พอใช้ได้ ตามจำเป็น
3. Input Pull up Resistor ใน ขาที่ ต้องต่อสาย ออกไป ไม่นั้น จะ รบกวน
วันอังคารที่ 6 เมษายน พ.ศ. 2564
เปลี่ยน Sonoff เป็น remote Relay
Sonoff basic เป็น ตัวควบคุม โดยใช้ weLink ใช้ CPU ESP 8266 สามารถโปรแกรม ได้
ใข้ USB serial ต้อง Modify นิดหน่อย เพราะ เป็น 3.3 V แต่ USB Serial ที่ซื้อแบบ TTL จะเป็น 5 V
วิธี แก้ ให้ เอา สาย แดง ในรูป
ต่อ Diode ด้านตรงข้างกับ แถบดำ ต่อกัน 3 ตัว จะได้ 3.6 V ก็จะ ใช้ program ได้
เวลาโปรแกรม ให้ถอดสาย แดงออกก่อนโดยใช้ Arduino ide ให้ กด button ค้างใว้ เสียบสาย แล้วปล่อย
กด Arduino ide upload
ตัวอย่าง Code
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
MDNSResponder mdns;
// Replace with your network credentials
const char* ssid = "myhome";
const char* password = "*******";
ESP8266WebServer server(80);
// Set your Static IP address
IPAddress local_IP(192, 168, 10, 123);
// Set your Gateway IP address
IPAddress gateway(192, 168, 10, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(192, 168, 10, 1); //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional
String webPage = "";
int gpio13Led = 13;
int gpio12Relay = 12;
void setup(void){
webPage += "<h1>ON OFF BUTTON</h1><p><a href=\"on\"><button>ON Blink</button></a> <a href=\"off\"><button>OFF</button></a></p>";
// preparing GPIOs
pinMode(gpio13Led, OUTPUT);
digitalWrite(gpio13Led, LOW);
pinMode(gpio12Relay, OUTPUT);
digitalWrite(gpio12Relay, LOW);
Serial.begin(115200);
delay(5000);
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
Serial.println("STA Failed to configure");
}
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (mdns.begin("esp8266", WiFi.localIP())) {
Serial.println("MDNS responder started");
}
server.on("/", [](){
server.send(200, "text/html", webPage);
});
server.on("/on", [](){
server.send(200, "text/html", webPage);
digitalWrite(gpio13Led, LOW);
digitalWrite(gpio12Relay, HIGH);
delay(1000);
digitalWrite(gpio13Led, HIGH);
digitalWrite(gpio12Relay, LOW);
});
server.on("/off", [](){
server.send(200, "text/html", webPage);
digitalWrite(gpio13Led, HIGH);
digitalWrite(gpio12Relay, LOW);
delay(1000);
});
server.begin();
Serial.println("HTTP server started");
}
void loop(void){
server.handleClient();
}



