RF 433.92 sending works :) sending remote buttons to switches and sending wrong temperature to radio alarmclock

pull/1/head
Simon Stuerz 2013-08-20 03:15:51 +02:00
parent 73abc9fd4c
commit 6aca4fd108
13 changed files with 291 additions and 64 deletions

View File

@ -1,4 +0,0 @@
TEMPLATE = subdirs
CONFIG = ordered
SUBDIRS += hive_client

View File

@ -1,9 +1,12 @@
#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
//QQmlApplicationEngine engine("qml/hive_client/main.qml");
QtQuick2ApplicationViewer viewer;
viewer.setMainQmlFile(QStringLiteral("qml/hive_client/main.qml"));

View File

@ -2,22 +2,15 @@ import QtQuick 2.0
import QtQuick.Controls 1.0
import QtQuick.Layouts 1.0
Rectangle {
id: mainWindow
//title: "Hive Client"
width: 500
height: 360
color: "#776262"
RowLayout{
anchors.centerIn: parent
Button{
text: "Button 1"
}
Button{
text: "Button 1"
ApplicationWindow{
id: window
width: 600
height: 360
statusBar: StatusBar {
RowLayout {
Label { text: "Read Only" }
}
}
}

View File

@ -0,0 +1,6 @@
#include "jsonparser.h"
JsonParser::JsonParser(QObject *parent) :
QObject(parent)
{
}

18
hive/libhive/jsonparser.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef JSONPARSER_H
#define JSONPARSER_H
#include <QObject>
class JsonParser : public QObject
{
Q_OBJECT
public:
explicit JsonParser(QObject *parent = 0);
signals:
public slots:
};
#endif // JSONPARSER_H

View File

@ -0,0 +1,6 @@
#include "jsonserializer.h"
JsonSerializer::JsonSerializer(QObject *parent) :
QObject(parent)
{
}

View File

@ -0,0 +1,18 @@
#ifndef JSONSERIALIZER_H
#define JSONSERIALIZER_H
#include <QObject>
class JsonSerializer : public QObject
{
Q_OBJECT
public:
explicit JsonSerializer(QObject *parent = 0);
signals:
public slots:
};
#endif // JSONSERIALIZER_H

View File

@ -15,13 +15,17 @@ DEFINES += LIBHIVE_LIBRARY
SOURCES += libhive.cpp \
server.cpp \
devicemanager.cpp \
logwriter.cpp
logwriter.cpp \
jsonparser.cpp \
jsonserializer.cpp
HEADERS += libhive.h\
libhive_global.h \
server.h \
devicemanager.h \
logwriter.h
logwriter.h \
jsonparser.h \
jsonserializer.h
#unix:!symbian {
# maemo5 {

View File

@ -8,19 +8,20 @@ HiveCore::HiveCore(QObject *parent) :
m_server = new Server(this);
m_server->startServer();
// create Sender
m_sender = new RadioSender(this);
m_sender->setFrequency(RadioSender::RF433MHz);
m_sender->setLineCode(RadioSender::THERMOMETER);
m_sender->setPulseLength(250);
m_sender->sendBin("010100101000101111110110");
m_sender->sendBin("010100101000101111110110");
QByteArray data("11101101");
QDataStream stream(&data, QIODevice::ReadOnly);
qint8 dataInt;
stream >> dataInt;
qDebug() << data << dataInt << data.toInt(0,2);
// create 433.92 MHz receiver
m_reciver = new RadioReciver(this);
m_reciver->setFrequence(RadioReciver::RC433MHz);
m_reciver->setFrequency(RadioReciver::RF433MHz);
m_reciver->enableReceiver();
m_sender->sendBin("010100101000101111110110");
DeviceManager deviceManager;
}

View File

@ -4,9 +4,11 @@
#include <QDebug>
#include <QFile>
#include <QStringList>
#include <QDateTime>
static bool m_enable = false;
static unsigned int timings[RC_MAX_CHANGES];
static float lastTemperature = 0;
RadioReciver::RadioReciver(QObject *parent) :
@ -58,11 +60,11 @@ void RadioReciver::handleInterrupt()
void RadioReciver::detectProtocol(int signalCount)
{
qDebug() << "===========================================================================";
if(signalCount < 49){
qDebug() << "ERROR: got a signal with just" << signalCount << "signals";
//qDebug() << "ERROR: got a signal with just" << signalCount << "signals";
return;
}
qDebug() << "===========================================================================";
QList <int> rawData;
// go trough all 49 timings
@ -83,6 +85,11 @@ void RadioReciver::detectProtocol(int signalCount)
QByteArray binCode;
// __
// pulse form: | |________ = 0 1100000000
// __
// | |________________ = 1 110000000000000000
for(int i = 1; i <= 48; i+=2 ){
if(timings[i] < 1000 && timings[i+1] < 3000 && timings[i+1] > 1000){
binCode.append('0');
@ -101,7 +108,7 @@ void RadioReciver::detectProtocol(int signalCount)
}
// #########################################################################
if(delay > 310 && delay < 320){
if(delay > 310 && delay < 340){
qDebug() << "-----------------------------------------------------------";
qDebug() << " seems to be a REMOTE signal";
@ -133,9 +140,9 @@ void RadioReciver::detectProtocol(int signalCount)
}
// _
// if we have | |___ = 0 -> in 4 delays
// if we have | |___ = 0 -> in 4 delays => 1000
// _
// if we have ___| | = 1 -> in 4 delays
// if we have ___| | = 1 -> in 4 delays => 0001
if(div == 1 && divNext == 3){
binCode.append("0");
@ -196,9 +203,11 @@ float RadioReciver::parseTemperature(QByteArray codeBin)
qDebug() << byteList;
QByteArray temperatureBin(byteList.at(2) + byteList.at(3));
QByteArray batteryBin(byteList.at(4));
QByteArray temperatureTenthBin(byteList.at(5));
// get sign of temperature -> if first bit of temperature byte is 1 -> temp is negativ
// check sign of temperature -> if first bit of temperature byte is 1 -> temp is negativ
int sign = 0;
if(temperatureBin.left(1).toInt() == 1){
sign = -1;
@ -206,11 +215,36 @@ float RadioReciver::parseTemperature(QByteArray codeBin)
sign = 1;
}
qDebug() << temperatureBin << "=" << temperatureBin.left(1) << temperatureBin.right(7) << temperatureBin.right(7).toInt(0,2) << "," << temperatureTenthBin.toInt(0,2) ;
//qDebug() << temperatureBin << "=" << temperatureBin.left(1) << temperatureBin.right(7) << temperatureBin.right(7).toInt(0,2) << "," << temperatureTenthBin.toInt(0,2) ;
// calc temperature
float temperature = sign*(temperatureBin.right(7).toInt(0,2) + (float)temperatureTenthBin.toInt(0,2)/10);
qDebug() << "Temperature:" << temperature;
// check if the battery is low
QString batteryStatus;
if(batteryBin.toInt(0,2) == 0){
batteryStatus = "ok";
}else{
batteryStatus = "low";
}
qDebug() << "Temperature:" << temperature << "Battery: " << batteryStatus;
if(temperature == lastTemperature){
return temperature;
}else{
lastTemperature = temperature;
QString timeStamp = QDateTime::currentDateTime().toString("dd.MM.yyyy, hh:mm");;
qDebug() << timeStamp;
QFile file("/root/temperature_log.ods");
file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text);
QTextStream out(&file);
out << timeStamp << "," << temperature << "," << batteryStatus << "\n";
file.close();
}
return temperature;
}
@ -224,17 +258,17 @@ void RadioReciver::disableReceiver()
m_enable = false;
}
void RadioReciver::setFrequence(RadioReciver::Frequenze frequenze)
void RadioReciver::setFrequency(RadioReciver::Frequency frequency)
{
if(frequenze == RadioReciver::RC433MHz){
if(frequency == RadioReciver::RF433MHz){
if(wiringPiSetup() == -1){
qDebug() << "ERROR: GPIO setup failed.";
qDebug() << "ERROR: GPIO setup for 433.92 MHz receiver failed.";
}
qDebug() << "GPIO setup ok.";
pinMode(2,INPUT);
wiringPiISR(2, INT_EDGE_BOTH, &handleInterrupt);
qDebug() << "GPIO setup for 433.92 MHz receiver ok.";
}
if(frequenze == RadioReciver::RC868MHz){
if(frequency == RadioReciver::RF868MHz){
qDebug() << "ERROR: 868 MHz Module not connected yet";
}

View File

@ -11,9 +11,9 @@ class RadioReciver : public QObject
public:
explicit RadioReciver(QObject *parent = 0);
enum Frequenze{
RC433MHz = 0x0,
RC868MHz = 0x1
enum Frequency{
RF433MHz = 0x0,
RF868MHz = 0x1
};
private:
@ -26,7 +26,7 @@ signals:
public slots:
void enableReceiver();
void disableReceiver();
void setFrequence(Frequenze frequenze);
void setFrequency(Frequency frequency);
};

View File

@ -6,34 +6,161 @@
RadioSender::RadioSender(QObject *parent) :
QObject(parent)
{
// set default pulselenght
m_pulseLength = 350;
// set default radio frequency module
m_frequenze = RadioSender::RF433MHz;
}
void RadioSender::sendSync()
{
// sync for UNIPOLAR:
if(m_lineCode == RadioSender::UNIPOLAR){
}
void RadioSender::transmit(int high, int low)
{
}
void RadioSender::sendBin(QString codeBin)
{
if(wiringPiSetup() == -1){
qDebug() << "ERROR: GPIO setup failed.";
}
qDebug() << "GPIO setup ok.";
pinMode(0,OUTPUT);
// sync for MANCHESTER:
if(m_lineCode == RadioSender::MANCHESTER){
}
// sync for differential MANCHESTER:
if(m_lineCode == RadioSender::DMANCHESTER){
}
// sync for REMOTE: 1 high 31 low
if(m_lineCode == RadioSender::REMOTE){
digitalWrite(m_pin,HIGH);
delayMicroseconds(m_pulseLength);
digitalWrite(m_pin,LOW);
delayMicroseconds(m_pulseLength*31);
}
// sync for THERMOMETER: 1 high 31 low
if(m_lineCode == RadioSender::THERMOMETER){
digitalWrite(m_pin,HIGH);
delayMicroseconds(m_pulseLength);
digitalWrite(m_pin,LOW);
delayMicroseconds(m_pulseLength*31);
}
// sync for WEATHERSTATION:
if(m_lineCode == RadioSender::WEATHERSTATION){
}
}
void RadioSender::send0()
{
// 0 in UNIPOLAR encoding
if(m_lineCode == RadioSender::UNIPOLAR){
digitalWrite(m_pin,LOW);
delayMicroseconds(m_pulseLength);
}
// 0 in MANCHESTER encoding
if(m_lineCode == RadioSender::MANCHESTER){
}
// 0 in differential MANCHESTER encoding
if(m_lineCode == RadioSender::DMANCHESTER){
}
// 0 in REMOTE encoding
if(m_lineCode == RadioSender::REMOTE){
digitalWrite(m_pin,HIGH);
delayMicroseconds(m_pulseLength);
digitalWrite(m_pin,LOW);
delayMicroseconds(m_pulseLength*3);
}
// 0 in THERMOMETER encoding
if(m_lineCode == RadioSender::THERMOMETER){
digitalWrite(m_pin,HIGH);
delayMicroseconds(m_pulseLength*2);
digitalWrite(m_pin,LOW);
delayMicroseconds(m_pulseLength*8);
}
// 0 in WEATHERSTATION encoding
if(m_lineCode == RadioSender::WEATHERSTATION){
}
}
void RadioSender::send1()
{
// 1 in UNIPOLAR encoding
if(m_lineCode == RadioSender::UNIPOLAR){
digitalWrite(m_pin,HIGH);
delayMicroseconds(m_pulseLength);
}
// 1 in MANCHESTER encoding
if(m_lineCode == RadioSender::MANCHESTER){
}
// 1 in differential MANCHESTER encoding
if(m_lineCode == RadioSender::DMANCHESTER){
}
// 1 in REMOTE encoding
if(m_lineCode == RadioSender::REMOTE){
digitalWrite(m_pin,HIGH);
delayMicroseconds(m_pulseLength*3);
digitalWrite(m_pin,LOW);
delayMicroseconds(m_pulseLength);
}
// 1 in THERMOMETER encoding
if(m_lineCode == RadioSender::THERMOMETER){
digitalWrite(m_pin,HIGH);
delayMicroseconds(m_pulseLength*2);
digitalWrite(m_pin,LOW);
delayMicroseconds(m_pulseLength*16);
}
// 1 in WEATHERSTATION encoding
if(m_lineCode == RadioSender::WEATHERSTATION){
}
}
void RadioSender::sendBin(QByteArray codeBin)
{
qDebug() << "send" << codeBin;
for(int i = 0; i < 8; i++){
for(int i = 0; i < codeBin.length(); i++){
if(codeBin.at(i) == '0'){
send0();
}
if(codeBin.at(i) == '1'){
send1();
}
}
sendSync();
}
}
void RadioSender::setFrequency(RadioSender::Frequency frequency)
{
m_frequenze = frequency;
if(m_frequenze == RadioSender::RF433MHz){
m_pin = 0;
if(wiringPiSetup() == -1){
qDebug() << "ERROR: GPIO setup for 433.92 MHz sender failed.";
}
pinMode(m_pin,OUTPUT);
qDebug() << "GPIO setup for 433.92 MHz sender ok.";
}
if(m_frequenze == RadioSender::RF868MHz){
qDebug() << "ERROR: 868 MHz Module not connected yet";
}
}
void RadioSender::setLineCode(RadioSender::LineCode lineCode)
{
m_lineCode = lineCode;
}
void RadioSender::setPulseLength(int pulseLength)
{
m_pulseLength = pulseLength;
}

View File

@ -9,17 +9,38 @@ class RadioSender : public QObject
public:
explicit RadioSender(QObject *parent = 0);
enum Frequency{
RF433MHz = 0x0,
RF868MHz = 0x1
};
enum LineCode{
UNIPOLAR = 0x0,
MANCHESTER = 0x1,
DMANCHESTER = 0x2,
REMOTE = 0x4,
THERMOMETER = 0x8
};
private:
// [us]
// [us = micro seconds]
int m_pulseLength;
Frequency m_frequenze;
LineCode m_lineCode;
int m_pin;
void sendSync();
void transmit(int high, int low);
void send0();
void send1();
signals:
public slots:
void sendBin(QString codeBin);
void sendBin(QByteArray codeBin);
void setFrequency(Frequency frequency);
void setLineCode(LineCode lineCode);
void setPulseLength(int pulseLength);
};