mercoledì 22 giugno 2016

Ascoltare radio in web steaming da shell

Nel mio continuo girovagare in cerca di novita' tecnologiche, ho trovato questo programma che in modo molto semplice e veloce consente di ascoltare le tue stazioni radio in streaming preferite.


Il sistema funziona da shell, non ha interfaccia grafica, ma in fondo non serve per ascoltare la radio!

Si istalla semplicemente con questo comando
 
 
sudo apt-get install mpd mpc
 
Caricato il programma sul sistema, basta aggiungere con 

mpc add "link"   

il link delle stazioni radio che piu' ci piacciono che il sistema comincera' a riprodurre lo streaming sugli altoparlanti del sistema.

Con 

mpc help

avremo la lista di tutti i comandi disponibili.
 



RPi 5,0 HDMI 800x480 con TouchScreen

La battaglia comincia:
Trovare una soluzione stabile e funzionante che consenta l'utilizzo del monitor 5 pollici HDMI per Raspberry Pi.
Una bella sfida, perche' ogni volta che mettiamo mano alla scoperta di qualche pezzo hardware un po' "diverso" dal solito, ci si scontra con la mancanza di informazioni o, peggio con una quantita' di informazioni errate, che fanno perdere un mare di tempo, prima di trovare la strada giusta.
Ma a me e' sempre piaciuto andare ad esplorare nuove strade ed evitare di rimanere legato alle solite cose sulle quali sperimentano un po' tutti, quindi eccomi qui alla ricerca.

La maggior parte delle buone informazioni sul funzionamento di hardware dedicato al meraviglioso campo della hobbistica elettronica, la fornisce Adafruit.
In questo caso pero', forse per il prezzo un po' alto del device,

Per l'istallazione ho seguito questa guida, ma per farla funzionare correttamente importante e' aggiungere queste istruzioni del file config.txt nella cartella /boot della Raspberry Pi con la distribuzione debian classica (Jessy)

hdmi_group=2
hdmi_mode=1
hdmi_mode=87
hdmi_cvt 800 480 60 6 0 0 0

Poi aggiungere  in basso al documento queste due istruzioni qui per attivare il Touch Screen

dtparam=spi=on
dtoverlay=ads7846,penirq=25,speed=10000,penirq_pull=2,xohms=150



con  questa istruzione si istalla il sistema per la calibrazione dello schermo, molto utile per associare al tocco del pennino la corretta posizione
 
 sudo apt-get install -y xinput-calibrator
 
 
Un altro link utile per rendere funzionante l'istallazione e' questo


 

 
 
 Nel caso di utilizzo solo in Terminale si puo' diminuire la memoria dedicata alla GPU
gpu_mem=32
framebuffer_ignore_alpha=1
framebuffer_swap=1
disable_overscan=1
init_uart_clock=16000000
hdmi_group=2
hdmi_mode=1
hdmi_mode=87
hdmi_cvt 800 480 60 6 0 0 0
 
 

 
 

Tastiera Virtuale per Raspberry Pi TouchScreen

 Ho assemblato qualche giorno fa un sistema composto con Raspberry Pi B2 e schermo TFT Touch screen, condito con RaspiCam e, ancora nei progetti ma non montato,  di amplificatore BF e altoparlanti, batteria di alimentazione da 10Ampere, e chissa' quante altre diavolerie mi inventero'!!!

Una delle cose di cui ho sentito subito l'esigenza e' una tastiera virtuale che consentisse di operare sul sistema anche attraverso lo schermo touch.
L'operazione di installazione come sempre non e' stata delle piu' veloci, ma poi , alla fine sono riuscito ad arrivare in fondo utilizzando questa guida.














RPi WebCam Interface

Sempre alla ricerca di qualche applicazione interessante ho scoperto questa che aiuta moltissimo nella costruzione di un  sistema di monitoraggio tramite RaspiCam. Da quando lo ho scoperto, la mia stampante 3D e' costantemente sotto il suo occhio vigile, cosi posso comandarla da remoto e controllare se la stampa impostata, si svolge regolarmente anche quando non sono li di persona.

Istallare il sistema e' semplicissimo.
Partendo da una nuova immagine debian su Raspberry Pi

