Autor: ricardojlrufino

Que tal Hackear seu carro e plugá-lo na nuvem ?! (TDC/2017 SP)

Segue aqui os slides e vídeos da palestra.

Resumo:

Nessa palestra irei apresentar como você poderá acessar o computador de bordo do seu carro e coletar informações em tempo real, realizar detecção de falhas, e como enviar esses dados para nuvem para realizar análises. Você irá se surpreender em quais carros é possível fazer isso !!

Vídeo de demonstração do APP

 

Vídeo de demonstração do APP e Hacking do sensor de estacionamento.

 

Fontes:

Demo App (Andoird): https://github.com/OpenDevice/opendevice-examples/tree/master/IoTCar

Firmware (arduino) : https://github.com/OpenDevice/opendevice-examples/tree/master/IoTCar/firmware

OBD2 protocoll extension: https://github.com/OpenDevice/opendevice-extensions/tree/master/obd-connection

Anúncios

Remove Noise/Echo using PulseAudio

Simple tip to remove noise / echo from audio for recordings
Edit file pulseaudio config:

sudo nano /etc/pulse/default.pa

Append to end:

load-module module-echo-cancel source_name=MicEchoOFF
set-default-source MicEchoOFF

Restart pulseaudio server

pulseaudio -k

Backup and Flash SPI Memory using Arduino

After a wrong upgrade firmware of a TP-Link router, the only alternative was to write the flash memory directly.

The strategy I used was: Update only the u-boot sector, which is responsible for loading the kernel, and then updating using tftp [link].

It is possible to write all the firmware, however I preferred this method because it is faster. Writing the whole flash (ex: 8mb) can take about 10min.

I’ve developed a sketch for this purpose, and it can be downloaded from the link:
https://github.com/ricardojlrufino/SerialFlashSPI

The entire wiring diagram and details is also on the link above.

Notes

Currently (04-2017), it is only compatible with Winbond memories, but can be adapted for other libraries

I used the Arduino DUE because it is 3.3v. If you are using another arduino, you need to create a voltage divider.

The u-boot has 128 kb, which corresponds to the “512 pages” of “256 bytes”. You should adjust the base file size to the multiples of 256. This can be configured directly on the serial console

Wiring

Diagram

 

 

OpenWRT no TP-LINK WR740N(BR) v6

Segue algumas dicas e informações sobre o roteador TP-LINK  WR740N(BR) v6.0.
Não irei tratar do processo de instalação em detalhes pois o mesmo é simples, e pode ser feito pelo gerenciador do firmware original.

As instruções de instalação em modelos/versões similares pode ser encontrados no endereço: https://wiki.openwrt.org/toh/tp-link/tl-wr740n
Aqui são algumas dicas para o modelo específico:  v6.0

Download do firmware: 
https://downloads.openwrt.org/snapshots/trunk/ar71xx/generic/openwrt-ar71xx-generic-tl-wr740n-v6-squashfs-factory.bin

Informações gerais:

SoC: Qualcomm Atheros QCA9533
Memory (32MB): Zentel A3S56D40GTP
FLASH (4MB): Winbond 25Q32CSI

Acesso a Serial (RX/TX)

Esse modelo tem os conectores bem visíveis, o que pode animar, porém eles não estão soldados, para funcionar é preciso fazer um “jumper” e conecta-lo nos resistores que estão próximos, conforme a imagem:

TPLINK-WR740_UART.png
OBS: Na imagem eu já soldei uma barra de pinos …

Notas

Infelizmente o equipamento só tem 4MB de flash, o que limita bastante a instalação de pacotes, nem mesmo é possível instalar a interface gráfica.

O próximo passou que irei tentar é colocar outra memória flash. 😉

Imagens do Hardware

Support multiple versions of Java

On ubuntu/linux you can switch java version using

update-alternatives –config java

But before, you need install the version.

You can use this script (./install-java.sh) to install multiple JVMs

#!/bin/sh
(
lookforJdks=$PWD
echo "Directory: $lookforJdks"
jdks=`test -e ./javac || find $lookforJdks -type d -iname '*jdk1.*' 2> /dev/null`
#set -e
echo 'which jdk do you want to choose? looking for jdks. This might take a while'
echo "$jdks" | awk '{printf("%5d : %s\n", NR,$0)}'
read choose
test -e ./javac || cd `echo "$jdks" | tr '\n' ',' | cut -d',' -f $choose`/bin
for e in appletviewer extcheck idlj jar jarsigner java javac javadoc javah javap jconsole \
 jdb jhat jinfo jmap jps jrunscript jsadebugd jstack jstat jstatd native2ascii rmic \
 schemagen serialver wsgen wsimport xjc jvisualvm jmc; do sudo update-alternatives \
 --install /usr/bin/$e $e $(readlink -f ./$e) 100; done
)

