Archives mensuelles : décembre 2014

image_pdfimage_print

Follow the electrical consumption

It is made with ARIA G25 with ethernet and 1 serial port and 1 teleinfo module.


import serial
import datetime

import json
import urllib2

class SenseDevice:
    base_url = 'http://api.sen.se/events/'
    data = []

    def __init__(self, api_key):
        self.api_key = api_key

    def add_value(self, feed_id, value):
        self.data.append({
                'feed_id': feed_id,
                'value': value
                })

    def publish(self):
        req = urllib2.Request(self.base_url)
        req.add_header('sense_key', self.api_key)
        req.add_header('content-type', 'application/json')

        req.add_data(json.dumps(self.data).encode('utf-8'))
        res = urllib2.urlopen(req)
        self.data = []
        return res

t0=datetime.datetime.now()

ser = serial.Serial('/dev/ttyS4', 9600, timeout=1)
print("connected to: " + ser.portstr)

a=SenseDevice('XXXXXXXXXXXX')
while True:
    # Read a line and convert it from b'xxx\r\n' to xxx
    line = ser.readline()[:-2]
    print line
    if 'HCHP' in line:
     val1=line.split()[1]


    if 'HCHC' in line:
     val2=line.split()[1]

    t1=datetime.datetime.now()

    if (t1-t0).seconds > 60 :
       t0=t1
       print datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),val1,val2
       a=SenseDevice('XXXXXXXXXXXXXXXXXA')
       a.add_value(49711,float(val1)/1000.0)
       a.add_value(54884,float(val2)/1000.0)
       res=a.publish()
       print res
 
ser.close()

Recompile kernel for Aria G25 to have the DLINK WIFI USB dongle working

Update with kernel 3.16.1

On my laptop :

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- acme-aria_defconfig

make ARCH=arm menuconfig

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- acme-aria.dtb
make -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- uImage
make modules -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
make modules_install INSTALL_MOD_PATH=./modules ARCH=arm

scp arch/arm/boot/dts/acme-aria.dtb root@192.168.1.41:/boot/at91-ariag25.dtb

scp arch/arm/boot/uImage root@192.168.1.41:/boot/image.bin

I had to install rsync on the aria g25 board (apt-get install rsync
rsync -avc modules/lib/ root@192.168.1.41:/lib/

Then reboot the acme card

once rebooted, do

depmod -a

apt-get install firmware-realtek
echo 2001 330d > /sys/bus/usb/drivers/rtl8192cu/new_id

I see with dmesg :

rtl8192cu: Chip version 0x11
rtl8192cu: MAC address: f8:e9:03:d5:03:8a
rtl8192cu: Board Type 0
rtl_usb: rx_max_size 15360, rx_urb_num 8, in_ep 1
rtl8192cu: Loading firmware rtlwifi/rtl8192cufw_TMSC.bin
usb 2-1: Direct firmware load failed with error -2
usb 2-1: Falling back to user helper
rtlwifi: Loading alternative firmware rtlwifi/rtl8192cufw.bin
ieee80211 phy0: Selected rate control algorithm ‘rtl_rc’
rtlwifi: wireless switch is on

root@acmeboard:~# cat /proc/net/wireless
Inter-| sta-| Quality | Discarded packets | Missed | WE
face | tus | link level noise | nwid crypt frag retry misc | beacon | 22
wlan0: 0000 0 0 0 0 0 0 0 0 0

apt-get install wireless-tools

and process as below to set the /etc/network/interfaces

then

/etc/init.d/networking restart

To have this ok at boot, add the 2 lines below in /etc/rc.local

echo 2001 330d > /sys/bus/usb/drivers/rtl8192cu/new_id

/etc/init.d/networking restart

————————————————————–

Following instructions from :

http://www.acmesystems.it/dlink_wifi

Add a USB connector to the board : http://www.acmesystems.it/ariag25_wirings

Recompile the kernel 2.6.39 (http://www.acmesystems.it/ariag25_compile_linux_2_6_39)

In linux-2.6.39/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c, you have to add a line for your dongle :

/****** 8192CU ********/
{RTL_USB_DEVICE(0x0586, 0x341f, rtl92cu_hal_cfg)}, /*Zyxel -Abocom*/
{RTL_USB_DEVICE(0x07aa, 0x0056, rtl92cu_hal_cfg)}, /*ATKK-Gemtek*/
{RTL_USB_DEVICE(0x07b8, 0x8178, rtl92cu_hal_cfg)}, /*Funai -Abocom*/
{RTL_USB_DEVICE(0x07b8, 0x8178, rtl92cu_hal_cfg)}, /*Abocom -Abocom*/
{RTL_USB_DEVICE(0x2001, 0x3307, rtl92cu_hal_cfg)}, /*D-Link-Cameo*/
{RTL_USB_DEVICE(0x2001, 0x3309, rtl92cu_hal_cfg)}, /*D-Link-Alpha*/
{RTL_USB_DEVICE(0x2001, 0x330a, rtl92cu_hal_cfg)}, /*D-Link-Alpha*/
{RTL_USB_DEVICE(0x2001, 0x330d, rtl92cu_hal_cfg)}, /*D-Link-Alpha*/
{RTL_USB_DEVICE(0x2019, 0xab2b, rtl92cu_hal_cfg)}, /*Planex -Abocom*/
{RTL_USB_DEVICE(0x7392, 0x7822, rtl92cu_hal_cfg)}, /*Edimax -Edimax*/
{}

You need rtl8192cufw.bin  in  /lib/firmware/rtlwifi/ (it is not installed when you install the package firmware-realtek)

In /etc/network/interfaces (WEP key) :


auto wlan0
iface wlan0 inet dhcp
wireless-essid Freebox-XXXX
wireless-key XXXXXX

The Wifi USB dongle must not be too far from the access point.

You got :

...
sb 2-1: new full speed USB device number 2 using at91_ohci
usb 2-1: not running at top speed; connect to a high speed hub
usb 2-1: New USB device found, idVendor=2001, idProduct=330d
usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 2-1: Product: 802.11n WLAN Adapter
usb 2-1: Manufacturer: Realtek
usb 2-1: SerialNumber: 00e04c000001
rtl8192cu: MAC address: f8:e9:03:d5:03:8a
rtl8192cu: Board Type 0
rtl8192cu: rx_max_size 15360, rx_urb_num 8, in_ep 1
ieee80211 phy0: Selected rate control algorithm 'rtl_rc'
rtl8192cu 2-1:1.0: wlan0: Features changed: 0x00004800 -> 0x00004000
....
rtl8192cu: MAC auto ON okay!
rtl8192cu: Tx queue select: 0x05
rtl8192cu: Loading firmware file rtlwifi/rtl8192cufw.bin
wlan0: authenticate with f4:ca:e5:ab:22:2c (try 1)
wlan0: authenticated
wlan0: associate with f4:ca:e5:ab:22:2c (try 1)
wlan0: RX AssocResp from f4:ca:e5:ab:22:2c (capab=0x411 status=0 aid=3)
wlan0: associated
...

20141230_004649
Electronic circuit to follow my electrical consumption and publish the results on the net.