sudo apt-get update
sudo apt-get dist-upgrade

Poi, se l'istruzione  git  non e' ancora stata caricata nel sistema:

sudo apt-get install git

Quindi:

git clone https://github.com/silvanmelchior/RPi_Cam_Web_Interface.git
cd RPi_Cam_Web_Interface
chmod u+x *.sh
./install.sh

A questo punto il sistema e' installato e potete gia' utilizzarlo chiamando da un browser web l'indirizzo IP della Raspberry Pi, anche dal telefonino come faccio io.



http://elinux.org/RPi-Cam-Web-Interface

ESP8266 i comandi AT

L' ESP8266 appena scartato dalla confezione originale dovrebbe avere gia' caricato il firmware di default che consente di comunicare attraverso semplici comandi AT Hayes compatibili, quelli dei vecchi modem telefonici, per capirsi. I vecchi appassionati della prima ora di internet se li ricordenranno sicuramente.

 Girovagando in rete ho trovato questo link dove vengono riepilogati tutti i comandi in maniera dettagliata.

Room-15

Riporto qui di seguito un copia ed incolla piu' significativo, rimandando al link sopra per un approfondimento  maggiore

I comandi AT riconosciuti dal modulo ESP8266


Index of all known AT commands

Basic WiFI layer TCPIP Layer
AT AT+CWMODE AT+CIPSTATUS
AT+RST AT+CWJAP AT+CIPSTART
AT+GMR AT+CWLAP AT+CIPSEND
AT+GSLP AT+CWQAP AT+CIPCLOSE
ATE AT+CWSAP AT+CIFSR
AT+CWLIF AT+CIPMUX
AT+CWDHCP AT+CIPSERVER
AT+CIPSTAMAC AT+CIPMODE
AT+CIPAPMAC AT+CIPSTO
AT+CIPSTA AT+CIUPDATE
AT+CIPAP +IPD

Line termination

ESP8266 expects  or CarriageReturn and LineFeed at the end of each command, but just ; seems to work too.

Command variants

Each command can have up to 4 variants changing the function of it. You can chose between them by appending one of four possible values to the end of the root command itself. These four appendices can have the following values "",=,"?",=?
Type Example Description
Test AT+CIPSTART=? Query the range of values (So far only AT+CWMODE=? uses it)
Query AT+CMD? Returns the current value of the parameter.
Set AT+CMD=Parameter Set the value of user-defined parameters in commands and run.
Execute AT+CMD Runs commands with no user-defined parameters.
Note:
  • Not all AT commands support all 4 variants.
  • [] = default value, not required or may not appear.
  • String values require double quotation marks, for example: AT+CWSAP="ESP756190","21030826",1,4.
  • Baud rate = 115200
  • AT instruction ends with “\r\n”

Commands

AT - Test AT startup

Variant Command Response Function
Execute AT OK Test if AT system works correctly

AT+RST - Restart module

Variant Command Response Function
Execute AT+RST OK Reset the module

ESP-01 Output after reset:

 ets Jan  8 2013,rst cause:4, boot mode:(3,7)

wdt reset
load 0x40100000, len 24444, room 16
tail 12
chksum 0xe0
ho 0 tail 12 room 4
load 0x3ffe8000, len 3168, room 12
tail 4
chksum 0x93
load 0x3ffe8c60, len 4956, room 4
tail 8
chksum 0xbd
csum 0xbd

ready

ESP-12 Output after reset:

\0x04B1\0x85 \0xff\0x13:'\0xe0;\0xcc;!G\0xfa\0x11\0xa9R\0xc6\0x83\0x01\0xd9\0x81
[Vendor:www.ai-thinker.com Version:0.9.2.4]

ready

AT+GMR - View version info

Variant Command Response Function
Execute AT+GMR version, OK Print firmware version
Parameters:
  • version: firmware version number
ESP-01 output:
00160901
ESP-12 output:
0018000902-AI03

AT+GSLP - Enter deep-sleep mode

Variant Command Response Function
set AT+GSLP=time time OK Enter deep sleep mode for time milliseconds
parameters:
  • time: Time to sleep in milliseconds
