jueves, 12 de octubre de 2017

Baja velocidad en interface wireless Qualcomm Atheros QCA9377 - OpenSuse Linux

Problema:
Baja velocidad entrante en interfaz de red wireless Qualcomm Atheros QCA9377.
Distribucion: openSUSE Tumbleweed

Verificar driver de la interfaz de red
# lspci -v
02:00.0 Network controller: Qualcomm Atheros QCA9377 802.11ac Wireless Network Adapter (rev 31)
Subsystem: Lite-On Communications Inc Device 08a6
Flags: bus master, fast devsel, latency 0, IRQ 132
Memory at b1000000 (64-bit, non-prefetchable) [size=2M]
Capabilities: [40] Power Management version 3
Capabilities: [50] MSI: Enable+ Count=1/8 Maskable+ 64bit-
Capabilities: [70] Express Endpoint, MSI 00
Capabilities: [100] Advanced Error Reporting
Capabilities: [148] Virtual Channel
Capabilities: [168] Device Serial Number 00-00-00-00-00-00-00-00
Capabilities: [178] Latency Tolerance Reporting
Capabilities: [180] L1 PM Substates
Kernel driver in use: ath10k_pci
Kernel modules: ath10k_pci

Verificar modulo de la interface de red wireless

# lsmod | grep -i ath10
ath10k_pci 57344 0
ath10k_core 335872 1 ath10k_pci
ath 36864 1 ath10k_core
mac80211 987136 1 ath10k_core
cfg80211 778240 3 mac80211,ath,ath10k_core


Solucion:

Descargar firmware bin
https://github.com/kvalo/ath10k-firmware/blob/master/QCA9377/hw1.0/WLAN.TF.1.0/firmware-5.bin_WLAN.TF.1.0-00002-QCATFSWPZ-5
cp firmware-5.bin_WLAN.TF.1.0-00002-QCATFSWPZ-5 /lib/firmware/ath10k/QCA9377/

Descargamos de memoria el modulo de la interfaz de red wireless
# modprobe -r ath10k_pci

#cd /lib/firmware/ath10k/QCA9377/hw1.0 #
mv firmware-5.bin firmware-5.bin_old
mv firmware-5.bin_WLAN.TF.1.0-00002-QCATFSWPZ-5 firmware-5.bin

#/lib/firmware/ath10k/QCA9377/hw1.0 # ls -ltr
total 1716
-rw-r--r-- 1 root root 46142 Sep 6 22:31 notice_ath10k_firmware-5.txt
-rw-r--r-- 1 root root 605908 Sep 6 22:31 firmware-5.bin_old
-rw-r--r-- 1 root root 8124 Sep 6 22:31 board.bin
-rw-r--r-- 1 root root 304308 Sep 6 22:31 board-2.bin
-rw-r--r-- 1 root root 783336 Oct 11 18:03 firmware-5.bin

Cargamos el modulo:

# modprove ath10k_pci

y volvemos a conectarnos a la red

Referencias:
https://askubuntu.com/questions/607707/ath10k-installation
https://ubuntuforums.org/showthread.php?t=2300861

domingo, 8 de octubre de 2017

Error al montar directorio Samba - mount error(22): Invalid argument

Problema:
Al intentar montar desde terminal un directorio compartido Samba aparece un error


mount -t cifs //192.0.2.122/dir_smb /mont -o user=user_smb
Password for user_smb//192.0.2.122/dir_smb: **********
mount error(22): Invalid argument
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)


2017-10-06T16:22:16.273942-03:00 localhost kernel: [17465.104406] No dialect specified on mount. Default has changed to a more secure dialect, SMB3 (vers=3.0), from CIFS (SMB1). To use the less secure SMB1 dialect to access old servers which do not support SMB3 specify vers=1.0 on mount. For somewhat newer servers such as Windows 7 try vers=2.1.
2017-10-06T16:22:16.449895-03:00 localhost kernel: [17465.279425] CIFS VFS: cifs_mount failed w/return code = -22


Solucion:
mount -t cifs //192.0.2.122/dir_smb /mont -o vers=1.0,user=user_smb

miércoles, 4 de octubre de 2017

Eliminar Sony Vaio Media Gallery - de Windows 10

Problema:
Aparece una ventana informando que el instalador MSI no es encontrado. Mensaje: cannot find folder containing media gallery x64 msi

Solucion:

