A multifunctional and modular Firmware for Multitech's mDot based on ARM mBed provides a widerange of functionality for several Sensors such as MAX44009, BME280, MPU9250, SI1143 and uBlox. It allows you to quickly build a Sensornode that measures specific data with its sensors and sends it via LoRaWAN.

Dependencies:   mDot_LoRa_Sensornode_Flowmeter_impl mbed-rtos mbed

LoRa-Sensornode Firmware for Multitech mDot

A multifunctional and modular Firmware for Multitech's mDot which provides a widerange of functionality for several Sensors. It allows you to quickly build a Sensornode that measures specific data with its sensors and sends it via LoRaWAN.

/media/uploads/mitea1/logo-lora-600x370.png /media/uploads/mitea1/mt_mdot_family_642px.png

Supported Sensors

Idea

The Firmware has some predefined Application Modes running different Tasks(Measurements). Each mode can be used in a different Scenario. Application_Modes define which sensors are used, how often they aquire data and how often the data has to be sent via LoRa. Lets say you just want to measure the Light then you choose an Application_Mode (or define one) that only runs TaskLight for light measurement. As a standard all measurements are taken every second and sent via LoRa but you can change that interval depending on your usage Scenario

app/TaskFlowMeter.cpp

Committer:
mitea1
Date:
2018-11-02
Revision:
10:4051c38bf73f
Parent:
9:c4e378f4801d

File content as of revision 10:4051c38bf73f:

/*
 * TaskFlowMeter.cpp
 *
 *  Created on: 23.10.2018
 *      Author: Adrian
 */

#include "TaskFlowMeter.h"

TaskFlowMeter::TaskFlowMeter(FlowMeter* flowMeter, Mutex* mutex, Queue<FlowMeterMessage,FLOWMETER_QUEUE_LENGTH>* queue) {
	this->flowMeter = flowMeter;
	setMutex(mutex);
	setQueue(queue);
}
TaskFlowMeter::TaskFlowMeter(FlowMeter* flowMeter, Mutex* mutex, Queue<FlowMeterMessage,FLOWMETER_QUEUE_LENGTH>* queue,
		osPriority priority, uint32_t stackSize, unsigned char* stackPointer){
	this->flowMeter = flowMeter;
	setMutex(mutex);
	setQueue(queue);
	setPriority(priority);
	setStackSize(stackSize);
	setStackPointer(stackPointer);
	setState(SLEEPING);
}

TaskFlowMeter::~TaskFlowMeter() {
	// TODO Auto-generated destructor stub
}

osStatus TaskFlowMeter::start(){
	this->setState(RUNNING);
	this->thread = new rtos::Thread(callBack,this);
}

osStatus TaskFlowMeter::stop(){
	thread->terminate();
	setState(SLEEPING);
	delete this->thread;
}

void TaskFlowMeter::callBack(void const* data){
	// WOODHAMMER METHOD of Casting!
	const TaskFlowMeter* constInstance = static_cast<const TaskFlowMeter* >(data);
	TaskFlowMeter* instance = const_cast<TaskFlowMeter*>(constInstance);

	instance->measure();
}

void TaskFlowMeter::attachIdleHook(void (*fptr) (void)){
	this->thread->attach_idle_hook(fptr);
}

void TaskFlowMeter::measure(){
	FlowMeterMessage flowMeterMessage;

	while(true){
		mutexFlowMeter->lock(osWaitForever);
		flowMeterMessage.setCurrentFlowrate(flowMeter->getCurrentFlowrate());
		flowMeterMessage.setCurrentVolume(flowMeter->getCurrentVolume());
		flowMeterMessage.setTotalFlowrate(flowMeter->getTotalFlowrate());
		flowMeterMessage.setTotalVolume(flowMeter->getTotalVolume());
		mutexFlowMeter->unlock();

		queue->put(&flowMeterMessage,osWaitForever);
		osDelay(FLOWMETER__TASK_DELAY_MS);
	}
}

void TaskFlowMeter::setQueue(Queue<FlowMeterMessage,FLOWMETER_QUEUE_LENGTH>* queueFlowMeter){
	this->queue = queueFlowMeter;
}

void TaskFlowMeter::setMutex(Mutex* mutex){
	this->mutexFlowMeter = mutex;
}

void TaskFlowMeter::setPriority(osPriority priority){
	this->priority = priority;
}

void TaskFlowMeter::setStackSize(uint32_t stackSize){
	this->stack_size = stackSize;
}

void TaskFlowMeter::setStackPointer(unsigned char* stackPointer){
	this->stack_pointer = stackPointer;
}

void TaskFlowMeter::setState(TASK_STATE taskState){
	this->state = taskState;
}

TASK_STATE  TaskFlowMeter::getState(){
	return this->state;
}