echo "RUN update-alternatives --config java"

Put this script in folder where has unpacked the JVM(s), an run:

./install-java.sh

Next use: update-alternatives –config java

IP Camera Protocol / Webapp Integration

This post is for interested who want to create a desktop or web software to control IP cameras.

Reverse engineering was made in a Chinese IP camera (the image below)

Features:

  • Powerful high-speed video protocol processor.
  • Optimized MJPEG video compression for transmission.
  • Multi-level users management and passwords definition.
  • Embeded Web Server for users to visit by IE.
  • Support wireless network (Wi-Fi/802.11/b/g)mobile, two way audio.
  • Supporting Dynamic IP (DDNS)and UPnP LAN.
  • Giving alarm in cause of motion detection.
  • Support multiple network protocols:
    • HTTP/TCP/IP/UDP/STMP/DDNS/SNTP/DHCP/FTP.
  • Support remote system update,Multi-Protocol support and Transportation.
  • Sending the image to your mailbox automatically when the IP CAM is triggered.

Ref: http://www.chantronics.com.au/computers/viewitem.php?productid=204

In this model the web interface is at the port 81. As the IP of this equipment is dynamic, you can resort to the DHCP client list of the router, or run a port scan. In Linux, use:

nmap -p 81 192.168.1.0/24

Accessing resources of camera

Configuration Page
http://IP:81/config.htm

Telnet
telnet IP
Login: root, Pass: 123456

TIPs:

Open source software in Java, which supports integration with IP cameras:
http://webcam-capture.sarxos.pl/

Java FTP Server:
http://mirror.nbtelecom.com.br/apache/mina/ftpserver/1.0.6/dist/
Ref: https://geertschuring.wordpress.com/2015/02/11/how-to-start-a-simple-embedded-java-based-ftp-server/

Protocol


Video Stream

http://IP:PORT/videostream.cgi?loginuse=myuser&loginpas=mypass

Include in Webapp / Html page:

Snapshot

/snapshot.cgi?loginuse=myuser&loginpas=mypass

Request General Settings

/get_status.cgi?loginuse=myuser&loginpas=mypass

Response:

var alias=”IPCAM”; var deviceid=”EST-065556-XXXX”; var sys_ver=”57.2.0.138″; var now=1452435094; var alarm_status=0; var upnp_status=1; var dnsenable=0; var osdenable=0; var syswifi_mode=1; var mac=”00:0C:6C:11:XX:XX”; var wifimac=”00:0C:6C:11:XX:XX”; var dns_status=0; var authuser=0; var devicetype=21037151; var devicesubtype=0; var externwifi=1; var record_sd_status=0; var sdtotal=0; var sdfree=0;

Request Image Settings

/get_camera_params.cgi?loginuse=myuser&loginpas=mypass

var resolution=0; var vbright=1; var vcontrast=114; var vhue=0; var vsaturation=0; var OSDEnable=0; var mode=1; var flip=1; var enc_framerate=10; var sub_enc_framerate=15; var speed=10; var enc_bitrate=500; var ircut=1;

Change Name

/set_alias.cgi?alias=MYNAME&loginuse=myuser&loginpas=mypass

Resolution

/camera_control.cgi?loginuse=myuser&loginpas=mypass&param=0&value=XX
value=0 – VGA
value=1 – QVGA

Image Mirror

/camera_control.cgi?loginuse=myuser&loginpas=mypass&param=5&value=X
value=0 – normal
value=1 – reversal
value=2 – mirror
value=3 – reversal & mirror

FreameRate

/camera_control.cgi?loginuse=myuser&loginpas=mypass&param=6&value=10
value = 1 a 30

Brightness

/camera_control.cgi?loginuse=myuser&loginpas=mypass&param=1&value=1
value = 1 a 255

Contrast

camera_control.cgi?loginuse=myuser&loginpas=mypass&param=2&value=73
value = 1 a 255

Rotate/Move Speed

/camera_control.cgi?loginuse=myuser&loginpas=mypass&param=100&value=X
value = 1 .. 10

Rotate/Move

