Mostrando entradas con la etiqueta linux. Mostrar todas las entradas
Mostrando entradas con la etiqueta linux. Mostrar todas las entradas

miércoles, 7 de septiembre de 2016

MPL3115A2 sensor (GCC), Linux MySQL/postgreSQL

MPL3115A2 (Language C) Linux MySQL (Banana Pi/Raspberry Pi)

The MPL3115A2 is a compact piezoresistive absolute pressure sensor with an I2C interface. MPL3115A2 has a wide operating range of 20 kPa to 110 kPa, a range that covers all surface elevations on earth. The fully internally compensated MEMS in conjunction with an embedded high resolution 24-bit equivalent ADC provide accurate pressure (Pascals)/altitude (meters) and temperature (°C) data.(see DataSheet, AN4481, AN4519)

Direct reading:

Pressure: 20-bit measurement (Pascals)
Altitude: 20-bit measurement (meters)
Temperature: 12-bit measurement (°C)

MPL3115A2
Simple test MPL3115A2 with a BananaPi. Using the I2C library functions (WiringPi), we communicate with the sensor, then the data is stored in MySQL/postgreSQL database.


CREATE DATABASE sensor;


CREATE TABLE sensor.samples(
 sampleId INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
 sampleDate DATE,
 sampleTime TIME,
 sampleTemperature DOUBLE,
 sampleAltitude DOUBLE,
 samplePressure DOUBLE) default character  set utf8;

Download source code


   MYSQL *conn;
   MYSQL_RES *res;
   //MYSQL_ROW fila;

   char *server = "localhost";
   char *user = "sydbernard";
   char *password = "secreto";
   char *database = "sensor";
   
   conn = mysql_init(NULL);
   
   // Connect to database //
   if (!mysql_real_connect(conn, server,
         user, password, database, 0, NULL, 0)) {
      fprintf(stderr, "%s\n", mysql_error(conn));
      exit(1);
   }

   ...

   /* send SQL query */
   if (mysql_query(conn, buffer)) {
       fprintf(stderr, "%s\n", mysql_error(conn));
       exit(1);
   }
    

To Compile:

$ gcc -Wall -c main.c MPL3115A2.c
$ gcc -Wall -o mpl main.o MPL3115A2.o -l wiringPi -lmysqlclient

wiringBPi



Table MySQL


MySQL

PostgreSQL

PostgreSQL is an object-relational SQL database management system.

Header files and static library for compiling C programs to link with the libpq library in order to communicate with a PostgreSQL database backend.

sudo apt-get install libpq-dev
____________________________

create table samples(
 sampleId SERIAL PRIMARY KEY,
 sampleTemperature DOUBLE precision,
 sampleAltitude DOUBLE precision,
 samplePressure DOUBLE precision
);

PGresult *res;
PGconn *pgConn = PQconnectdb("dbname=sensor hostaddr=127.0.0.1 \
                               user=sydbernard password=snoopy");
if (PQstatus(pgConn) != CONNECTION_OK)
{
   fprintf(stderr, "Connection to database failed: %s",
   PQerrorMessage(pgConn));
}

...

sprintf(buffer,"INSERT INTO samples (sampleTemperature,sampleAltitude,samplePressure) \
VALUES (%.2f, %.2f, %.2f);",temperature, altitude, pressure);

/* send SQL query */
res = PQexec(pgConn, buffer);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
 fprintf(stderr, ">%s", PQerrorMessage(pgConn));
 PQclear(res);
       
}
 
Source Code Download
 
postgreSQL

jueves, 14 de julio de 2016

JCM UBA-10-SS (ID003 Protocol) Simple Driver gcc (Raspberry Pi /Banana Pi/ PC Linux)


Simple Driver JCM UBA-10-SS (ID003 Protocol)

 JCM UBA-10-SS (ID003 Protocol)

Simple driver (gcc) para un billetero JCM UBA-10-SS usando el protocolo ID003.

Las tramas del protocolo ID003 tienen la forma:

| SYNC | Length | CMD | Data Fields | Checksum |

SYNC (1byte): 0xFC
Length (1byte): Longitud total del string (todos los bytes)
CMD (1byte) (instrucción, tipo de orden)
Data (variable)( datos, opcional)
CRC (2byte)( CRC-Kermit)

Para mayor comprensión del CRC-Kermit probar la librería de Lammert Bies, la cual se puede compilar en gcc. Las funciones para el crc-kermit en este driver han salido de aquí.
----------------------------------------------------------------.
crc: tst_crc.o lib_crc.o
    gcc -o crc tst_crc.o lib_crc.o

lib_crc.o: lib_crc.c
    gcc -Wall -c lib_crc.c

tst_crc.o: tst_crc.c
    gcc -Wall -c tst_crc.c

clean:
    rm tst_crc.o lib_crc.o
----------------------------------------------------------------.

 Crc kermit


 
Communication settings:

BaudRate: 9600 (variable)
DataBits: 8 Bits
StopBits: 1 Bit
▪ Paridad: EVEN

Ejemplos de tramas ID003:
FC 05 11 27 56 (STATUS REQUEST)
FC 05 88 6F 5F (VERSION REQUEST)
FC 06 13 62 2B C9 (ESCROW)

Las denominaciones en el id003:

0x61 = 1st
0x62 = 2nd
0x63 = 3rd
0x64 = 4th
0x65 = 5th
0x66 = 6th
 ______________________________________________________________

 uba: main.o wiringSerial.o id003.o crc_kermit.o
    gcc -o uba main.o wiringSerial.o id003.o crc_kermit.o -l pthread

wiringSerial.o: wiringSerial.c
    gcc -Wall -c wiringSerial.c

main.o: main.c
    gcc -Wall -c main.c

id003.o: id003.c
    gcc -Wall -c id003.c

crc_kermit.o: crc_kermit.c
    gcc -Wall -c crc_kermit.c

clean:
    rm main.o wiringSerial.o id003.o crc_kermit.o
 ______________________________________________________________

Descargar Código fuente (Simple Driver JCM UBA)

Descargar herramienta para comprender Id003 by igrotechnics

Driver UBA (JAVA/C++ [Qt]) ID003 Protocol

Disculpen si no respondí antes, password: "sydbernard", "sydbernard1", "maniacmansion" ,"maniacmanison1". Alguno ha de servir.

Código fuente (Simple Driver JCM UBA)