Example:
AT+GSLP=1500
Note:
Hardware has to support deep-sleep wake up (Reset pin has to be High).

ATE - Enable / Disable echo

Variant Command Response Function
Execute ATE0 OK Disable echo (Doesn’t send back received command)
Execute ATE1 OK Enable echo (Sends back received command before response)
Note:
I haven’t had any luck with this command yet. Both ATE0 and ATE1 return no this fun.
ATE returns OK
This changed with ESP-12 where the command functions exactly as expected!

AT+CWMODE - WIFI mode(station, AP, station + AP)

Variant Command Response Function
Test AT+CWMODE=? +CWMODE:(1-3) OK List valid modes
Query AT+CWMODE? +CWMODE:mode OK Query AP’s info which is connect by ESP8266.
Execute AT+CWMODE=mode OK Set AP’s info which will be connect by ESP8266.
Parameters:
  • mode: An integer designating the mode of operation either 1, 2, or 3.
    1 = Station mode (client)
    2 = AP mode (host)
    3 = AP + Station mode (Yes, ESP8266 has a dual mode!)
Notes:
ESP-12 came configured as host with ssid set to ESP_A0A3F2, no password, channel 1 You can use AT+CWSAP? to find the current settings.

AT+CWJAP - Connect to AP

Variant Command Response Function
Query AT+CWJAP? + CWJAP:ssid OK Prints the SSID of Access Point ESP8266 is connected to.
Execute AT+CWJAP=ssid,pwd OK Commands ESP8266 to connect a SSID with supplied password.
Parameters:
  • ssid:String, AP’s SSID
  • pwd:String, not longer than 64 characters
Example:
AT+CWJAP="my-test-wifi","1234test"  
Example AT+CWJAP?
+CWJAP:"my-test-wifi"  

AT+CWLAP - Lists available APs

Variant Command Response Function
Set AT+CWLAP=ssid,mac,ch +CWLAP:ecn,ssid,rssi,mac OK Search available APs with specific conditions.
Execute AT+CWLAP AT+CWLAP:ecn,ssid,rssi,mac OK Lists available Access Points.
Parameters:
  • ecn:
    • 0 = OPEN
    • 1 = WEP
    • 2 = WPA_PSK
    • 3 = WPA2_PSK
    • 4 = WPA_WPA2_PSK
  • ssid: String, SSID of AP
  • rssi: signal strength
  • mac: String, MAC address
Note:
On ESP-01 I have had no luck with the set version of this command (AT+CWLAP=...). If you know what it does please let me know.
On ESP-12, the Set version of the command allows to see if a certain SSID, with certain MAC on certain channel exists. If it doesit is returned as one line of the Execute version of this command.
Example AT+CWLAP:
+CWLAP:(3,"CVBJB",-71,"f8:e4:fb:5b:a9:5a",1)
+CWLAP:(3,"HT_00d02d638ac3",-90,"04:f0:21:0f:1f:61",1)
+CWLAP:(3,"CLDRM",-69,"22:c9:d0:1a:f6:54",1)
+CWLAP:(2,"AllSaints",-88,"c4:01:7c:3b:08:48",1)
+CWLAP:(0,"AllSaints-Guest",-83,"c4:01:7c:7b:08:48",1)
+CWLAP:(0,"AllSaints-Guest",-83,"c4:01:7c:7b:05:08",6)
+CWLAP:(4,"C7FU24",-27,"e8:94:f6:90:f9:d7",6)
+CWLAP:(2,"AllSaints",-82,"c4:01:7c:3b:05:08",6)
+CWLAP:(3,"QGJTL",-87,"f8:e4:fb:b5:6b:b4",6)
+CWLAP:(4,"50EFA8",-78,"74:44:01:50:ef:a7",6)
+CWLAP:(0,"optimumwifi",-78,"76:44:01:50:ef:a8",6)
+CWLAP:(3,"BHQH4",-95,"18:1b:eb:1a:af:5b",6)
+CWLAP:(3,"NETGEAR49",-86,"84:1b:5e:e0:28:03",7)
+CWLAP:(3,"ngHub_319332NW00047",-56,"20:e5:2a:79:b1:2f",11)
+CWLAP:(3,"BFZR4",-73,"18:1b:eb:1d:c3:91",11)
+CWLAP:(1,"5FFVL",-82,"00:26:b8:b5:c0:f2",11)
+CWLAP:(3,"59G6D",-77,"00:7f:28:6d:91:7b",11)
+CWLAP:(3,"N16FU",-53,"20:cf:30:ce:60:fe",11)
+CWLAP:(3,"ITS",-82,"90:72:40:21:5f:76",11)
+CWLAP:(3,"ITS",-79,"24:a2:e1:f0:04:e4",11)
Example AT+CWLAP="N16FU","20:cf:30:ce:60:fe",11:
+CWLAP:(3,"N16FU",-53,"20:cf:30:ce:60:fe",11)

