static void *handleTemperaturePressure (void *data)
{
	double temperature;
	double pressure;
	time_t sec;
	double sample = 1200; //trigger time (second) for trend 
	time_t initial = time (NULL) ;
	double delta ;

	for (;;){
		if(bmp085_Calibration(fd) > 0 ){
			temperature = bmp085_GetTemperature(bmp085_ReadUT(fd));
			sleep(1);
			pressure = bmp085_GetPressure(bmp085_ReadUP(fd));
			int press = round(pressure/100);
			int temp = round(temperature/10);
			updateTemp (temp) ;
			updatePressure (press) ;
			sleep(4) ; //Wait 4s to avoid concurrent access
  			sec = time (NULL);
  			delta = difftime(sec,  initial);
   			if (delta > sample ){
  				trend (press);
				initial = time(NULL);
				sleep (1);
			}
		}	
		sleep (2);
	}
	return 0;
}
Example #2
0
int initialise() {

	setbuf(stdout, NULL);
		
	if (initialiseDS18B20() == 0)
		return 0;

	if (initialiseMCP3008() == 0)
		return 0;

	if (initialiseGPS() == 0)
		return 0;

	if (initialiseGeiger() == 0)
		return 0;

	bmp085_Calibration();

	return 1;
}
Example #3
0
int main(int argc, char **argv)
{
	char spin[] = "-\\|/", SequenceCount = 'a';
	char Message[65], Data[100], upload_exclude[200], Command[200], Telemetry[100], *Bracket, *Start;
	int Bytes, Sentence_Count, sc = 0;
	double Latitude, Longitude;
	unsigned int Altitude;
	uint8_t opmode, flags1, flags2, old_opmode = 0, old_flags1 = 0, old_flags2 = 0;
	const char *inifile = "gateway.ini"; // FIXME
	float node_lat, node_lon;
	time_t next_beacon;
	bool bmp085, xap;

	/* load configuration */
	ini_gets("node", "id", "", node_id, sizeof(node_id), inifile);
	node_lat = ini_getf("node", "lat", 999, inifile);
	node_lon = ini_getf("node", "lon", 999, inifile);
	bmp085 = ini_getbool("sensors", "bmp085", false, inifile);
	xap = ini_getbool("xap", "enabled", false, inifile);
	ini_gets("upload", "exclude", "", upload_exclude, sizeof(upload_exclude), inifile);
	
	if (strlen(node_id) == 0) {
		puts("Node ID has not been specified");
		exit(1);
	}

	printf("Upload exclude list is \"%s\"\n", upload_exclude);

	if (xap) {
		xapInit();
	}

	if (node_lat < 900 && node_lon < 900) {
		/* put the gateway on the map */
		sprintf(Message,"0aL%f,%f:%s[%s]", node_lat, node_lon, GIT_VER, node_id);
	} else {
		sprintf(Message,"0a:%s[%s]", GIT_VER, node_id);
	}

	UploadPacket(Message,0);
	if (xap) {
		xapSendPacket(Message, 0);
	}

	if (bmp085) {
		next_beacon = time(NULL) + 10;
		printf("Initialising BMP085\n");
		bmp085_Calibration();
	}

	printf("Initialising RFM69\n");

	setupRFM69();
	
	printf("Starting main loop ...\n");

	Sentence_Count = 0;

	while (1)
	{
		if (rfm69_available())
		{
			Bytes = rfmM69_recv(Message, sizeof(Message));
			printf ("%s Data available - %d bytes\n", Now(), Bytes);
			printf ("rx: %s|%d\n", Message,RFM69_lastRssi());

			if (Bytes > 0)
			{
				if (!excluded(Message, upload_exclude)) {
					// UKHASNet upload
					UploadPacket(Message, RFM69_lastRssi());
				}

				if (xap) {
					// xAP broadcast
					xapSendPacket(Message, RFM69_lastRssi());
				}
#if 0
				// Habitat upload
				// 3dL51.95023,-2.54445,155[DA1]
				if (strstr(Message, "DA1"))
				{
					if (Start = strchr(Message, 'L'))
					{
						// DA1,2,19:35:37,51.95023,-2.54445,160*05%0A

						if (sscanf(Start+1, "%lf,%lf,%u[", &Latitude, &Longitude, &Altitude))
						{
							printf("Altitude = %u\n", Altitude);
							sprintf(Telemetry, "%s,%d,%s,%lf,%lf,%u", "DA1", ++Sentence_Count, Now(), Latitude, Longitude, Altitude);
							sprintf(Command, "wget -O habitat.txt \"http://habitat.habhub.org/transition/payload_telemetry\" --post-data \"callsign=DA0&string=\\$\\$%s*%s%s&string_type=ascii&metadata={}\"",	Telemetry, Checksum(Telemetry), "\%0A");
							printf("%s\n", Command);
							system(Command);
						}
					}
				}
#endif
			}
		}
		else
		{