/decoder_control.cgi?loginuse=myuser&loginpas=mypass&command=XX&onestep=0
Command Center = 25
PTZ_UP=0;
PTZ_UP_STOP=1;
PTZ_DOWN=2;
PTZ_DOWN_STOP=3;
PTZ_LEFT=4;
PTZ_LEFT_STOP=5;
var PTZ_RIGHT=6;
var PTZ_RIGHT_STOP=7;
var PTZ_LEFT_UP=90;
var PTZ_RIGHT_UP=91;
var PTZ_LEFT_DOWN=92;
var PTZ_RIGHT_DOWN=93;
var PTZ_STOP=1;
var PTZ_VPATROL=26;
var PTZ_VPATROL_STOP=27;
var PTZ_HPATROL=28;
var PTZ_HPATROL_STOP=29;

List Alarms

/get_alarmlog.cgi&loginuse=myuser&loginpas=mypass

Clear: /set_alarmlogclr.cgi&loginuse=myuser&loginpas=mypass

var log_text=””; log_text+=”gpio alarm 2016-01-10 15:49:56\n”; log_text+=”gpio alarm 2016-01-10 15:49:09\n”;

References:

 

Setup DHCP Server on Ubuntu

Sometimes you need to connect a device (Raspberry, IP Cam) directly to the PC. As these devices are mostly configured with dynamic IP, you need to setup a dhcp server.

sudo apt-get install dhcp3-server

Set to start manually if you do not want this service on your PC

sudo /etc/init.d/isc-dhcp-server stop
sudo sh -c "echo 'manual' > /etc/init/isc-dhcp-server.override"

Configure the INTERFACES setting to include eth0
Edit file: /etc/default/isc-dhcp-server , and change

INTERFACES="eth0"

Configure DHCP to assign network addresses in the range 192.168.1.100 to 192.168.1.200.
Edit File: /etc/dhcp/dhcpd.conf , add apppend.
> sudo nano /etc/dhcp/dhcpd.conf

subnet 192.168.1.0 netmask 255.255.255.0 { #network
 range 192.168.1.20 192.168.1.100; # Range
 option domain-name-servers 192.168.1.5, 8.8.8.8; #Pri DNS , Sec DNS
 option routers 192.168.1.1; #Gateway
 option broadcast-address 192.168.1.255; #Broadcast
 default-lease-time 600;
 max-lease-time 7200;
}

 

Configure Network (new Ethernet)

1. Open:

Selection_255.png

2. Add new Ethernet

Selection_253.png

3. Configure Static IP

Selection_254.png

4. Connecte in the newly created network

Start DHCP Server

# start DHCP service
sudo service isc-dhcp-server start

# enable forwarding from the ethernet to wireless router
sudo /sbin/iptables --table nat -A POSTROUTING -o wlan0 -j MASQUERADE

Testing the connection

tail /var/log/syslog

Testing the connection

Reference:
http://www.mccarroll.net/blog/rpi_netbook/index.html
http://www.krizna.com/ubuntu/setup-dhcp-server-ubuntu-14-04/
http://unix.stackexchange.com/a/42308

Bluetooth audio from Phone to Ubuntu

This is a short guide to how to send audio from your phone (tested on Android) to your PC (tested on Ubuntu).

I have not found how to enable the functionality in the system settings (PC side)

Support is already implemented in PulseAudio

Now you’ll have to pair the computer with the phone as per normal.

Method 1 – Using GUI (D-FEET)

Use a tool called d-feet, which is available in the Ubuntu repos.

$> sudo apt-get install d-feet

Open d-feet  and find your phone device

Seleção_239.png

Click in Connect on org.bluez.AudioSource , and then click Execute in the dialog that will open

Method 2 – Using Script / Command Line

export BTADAPTER=`dbus-send --system --dest=org.bluez --print-reply / org.bluez.Manager.DefaultAdapter | tail -1 | sed 's/^.*"\(.*\)".*$/\1/'`

dbus-send --system --dest=org.bluez --type=method_call --print-reply \
$BTADAPTER/dev_1C_56_FE_A3_EC_0C org.bluez.AudioSource.Connect

Now all audio from your phone should be streaming through your computer

If this method did not work, check the complete guide in reference:

Reference:

Algoritmos de Busca – IA – PuzzleSearch

problema.jpg

 

Este exemplo mostra um algorítmo para resolver aqueles quebra-cabeças formados por blocos de numeros, onde é possivel mover uma peça de cada vez e o objetivo é deixar os numeros alinhados (1, 2, 3, 4, …. ):

Seleção_197.png

O segredo deste algorítmo esta na definição da função heuristica que irá determinar um valor para cada estado do tabuleiro. O objetivo é maximizar este valor, isto é, a solução será encontrada quando o valor for 8.

Veja a classe: BoardHeuristicA.java

Código:
https://github.com/ricardojlrufino/IA_PuzzleSearch

No projeto estão implementados outros métodos de busca e a estrutura está flexível para implementar outros algoritmos.