AT+CWQAP - Disconnect from AP

Variant Command Response Function
Execute AT+CWQAP OK Disconnect ESP8266 from the AP is currently connected to.
Note:
After running this command, if you run AT+CWJAP? it still shows the AP you were connected to before.

AT+CWSAP - Configuration of softAP mode

Variant Command Response Function
Query AT+CWSAP? +CWSAP:ssid,pwd,ch,ecn OK Query configuration of ESP8266 softAP mode.
Set AT+CWSAP=ssid,pwd,ch,ecn OK Set configuration of softAP mode.
Parameters:
  • ssid: String, ESP8266’s softAP SSID
  • pwd: String, Password, no longer than 64 characters
  • ch: channel id
  • ecn:
    • 0 = OPEN
    • 2 = WPA_PSK
    • 3 = WPA2_PSK
    • 4 = WPA_WPA2_PSK
Example
AT+CWSAP="esp_123","1234test",5,3
AT+CWSAP? => +CWSAP:"esp_123","1234test",5,3

AT+CWLIF - List clients connected to ESP8266 softAP

Variant Command Response Function
Execute AT+CWLIF [ip,other] OK List information on of connected clients.
Parameters:
ip: IP address of a client connected to the ESP8266 softAP other: Other info, look at example. I don’t know what it means yet.
Example (ESP-01):
AT+CWLIF

192.168.4.100,3fff50b4:3fff50ba:3fff50c0:3fff50c6:3fff50cc:3fff50d2

OK
Example (ESP-12):
AT+CWLIF

192.168.4.100,c0:ee:fb:25:33:ec

OK
I ran the command after connecting to the ESP8266 with my cellphone.

AT+CWDHCP - Enable/Disable DHCP

Variant Command Response Function
Set AT+CWDHCP=mode,en OK Enable or disable DHCP for selected mode
Parameters:
  • mode:
    • 0 : set ESP8266 as a softAP
    • 1 : set ESP8266 as a station
    • 2 : set both ESP8266 to both softAP and a station
  • en:
    • 0 : Enable DHCP
    • 1 : Disable DHCP
Note:
This command doesn’t seem to work on firmware 00160901 (ESP-01) nor 0018000902-AI03 (ESP-12).

AT+CIPSTAMAC - Set MAC address of ESP8266 station

Variant Command Response Function
Query AT+CIPSTAMAC? +CIPSTAMAC:mac OK Print current MAC ESP8266’s address.
Execute AT+CIPSTAMAC=mac OK Set ESP8266’s MAC address.
Parameters:
  • mac: String, MAC address of the ESP8266 station.
Example:
AT+CIPSTAMAC="18:aa:35:97:d4:7b"
Note:
This command doesn’t seem to work on firmware 00160901

AT+CIPAPMAC - Set MAC address of ESP8266 softAP

Variant Command Response Function
Query AT+CIPAPMAC? +CIPAPMAC:mac OK Get MAC address of ESP8266 softAP.
Execute AT+CIPAPMAC=mac OK Set mac of ESP8266 softAP.
Parameters:
  • mac: String, MAC address of the ESP8266 softAP.
Example:
AT+CIPAPMAC=”2c:aa:35:97:d4:7b”
Note:
This command doesn’t seem to work on firmware 00160901

AT+CIPSTA - Set IP address of ESP8266 station

