jimh

Recent activity

Posted in odd behaviour with two subscribers

Hi Alain,

Added the fix to nocanc_ll.c and can confirm the code now acts as expected. I will continue to test and if any issues show up I will let you know.

Best regards,
Jim

Started odd behaviour with two subscribers

Hi Alain,

As the testing continues I have come across another odd piece of behaviour which I am not sure is a coding problem or something else.

This is the code I have been testing:

/*
Name: nctemp.ino
Created: 12/22/2018 11:20:15 AM
Author: jimha
*/

#include #include #include #include #include #include #include

#define DHTPIN 2 // Pin which is connected to the DHT sensor.

// Uncomment the type of sensor in use:
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

// See guide for details on sensor wiring and usage:
// https://learn.adafruit.com/dht/overview

DHT_Unified dht(DHTPIN, DHTTYPE);

const int ledPin = LED_BUILTIN;
// Variables will change:
//int ledState = LOW; // ledState used to set the LED

String sensoreName;

NocanChannelId tid; // temperature
NocanChannelId hid; // humidity
NocanChannelId lid; // led
NocanChannelId mid; // motion

Timer<> timer;

bool read_sensors(void *) {

sensors_event_t event;

dht.temperature().getEvent(&event);
if (isnan(event.temperature)) {
	// error handler
}
else {

	String temp_string;

	temp_string = String(event.temperature, 2);            // transform temp into string

	Nocan.publishMessage(tid, temp_string.c_str());        // publish to the network
}

// Get humidity event and print its value.
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity)) {
	// error handler
}
else {

	String temp_string;

	temp_string = String(event.relative_humidity, 2);      // transform humidty into string

	Nocan.publishMessage(hid, temp_string.c_str());        // publish to the network

}

return true; // repeat? true }

// move message processing to its own function
void process_msg() {

NocanMessage msg;

int8_t status = Nocan.receiveMessage(&msg);

if (status == 0)
{
	
	if (msg.channel_id == lid)   // handle the led message
	{
		if (msg.data[0] == 'c' || msg.data[0] == '1')
			digitalWrite(ledPin, HIGH);
		if (msg.data[0] == 'o' || msg.data[0] == '0')
			digitalWrite(ledPin, LOW);
	}
	else if (msg.channel_id == mid)  // handle the motion message - way setup this should turn the led on but not off on motion msg
	{
		if (msg.data[0] == 'c' || msg.data[0] == '1')
			digitalWrite(ledPin, HIGH);
		if (msg.data[0] == 'o' || msg.data[0] == '0')
			digitalWrite(ledPin, LOW);
	}
} }

// the setup function runs once when you press reset or power the board
void setup() {

// set the digital pin as output:
pinMode(ledPin, OUTPUT);

// Initialise Nocan
for (;;)
{
	if (Nocan.open() >= 0)
		break;  // Nocan open success
	delay(1000);
}

int8_t lookUpStatus;
// lookup channel name and register if not found
lookUpStatus = Nocan.lookupChannel("myled", &lid);
if (lookUpStatus < 0) { // lookup a failed, channel not registered
	Nocan.registerChannel("myled", &lid);
}

lookUpStatus = Nocan.lookupChannel("temperature", &tid);
if (lookUpStatus < 0) { // lookup a failed, channel not registered
	Nocan.registerChannel("temperature", &tid);
}

lookUpStatus = Nocan.lookupChannel("humidity", &hid);
if (lookUpStatus < 0) { // lookup a failed, channel not registered
	Nocan.registerChannel("humidity", &hid);
}

lookUpStatus = Nocan.lookupChannel("motion", &mid);
if (lookUpStatus < 0) { // lookup a failed, channel not registered
	Nocan.registerChannel("motion", &mid);
}

// subscribe to channels of interest
Nocan.subscribeChannel(lid);
Nocan.subscribeChannel(mid);

// Initialize sensor device.
dht.begin();
sensor_t sensor;
sensoreName = sensor.name;

// call the read_sensors function every 60 seconds
timer.every(60000, read_sensors);

}

// the loop function runs over and over again until power down or reset
void loop() {

timer.tick(); // tick the timer

if (Nocan.receivePending())
{
	process_msg();
} }

If I comment out this block:

lookUpStatus = Nocan.lookupChannel("motion", &mid);
if (lookUpStatus < 0) { // lookup a failed, channel not registered
	Nocan.registerChannel("motion", &mid);
}

The built-in led responds to
nocanc publish myled 1/0 but won't respond to nocanc publish motion 0/1

If I uncomment the block the reverse occurs:

The built-in led responds to
nocanc publish motion 1/0 but won't respond to nocanc publish myled 0/1

It is like only the last workable subscribe actually works.

Is the process_msg function the right way to process channels to obtain the channel data in order to act differently to messages on on different channels that are subscribed? We need to be able to differentiate up to 12 subscribed channels.

The sensors are being read and published fine it is only the handling of the subscribed channels that is the current issue.

Best regards,
Jim

Started Allow nocanc to specify a config file

Hi Alain,

I have got nocand to run well as a demon process started by system on the raspberry pi. This has been running for the last 4-5 days without problems and I have used logrotate to keep the log files under control.

I would like to start nocanc the same way i.e. via system. To do so it would be really helpful to have a
-config option on nocanc to allow specific config files to be started. Allow the current default to work if the option is not specified by allow the option to override the default if used.

This way I can setup the nocand process and the mqtt and blynk nocanc process to start on boot.

An additional question relating to the config file entries: can the log-file etc options be placed in the config file? This would allow the startup lines in config files for system to shorter.

Best regards,

Jim

Posted in nocand abort

Hi Alain,

I have been testing the latest bits over the past 4-5 days and all looks with no further problems found.

Thanks.

Best regards,
Jim

Posted in nocanc option to display mapping between node and channel

Hi Alain,

Thanks for the update. Based on this information I can code or script the desired result. This will be enough for my needs.

Interestingly I could not find the ~/.nocand/cache file. On the raspberry pi hosting I have the .nocand directory but the only file is the config file.

Best regards,

Jim