Web controlled temp logger

I have a temp logger running on my Raspberry Pi and a Python script to show the data, running Apache on it.

I want to also use the same system to send commands to other Arduinos from a web interface. The temp modules are using RF24Network to send their info back to the Pi which logs it in a database.

My C TempReceiver program runs on the Pi. Any ideas how I could extend it to receive from a web interface and then send commands to another Arduino?

My C TempReceiver program runs on the Pi.

So, not on an Arduino, and you haven't shown any code.

Any ideas how I could extend it to receive from a web interface and then send commands to another Arduino?

What is "it" that you want to extend? The code you didn't show that doesn't run on an Arduino? Have you tried asking at Safeway?

What is Safeway?

I can post the code if you want. It's very similar to the RF24Network code on the Arduino for receiving data over the network, just a loop that checks for data on the RF24 network then writes it to the database.

I've seen examples that run a program via a web interface to send a command to an Arduino but don't know how to run that along side what I have running now.

What is Safeway?

A local grocery store chain. About as relevant to this discussion as the Pi. This is the Arduino forum.

There is a possibility that we could help you anyway, if we saw some code.

Without any code, all we see is you waving your arms uselessly.

Sure, why not. Google is your friend

PaulS:
A local grocery store chain. About as relevant to this discussion as the Pi. This is the Arduino forum.

Haha. They're not around in the UK anymore.

Anyway, I've finally got around to tidying up and refactoring my code so hopefully it makes some sense.

int main(int argc, char** argv) 
{
	int rc = sqlite3_open(dbPath, &db);
	// If rc is not 0, there was an error
	if(rc)
	{
		fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
		exit(0);
	}
	
	radio.begin();
	delay(5);
	network.begin( 90, this_node);
	radio.printDetails();
	
	while(keepRunning)
	{
		network.update();
		while ( network.available() ) 
		{			
			RF24NetworkHeader header;
			network.peek (header);
			
			payload_t payload;
			network.read(header,&payload,sizeof(payload));
			
			//Save data to database/files
			saveTempData(payload);
		}
		usleep(100000);
	}
	sqlite3_close(db);
	return 0;
}


void saveTempData(payload_t payload)
{
	//Save temperature to database
	recordTemp(payload.deviceNum, payload.temp);

	//
	float battVolts=0;
	
	//Open correct file for saving data
	if (payload.deviceNum==1)
	{
		f = fopen( "/home/pi/temp1.log", "a");
	}
	if (payload.deviceNum==2)
	{
		f = fopen( "/home/pi/temp2.log", "a");
		battVolts = payload.voltage * 0.001;
	}
	if (payload.deviceNum==3)
	{
		f = fopen( "/home/pi/temp3.log", "a");
	}
	if (payload.deviceNum==4)
	{
		f = fopen( "/home/pi/temp4.log", "a");
	}
	if (payload.deviceNum==5)
	{
		f = fopen( "/home/pi/temp5.log", "a");
	}
	if (payload.deviceNum==6)
	{
		f = fopen( "/home/pi/temp6.log", "a");
	}
	
	//Write data to screen
	printf("Received payload # %i at %f", payload.deviceNum,payload.temp);
	
	if (battVolts > 0)
		printf(" %fV \n", battVolts);
	else
		printf("\n");
	
	
	//Work out current time
	timeval curTime;
	gettimeofday(&curTime, NULL);

	char TimeString[128];

	strftime(TimeString, 80, "%Y-%m-%d %H:%M:%S", localtime(&curTime.tv_sec));

	char deviceNum[1];
	sprintf(deviceNum, "%i", payload.deviceNum);
	fprintf(f, deviceNum);
	fprintf(f, ",");

	char temp[4];
	sprintf(temp, "%f", payload.temp);
	fprintf(f, TimeString);
	fprintf(f, ",");
	fprintf(f, temp);


	if (payload.voltage>0)
	{
		fprintf(f, ",");
		char volts[4];
		sprintf(volts, "%f", battVolts);
		fprintf(f, volts);
	}

	fprintf(f, "\r\n");
	fclose(f);
}

So currently what I have is a wireless Arduino temperature module sending data to the Pi every minute or so. The Pi has the TempReceiver program looping waiting for data then saves it to a database and to a file. Apache running on the Pi displays the data in a graph in a web page.

What I'd like to add is the ability to control other devices through a web interface on the Pi. So using the same RF24 module on the Pi have a button on a web page that can send a signal to the boiler, light, whatever, and switch it on/off.

I've seen an example that runs a program program on the Pi every time a button on a web page is pressed to send a signal, but I already have my TempReceiver running accessing the radio.

So using the same RF24 module on the Pi have a button on a web page that can send a signal to the boiler, light, whatever, and switch it on/off.

Your boiler is connected to the internet? Send me it's URL. I want to run your heating bill up. :slight_smile:

PaulS:
Your boiler is connected to the internet? Send me it's URL. I want to run your heating bill up. :slight_smile:

Haha, no not yet. I think maybe it should be password protected if I give access to the outside world. My graph of temp values is only accessible on my network.