Variant Command Response Function
Query AT+CIPSTA? +CIPSTA:ip OK Get IP address of ESP8266 station.
Execute AT+CIPSTA=ip OK Set ip addr of ESP8266 station.
Parameters:
  • ip: String, ip address of the ESP8266 station.
Example:
AT+CIPSTA=”192.168.101.108”
Note:
This command doesn’t seem to work on firmware 00160901

AT+CIPAP - Set ip address of ESP8266 softAP

Variant Command Response Function
Query AT+CIPAP? +CIPAP:ip OK Get ip address of ESP8266 softAP.
Execute AT+CIPAP=ip OK Set ip addr of ESP8266 softAP.
Parameters:
  • ip: String, ip address of ESP8266 softAP.
Example:
AT+CIPAP="192.168.5.1"
Note:
This command doesn’t seem to work on firmware 00160901

AT+CIPSTATUS - Information about connection

Variant Command Response Function
Test AT+CIPSTATUS=? OK
Execute AT+CIPSTATUS STATUS:status +CIPSTATUS:id,type,addr,port,tetype OK Get information about connection.
Parameters:
  • status
    • 2: Got IP
    • 3: Connected
    • 4: Disconnected
  • id: id of the connection (0~4), for multi-connect
  • type: String, “TCP” or “UDP”
  • addr: String, IP address.
  • port: port number
  • tetype
    • 0 = ESP8266 runs as a client
    • 1 = ESP8266 runs as a server
Note:
On ESP-01 this command returns STATUS:1 instead (no extra info, but status changes) On 0018000902-AI03 this command returns STATUS:2 instead (no extra info, but status changes)

AT+CIPSTART - Establish TCP connection or register UDP port and start a connection

Variant Command Response Function
Set AT+CIPSTART=type,addr,port OK Start a connection as client. (Single connection mode)
Set AT+CIPSTART=id,type,addr,port OK Start a connection as client. (Multiple connection mode)
Test AT+CIPSTART=? [+CIPSTART:(id)(“type”),(“ip address”),(port)] OK List possible command variations)
Parameters:
  • id: 0-4, id of connection
  • type: String, “TCP” or “UDP”
  • addr: String, remote IP
  • port: String, remote port

AT+CIPSEND - Send data

Variant Command Response Function
Test AT+CIPSEND=? OK
Set AT+CIPSEND=length SEND OK Set length of the data that will be sent. For normal send (single connection).
Set AT+CIPSEND=id,length SEND OK Set length of the data that will be sent. For normal send (multiple connection).
Execute AT+CIPSEND Send data. For unvarnished transmission mode.

Normal Mode

Parameters:
  • id: ID no. of transmit connection
  • length: data length, MAX 2048 bytes

Unvarnished Transmission Mode

Wrap return “>” after execute command. Enters unvarnished transmission, 20ms interval between each packet, maximum 2048 bytes per packet. When single packet containing “+++” is received, it returns to command mode.

AT+CIPCLOSE - Close TCP or UDP connection

Variant Command Response Function
Test AT+CIPCLOSE=? OK
Set AT+CIPCLOSE=id OK Close TCP or UDP connection.For multiply connection mode
Execute AT+CIPCLOSE OK Close TCP or UDP connection.For single connection mode
Parameters:
  • id: ID no. of connection to close, when id=5, all connections will be closed.
Note:
In server mode, id = 5 has no effect!

AT+CIFSR - Get local IP address

Variant Command Response Function
Test AT+CIFSR=? OK
Execute AT+CIFSR +CIFSR:ip OK Get local IP address.
Parameters:
  • ip: IP address of the ESP8266 as an client.
Example AT+CIFSR:
10.101.10.134

AT+CIPMUX - Enable multiple connections or not

Variant Command Response Function
Set AT+CIPMUX=mode OK Enable / disable multiplex mode (up to 4 conenctions)
Query AT+CIPMUX? +CIPMUX:mode OK Print current multiplex mode.
Parameters:
  • mode:
    • 0: Single connection
    • 1: Multiple connections (MAX 4)
NOTE:
This mode can only be changed after all connections are disconnected. If server is started, reboot is required.

AT+CIPSERVER - Configure as server

