sensor autodetection

This commit is contained in:
formtapez
2019-05-05 20:04:28 +02:00
parent 264f952c4e
commit c419b35a08
5 changed files with 44 additions and 30 deletions

View File

@@ -46,7 +46,7 @@ CC2530 based multi-purpose ZigBee Relais, Switch, Sensor and Router
4. Load HEX-File and perform "Erase, program and verify" action
# Packet Sniffing using CC Debugger
1. Get **PACKET-SNIFFER v2.18.1 (not SNIFFER-2 v1.x!)** from http://www.ti.com/tool/PACKET-SNIFFER
1. Get **PACKET-SNIFFER v2.18.1 (not SNIFFER-2 v1.x!)** from https://www.ti.com/tool/PACKET-SNIFFER
2. Connect CC Debugger to the Debug-Port of ZigUP with an 1:1 cable.
3. Select protocol "IEEE 802.15.4/ZigBee" and click "Start"
4. Change radio channel and click "Start"

View File

@@ -14,13 +14,15 @@ int DHT22_Measure(void)
uint8 counter = 0;
uint8 checksum = 0;
uint8 dht22_data[5];
/*
//#define ZIGUP_DHT22_DEBUG
#ifdef ZIGUP_DHT22_DEBUG
uint8 dht22_debug[100];
uint8 debugcnt;
for(debugcnt = 0; debugcnt < 100; debugcnt++) dht22_debug[debugcnt] = 0;
debugcnt = 0;
*/
#endif
P0DIR |= (1<<7); // output
P0_7 = 1;
@@ -47,32 +49,35 @@ int DHT22_Measure(void)
if((i >= 4) && ((i % 2) != 0))
{
dht22_data[j / 8] <<= 1;
// dht22_debug[debugcnt++] = counter;
if(counter > 20) // detect "1" bit time
#ifdef ZIGUP_DHT22_DEBUG
dht22_debug[debugcnt++] = counter;
#endif
if(counter > 9) // detect "1" bit time
{
dht22_data[j / 8] |= 1;
}
j++;
}
}
char buffer[100];
/*
#ifdef ZIGUP_DHT22_DEBUG
sprintf(buffer, "j: %u", j);
UART_String(buffer);
for(i = 0; i < 5; i++)
{
sprintf(buffer, "DHT22: (%u) %u\n", i, dht22_data[i]);
UART_String(buffer);
}
sprintf(buffer, "DHT22: (%u) %u\n", i, dht22_data[i]);
UART_String(buffer);
}
for(debugcnt = 0; debugcnt < 100; debugcnt++)
{
sprintf(buffer, "DHT22 Debug: (%u) %u\n", debugcnt, dht22_debug[debugcnt]);
UART_String(buffer);
}
*/
sprintf(buffer, "DHT22 Debug: (%u) %u\n", debugcnt, dht22_debug[debugcnt]);
UART_String(buffer);
}
#endif
// If we have 5 bytes (40 bits), wrap-up and end
if(j >= 40)

View File

@@ -12,3 +12,5 @@ uint16 zclZigUPSeqNum=0;
volatile uint32 S0=0;
volatile uint8 STATE_LIGHT=0;
volatile uint8 STATE_LED=0;
uint8 TEMP_SENSOR=0;

View File

@@ -12,3 +12,5 @@ extern uint16 zclZigUPSeqNum;
extern volatile uint32 S0;
extern volatile uint8 STATE_LIGHT;
extern volatile uint8 STATE_LED;
extern uint8 TEMP_SENSOR;

View File

@@ -45,14 +45,13 @@ void Measure(void)
ADC_Voltage = ADC_GetVoltage();
CPU_Temperature = ADC_GetTemperature();
if (!DHT22_Measure())
{
EXT_Humidity = -1000;
if (!ds18b20_get_temp())
{
EXT_Temperature = -1000;
}
}
// invalidate old measurements
EXT_Temperature = -1000;
EXT_Humidity = -1000;
// make new measurement depending of autodetected sensor type
if (TEMP_SENSOR == 1) DHT22_Measure();
else if (TEMP_SENSOR == 2) ds18b20_get_temp();
}
void zclZigUP_Reporting(void)
@@ -313,17 +312,23 @@ void zclZigUP_Init( byte task_id )
// WS2812_SendLED(0, 0, 0);
UART_Init();
if (P0_7) UART_String("Sensor: High.");
else UART_String("Sensor: Low.");
// autodetecting sensor type
if (DHT22_Measure())
{
TEMP_SENSOR = 1;
UART_String("Sensor type DHT22 detected.");
}
else if (ds18b20_get_temp())
{
TEMP_SENSOR = 2;
UART_String("Sensor type DS18B20 detected.");
}
else UART_String("No sensor detected.");
// osal_start_reload_timer( zclZigUP_TaskID, ZIGUP_REPORTING_EVT, ZIGUP_REPORTING_INTERVAL );
UART_String("Init done.");
}
/*********************************************************************