Websocket Head
Robot Head controllable with Turbowrap via Websocket[edit]
Microcontroller[edit]
- An ESP32 is Programmed in Arduino IDE
- Servos, buttons, sonsors and speaker can be controlled with Website or websocket
- Arduino code: esp32-sensors-and-servos
Website[edit]
- Connect to ESP_32_servo_xxx
- Open in browser 192.168.4.1
- Optional: Connect ESP to local network, remember IP and connect to this IP
- Control servos, read sensors, play sound via
Turbowrap[edit]
TurboWarp is a fast, powerful Scratch mod that adds more features and performance optimizations.
Start Turbowrap[edit]
Add ESP controll blocks in Turbowrap[edit]
- Add Extension (bottom left)
- Custom Extension -> Text
- Enter JavaScript code: turbowrap_esp32_control
- Check run without sandbox
- Load
Security[edit]
If you use the online editor, the wireless control of the microcontroller with TurboWarp will not work out of the box in most Browsers. There is are security policies (Mixed Content, Same-Origin-Policy) that only allow certain communications between http and WebSocket (https-wss http-ws). You have to allow it manually.
- Desktop version
- No problem
- Firefox:
- Enter [about:config] in adress bar
- Search for network.websocket.allowInsecureFromHTTPS
- Set to true
- Chrome:
- To be tested
- start chrome from cmd with chrome.exe --unsafely-treat-insecure-origin-as-secure=http://192.168.4.1 --user-data-dir="C:/tmp/chrome-dev"
- Local Hosting of TurboWrap
- http <-> ws -> OK
- Run finished project localy
- Download finished projekt with TurboWarp Packager as html and start local
Find IP Adress[edit]
To find the ip adress and names of all available devices enter the command in windows power shell:
arp -a | Select-String '\d+\.\d+\.\d+\.\d+' -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $ip = $_.Value; try { $html=(Invoke-WebRequest -Uri "http://$ip/" -UseBasicParsing -TimeoutSec 2 -ErrorAction Stop).Content; if($html -match 'Name:\s*</strong>\s*([^<\s]+)\.local'){ "$ip -> $($matches[1])" } elseif($html -match '([\w\-]{2,})\.local'){ "$ip -> $($matches[1])" } } catch{} }