Variant Command Response Function
Set AT+CIPSERVER=mode[,port] OK Configure ESP8266 as server
Parameters:
  • mode:
  • 0: Delete server (need to follow by restart)
  • 1: Create server
  • port: port number, default is 333
NOTE:
  1. Server can only be created when AT+CIPMUX=1
  2. Server monitor will automatically be created when Server is created.
  3. When a client is connected to the server, it will take up one connection,be gave an id.

AT+CIPMODE - Set transfer mode

Variant Command Response Function
Query AT+CIPMODE? +CIPMODE:mode OK Set transfer mode,normal or transparent transmission.
Set AT+CIPMODE=mode OK Set transfer mode,normal or transparent transmission.
Parameters:
  • mode:
  • 0: normal mode
  • 1: unvarnished transmission mode

AT+CIPSTO - Set server timeout

Variant Command Response Function
Query AT+CIPSTO? +CIPSTO:time Query server timeout.
Set AT+CIPSTO=time OK Set server timeout.
Parameters:
  • time: server timeout, range 0~7200 seconds

AT+CIUPDATE - update through network

!!! Don’t run this unless you know what you’re doing !!!

### !!! It will likely brick your device !!! Attempts to self-update from the internet.
Variant Command Response Function
Execute AT+CIUPDATE +CIPUPDATE:n OK Start update through network
Parameters:
-n:
- 1: found server
- 2: connect server
- 3: got edition
- 4: start update
Example:
AT+CIUPDATE

+CIUPDATE: 1
+CIUPDATE: 2
+CIUPDATE: 3
+CIUPDATE: 4

\0x02\0x8cl\0x8el\0x8e\0x1cp\0x0c\0x8c\0xf2nn\0xee\0x00l\0x8c\0x8el`
\0x02\0x90\0x12\0x12nnl\0x8cl`\0x02\0x0e\0x02nr\0x8e\0x92\0x92n\0x0c\0x0c
\0x02\0x8c\0x92`\0x02`
\0xf2n\0x0c\0x0c\0x0c\0x9e\0xe0b\0x82nl\0x8c\0x0c\0x8c
\0xf2nn\0xee\0x00\0x0c\0x8e\0x0elp\0xf2n\0xe0\0x10\0x02\0x0c
\0x0cr\0x8c\0x9c\0x9c\0xe2\0xe0\0x0c\0x0c\0x0c
\0x0cb\0x0cn\0xe2|\0x02\0xec\0xecl\0x8c\0x0cb\0x8c\0xf2nn
...forever

eseguire uno script ad ogni avvio di debian

Quando devi costruire macchine che facciano una cosa specifica sempre ad ogni
avvio, basta preparare  un file bash con la lista delle istruzioni o dei programmi che devono essere eseguiti e aggiungerlo al sistema  di esecuzione automatica di debian  con questa istruzione
 
 
sudo update-rc.d nomescript.sh defaults
 
 

sabato 18 giugno 2016

USBdriveby - exploiting USB in style

scatola Raspberry Pi + 5 TFT HDMI + Batteria

Come avrete letto in questo post, sto costruendo un sistema portatile composto da Raspberry Pi ed il suo schermo Touch Screen da 5 pollici. Nei ritagli di tempo ho iniziato a progettare la scatola e come potrete vedere dalle foto nel post a cui faccio riferimento, ho anche gia' iniziato a stampare 3D il primo prototipo.
Il passo successivo sara' quello di includere una power bank da 10.000 mA all'interno della scatola e progettare la guaina per il pennino in dotazione con lo schermo.
Tutti i disegni e le scatole che realizzo sono pubblicate su Tingiverse a questo indirizzo.

coperchio Batteria

Di seguito il filmato del rendering del coperchio disegnato per la scatola della mia costruzione di un prototipo portatile con Raspberry Pi e TFT Touch Screen da 5 pollici HDMI.
Come descritto qui

Pubblichero' tutti i disegni e le modifiche sul mio spazio su Thingiverse a questo indirizzo  per quelli di voi che vorranno costruirsene un prototipo da soli con la propria stampante 3D.

Le prossime modifiche prevedono l'inserimento di una power bank da 10.000 mA in una tasca progettata ad hoc proprio sulla superficie interna di questo coperchio.