From: Dan White Date: Mon, 1 May 2017 10:23:48 +0000 (-0500) Subject: snapshot of rpi code for RF24 Gateway node X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=1309fff733fc34f409a3298ac949ebaa615ed972;p=valpo-ValpoSensorNet.git snapshot of rpi code for RF24 Gateway node --- 1309fff733fc34f409a3298ac949ebaa615ed972 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..56c29d2 --- /dev/null +++ b/Makefile @@ -0,0 +1,51 @@ +############################################################################# +# +# Makefile for librf24mesh examples on Raspberry Pi +# +# By: TMRh20 +# Date: 2013/09 +# +# Description: +# ------------ +# use make all and make install to install the examples +# You can change the install directory by editing the prefix line +# +prefix := /usr/local + +ARCH=armv6zk +ifeq "$(shell uname -m)" "armv7l" +ARCH=armv7-a +endif + +# Detect the Raspberry Pi from cpuinfo +#Count the matches for BCM2708 or BCM2709 in cpuinfo +RPI=$(shell cat /proc/cpuinfo | grep Hardware | grep -c BCM2708) +ifneq "${RPI}" "1" +RPI=$(shell cat /proc/cpuinfo | grep Hardware | grep -c BCM2709) +endif + +ifeq "$(RPI)" "1" +# The recommended compiler flags for the Raspberry Pi +CCFLAGS=-Ofast -mfpu=vfp -mfloat-abi=hard -march=$(ARCH) -mtune=arm1176jzf-s -std=c++0x +endif + +# define all programs +PROGRAMS = ${SOURCES:.cpp=} +SOURCES = ${wildcard *.cpp} + +all: ${PROGRAMS} + +${PROGRAMS}: ${SOURCES} + g++ ${CCFLAGS} -Wall -I../ -lrf24-bcm -lrf24network -lrf24mesh $@.cpp -o $@ + +clean: + rm -rf $(PROGRAMS) + +install: all + test -d $(prefix) || mkdir $(prefix) + test -d $(prefix)/bin || mkdir $(prefix)/bin + for prog in $(PROGRAMS); do \ + install -m 0755 $$prog $(prefix)/bin; \ + done + +.PHONY: install diff --git a/NodeData.proto b/NodeData.proto new file mode 100644 index 0000000..7b26ff6 --- /dev/null +++ b/NodeData.proto @@ -0,0 +1,8 @@ +syntax="proto2"; + +message NodeData { + required uint32 nodeID = 1; + optional uint32 vbatt = 2; + optional uint32 timestamp = 3; + optional uint32 temperature = 4; +} diff --git a/NodeData_pb2.py b/NodeData_pb2.py new file mode 100644 index 0000000..65959c3 --- /dev/null +++ b/NodeData_pb2.py @@ -0,0 +1,88 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: NodeData.proto + +import sys +_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +from google.protobuf import descriptor_pb2 +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='NodeData.proto', + package='', + serialized_pb=_b('\n\x0eNodeData.proto\"Q\n\x08NodeData\x12\x0e\n\x06nodeID\x18\x01 \x02(\r\x12\r\n\x05vbatt\x18\x02 \x01(\r\x12\x11\n\ttimestamp\x18\x03 \x01(\r\x12\x13\n\x0btemperature\x18\x04 \x01(\r') +) +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + + + + +_NODEDATA = _descriptor.Descriptor( + name='NodeData', + full_name='NodeData', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='nodeID', full_name='NodeData.nodeID', index=0, + number=1, type=13, cpp_type=3, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='vbatt', full_name='NodeData.vbatt', index=1, + number=2, type=13, cpp_type=3, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='timestamp', full_name='NodeData.timestamp', index=2, + number=3, type=13, cpp_type=3, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='temperature', full_name='NodeData.temperature', index=3, + number=4, type=13, cpp_type=3, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + extension_ranges=[], + oneofs=[ + ], + serialized_start=18, + serialized_end=99, +) + +DESCRIPTOR.message_types_by_name['NodeData'] = _NODEDATA + +NodeData = _reflection.GeneratedProtocolMessageType('NodeData', (_message.Message,), dict( + DESCRIPTOR = _NODEDATA, + __module__ = 'NodeData_pb2' + # @@protoc_insertion_point(class_scope:NodeData) + )) +_sym_db.RegisterMessage(NodeData) + + +# @@protoc_insertion_point(module_scope) diff --git a/RAPID.proto b/RAPID.proto new file mode 100644 index 0000000..25a4820 --- /dev/null +++ b/RAPID.proto @@ -0,0 +1,12 @@ +syntax = "proto2"; + +message SensorData { + + required int32 sensorId = 1; + optional float value = 2; + optional int32 timestamp = 3; + optional float temperature = 4; + optional float humidity = 5; + optional float pressure = 6; + optional float altitude = 7; +} diff --git a/extract-data.sh b/extract-data.sh new file mode 100755 index 0000000..d91c905 --- /dev/null +++ b/extract-data.sh @@ -0,0 +1,19 @@ +#!/bin/bash + + +nodeID=$1 +protofile=$2 + + +#this is one long pipeline of commands, +# the trailing "\" means that I'm not done with the line yet +# but allows breaking up the commands so they read better +grep "NA $nodeID\|-\d\+ $nodeID" temp.log \ + | awk '{print $8}' \ + | while read line; do \ + echo "$line" \ + | xxd -r -p \ + | protoc --decode NodeData NodeData.proto \ + | grep vbatt; \ + done + diff --git a/gateway.sh b/gateway.sh new file mode 100755 index 0000000..31e18b0 --- /dev/null +++ b/gateway.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +sudo stdbuf -oL ./rf24-master \ + | tee -a data.log \ + | ./send-to-database.sh winlink.from-il.com 22110 + diff --git a/rf24-master.cpp b/rf24-master.cpp new file mode 100644 index 0000000..20c9917 --- /dev/null +++ b/rf24-master.cpp @@ -0,0 +1,73 @@ + +#include +#include + +#include +#include +#include + + + + +#define RFCHANNEL 60 // Prof. White's Gateway +//#define RFCHANNEL 97 // default RF24Mesh channel + +#define MSG_BUFFER_SIZE 1024 + + + +RF24 radio(22, 0); +RF24Network network(radio); +RF24Mesh mesh(radio, network); + + +void timestamp(void) { + static int buflen = 128; + char buffer[buflen]; + struct timespec ts; + + timespec_get(&ts, TIME_UTC); + strftime(buffer, buflen, "%FT%T.", gmtime(&ts.tv_sec)); + printf("%s%09u ", buffer, (unsigned int)ts.tv_nsec); +} + + +int main(int argc, char** argv) { + uint8_t buffer[MSG_BUFFER_SIZE]; + size_t msglen=0; + + mesh.setNodeID(0); + mesh.begin(); + mesh.setChannel(RFCHANNEL); + + while (true) { + mesh.update(); + mesh.DHCP(); + + while (network.available()) { + timestamp(); + RF24NetworkHeader header; + network.peek(header); + + printf("%i NA %i %o ", + radio.getChannel(), + mesh.getNodeID(header.from_node), + header.from_node); + + msglen = network.read(header, buffer, MSG_BUFFER_SIZE); + + size_t i; + for (i=0; i