Desde el directorio C:/Program Files (x86)/Sony, ubicar el ejecutable installer de sony vaio y esperar a que muestre el listado de aplicaciones de Sony instaladas. Elegir Sony Vaio Media Gallery y luego de unos segundos empezara la desinstalacion.

Nota: Es posible que pida la descarga automatica de algun Framework. Elegir descargar e instalar.


Referencias:
http://forum.notebookreview.com/threads/uninstalling-sony-vaio-media-software-vaio-z.545381/
http://community.sony.com/t5/VAIO-Software-Other-Operating/Media-Gallery-x64-msi-Installation-error/td-p/21947
https://answers.microsoft.com/en-us/windows/forum/windows_7-windows_programs/cannot-find-folder-containing-media-gallery-x64/2fd8152f-d495-4f0b-9116-57a092e74c45
http://www.shouldiremoveit.com/vaio-media-gallery-9478-program.aspx

miércoles, 9 de agosto de 2017

Error: Incorrect number of bindings supplied (sqlite3 en python)

Se desea ejecutar la siguiente consulta en python utilizando variables

'select * from curso where code like "%pract%" '

Intento Fallido
        variable = "%pract%"
        self.c.execute('select * from curso where code like ? ', variable)
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 9 supplied.

Solucion:
Encerrar entre parentesis a la variable seguido de una coma:
        variable = "%pract%"
        self.c.execute('select * from curso where code like ? ', (variable,))

o de la siguiente forma

        self.c.execute('select * from curso where code like ? ', ("%"+variable+"%",))


Referencias:
https://docs.python.org/3.6/library/sqlite3.html

miércoles, 19 de julio de 2017

Insertar imagen matplot dentro de template html de Django

Insertar imagen matplot dentro de template html de Django

Crear proyecto
    py -m django startproject htmlmatplot 
    cd htmlmatplot


Crear archivo charts.html
---------------------------------------------------------------------------------
    <a href="http://127.0.0.1:8000/charts">Actualizar</a>
     </br> 
    Charts usando matploit modificando el template en Django 
    </br> 
    <img src="data:image/png;base64,{{imagen}}" /> 
    </br> 
    Fin
----------------------------------------------------------------------------------
    cd htmlmatplot/htmlmatplot
Editar el directorio de templates DIRS

settings.py
------------------------------------------------------------------------------------------
    ... TEMPLATES = [      
    {
              'BACKEND': 'django.template.backends.django.DjangoTemplates',          
              'DIRS': [os.path.join(BASE_DIR+"/templates")], 
    ...
------------------------------------------------------------------------------------------

Ejemplo tomado y modificado de referencia [10]
Crear archivo views.py
------------------------------------------------------------------------------------------
    from django.shortcuts import render 
    def charts(request):      
         import random      
         import django      
         import datetime      
         import io      
         import base64      
     
         from matplotlib.backends.backend_agg import FigureCanvasAgg as 
     
    FigureCanvas      
         from matplotlib.figure import Figure      
         from matplotlib.dates import DateFormatter      
         fig=Figure()      
         ax=fig.add_subplot(111)      
         x=[]      
         y=[]      
         now=datetime.datetime.now()      
         delta=datetime.timedelta(days=1)      
         for i in range(10):          
                x.append(now)          
                now+=delta          
                y.append(random.randint(0, 1000))      
         ax.plot_date(x, y, '-')      
         ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))      
         fig.autofmt_xdate()      
         canvas=FigureCanvas(fig)  
         response=django.http.HttpResponse(content_type='image/png')
         canvas.print_png(response)      
     
          a = io.BytesIO()      
          fig.savefig(a,format="png")      
          a.seek(0)      
          return render(request,"charts.html", {'imagen':base64.b64encode(a.getvalue()).decode()})
------------------------------------------------------------------------------------------

Editar archivo urls.py
----------------------------------------------------------------------------------------
    from django.conf.urls import url 
    from django.contrib import admin 
    from . import views 
    urlpatterns = [      
          url(r'^admin/', admin.site.urls),      
          url(r'^charts/', views.charts), 
    ]
----------------------------------------------------------------------------------------
    cd .. 
    py -m manage runserver
En el navegador browser:



Notas:
Modulo StringIO ya no es utilizado con python3, ahora se utiliza io.


Referencias y sitios visitados:
[1] https://stackoverflow.com/questions/41459657/how-to-create-dynamic-plots-to-display-on-flask
[2] https://stackoverflow.com/questions/7585435/best-way-to-convert-string-to-bytes-in-python-3
[3] https://stackoverflow.com/questions/11914472/stringio-in-python3/11970414#11970414
[4] https://stackoverflow.com/questions/11914472/stringio-in-python3
[5] https://geonet.esri.com/thread/190906-inmemory-png-to-base64-string
[6] https://stackoverflow.com/questions/19908975/loading-base64-string-into-python-image-library/19911883#19911883
[7] https://en.wikipedia.org/wiki/Data_URI_scheme
[9] https://github.com/xhtml2pdf/xhtml2pdf/issues/313
[10] http://scipy-cookbook.readthedocs.io/items/Matplotlib_Django.html
[11] https://stackoverflow.com/questions/1108881/returning-matpotlib-image-as-string
[12] http://grokbase.com/t/gg/django-users/137cw78gqm/how-to-display-image-on-a-template
[13] https://stackoverflow.com/questions/40833140/python-how-to-output-matplotlib-plots-as-images-to-the-browser-in-django
[14] https://www.wired.com/2010/02/use_templates_in_django/
[15] https://docs.djangoproject.com/en/1.11/intro/tutorial01/

lunes, 17 de julio de 2017

Insertar grafico de matplotlib en django

Este es un ejemplo de como insertar un grafico ayudado por la libreria matplotlib y trabajarlo con djando.

1. Crear un Proyecto Nuevo

    D:\testmat>py -m django startproject testmat

D:\testmat>dir
 Volume in drive D is Data
 Volume Serial Number is CEBB-41EC
 Directory of D:\testmat
17/07/2017  12:46 PM    <DIR>          .
17/07/2017  12:46 PM    <DIR>          ..
17/07/2017  12:46 PM    <DIR>          testmat
               0 File(s)              0 bytes
               3 Dir(s)  298.785.083.392 bytes free
     
D:\testmat>cd testmat

D:\testmat\testmat>dir
 Volume in drive D is Data
 Volume Serial Number is CEBB-41EC
 Directory of D:\testmat\testmat
17/07/2017  12:46 PM    <DIR>          .
17/07/2017  12:46 PM    <DIR>          ..
17/07/2017  12:46 PM               827 manage.py
17/07/2017  12:46 PM    <DIR>          testmat
               1 File(s)            827 bytes
               3 Dir(s)  298.785.083.392 bytes free


D:\testmat\testmat>cd testmat

2. Crear archivo views.py


# archivo views.py
# ejemplo copiado y modificado de referencia [1]
def simple(request):
    import random
    import django
    import datetime
    from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
    from matplotlib.figure import Figure
    from matplotlib.dates import DateFormatter
    fig=Figure()
    ax=fig.add_subplot(111)
    x=[]
    y=[]
    now=datetime.datetime.now()
    delta=datetime.timedelta(days=1)
    for i in range(10):
        x.append(now)
        now+=delta
        y.append(random.randint(0, 1000))
    ax.plot_date(x, y, '-')
    ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
    fig.autofmt_xdate()
    canvas=FigureCanvas(fig)
    response=django.http.HttpResponse(content_type='image/png')
    canvas.print_png(response)
    return response

3. Editar archivo urls.py

Agregar la linea que importa la vista agregada en el paso anterior

from django.conf.urls import url
from django.contrib import admin
from . import views
urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^charts/', views.simple), 
]

4. Iniciar el servidor

    D:\testmat\testmat>py -m manage runserver
Performing system checks...
System check identified no issues (0 silenced).
You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
July 17, 2017 - 13:21:21
Django version 1.11.3, using settings 'testmat.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Performing system checks...

Presionar Ctrl + C para salir.

5. Abrir navegador de paginas web indicando la url: http://localhost:8000/charts/


Referencias:

[1] http://scipy-cookbook.readthedocs.io/items/Matplotlib_Django.html

Instalar django en windows

    C:\Users\Uhu>py -m pip install django
Collecting django
Downloading Django-1.11.3-py2.py3-none-any.whl (6.9MB)
100% |████████████████████████████████| 7.0MB 211kB/s
Requirement already satisfied: pytz in c:\users\tmn\appdata\local\programs\python\python36\lib\site-packages (from django)
Installing collected packages: django
Successfully installed django-1.11.3