mirror of
https://github.com/formtapez/ZigUP.git
synced 2025-02-23 09:34:50 +01:00
sensor autodetection
This commit is contained in:
@@ -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
|
4. Load HEX-File and perform "Erase, program and verify" action
|
||||||
|
|
||||||
# Packet Sniffing using CC Debugger
|
# 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.
|
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"
|
3. Select protocol "IEEE 802.15.4/ZigBee" and click "Start"
|
||||||
4. Change radio channel and click "Start"
|
4. Change radio channel and click "Start"
|
||||||
|
|||||||
@@ -14,13 +14,15 @@ int DHT22_Measure(void)
|
|||||||
uint8 counter = 0;
|
uint8 counter = 0;
|
||||||
uint8 checksum = 0;
|
uint8 checksum = 0;
|
||||||
uint8 dht22_data[5];
|
uint8 dht22_data[5];
|
||||||
|
|
||||||
/*
|
//#define ZIGUP_DHT22_DEBUG
|
||||||
|
|
||||||
|
#ifdef ZIGUP_DHT22_DEBUG
|
||||||
uint8 dht22_debug[100];
|
uint8 dht22_debug[100];
|
||||||
uint8 debugcnt;
|
uint8 debugcnt;
|
||||||
for(debugcnt = 0; debugcnt < 100; debugcnt++) dht22_debug[debugcnt] = 0;
|
for(debugcnt = 0; debugcnt < 100; debugcnt++) dht22_debug[debugcnt] = 0;
|
||||||
debugcnt = 0;
|
debugcnt = 0;
|
||||||
*/
|
#endif
|
||||||
|
|
||||||
P0DIR |= (1<<7); // output
|
P0DIR |= (1<<7); // output
|
||||||
P0_7 = 1;
|
P0_7 = 1;
|
||||||
@@ -47,32 +49,35 @@ int DHT22_Measure(void)
|
|||||||
if((i >= 4) && ((i % 2) != 0))
|
if((i >= 4) && ((i % 2) != 0))
|
||||||
{
|
{
|
||||||
dht22_data[j / 8] <<= 1;
|
dht22_data[j / 8] <<= 1;
|
||||||
// dht22_debug[debugcnt++] = counter;
|
#ifdef ZIGUP_DHT22_DEBUG
|
||||||
if(counter > 20) // detect "1" bit time
|
dht22_debug[debugcnt++] = counter;
|
||||||
|
#endif
|
||||||
|
if(counter > 9) // detect "1" bit time
|
||||||
{
|
{
|
||||||
dht22_data[j / 8] |= 1;
|
dht22_data[j / 8] |= 1;
|
||||||
}
|
}
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char buffer[100];
|
char buffer[100];
|
||||||
/*
|
|
||||||
|
#ifdef ZIGUP_DHT22_DEBUG
|
||||||
sprintf(buffer, "j: %u", j);
|
sprintf(buffer, "j: %u", j);
|
||||||
UART_String(buffer);
|
UART_String(buffer);
|
||||||
|
|
||||||
for(i = 0; i < 5; i++)
|
for(i = 0; i < 5; i++)
|
||||||
{
|
{
|
||||||
sprintf(buffer, "DHT22: (%u) %u\n", i, dht22_data[i]);
|
sprintf(buffer, "DHT22: (%u) %u\n", i, dht22_data[i]);
|
||||||
UART_String(buffer);
|
UART_String(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(debugcnt = 0; debugcnt < 100; debugcnt++)
|
for(debugcnt = 0; debugcnt < 100; debugcnt++)
|
||||||
{
|
{
|
||||||
sprintf(buffer, "DHT22 Debug: (%u) %u\n", debugcnt, dht22_debug[debugcnt]);
|
sprintf(buffer, "DHT22 Debug: (%u) %u\n", debugcnt, dht22_debug[debugcnt]);
|
||||||
UART_String(buffer);
|
UART_String(buffer);
|
||||||
}
|
}
|
||||||
*/
|
#endif
|
||||||
|
|
||||||
// If we have 5 bytes (40 bits), wrap-up and end
|
// If we have 5 bytes (40 bits), wrap-up and end
|
||||||
if(j >= 40)
|
if(j >= 40)
|
||||||
|
|||||||
@@ -12,3 +12,5 @@ uint16 zclZigUPSeqNum=0;
|
|||||||
volatile uint32 S0=0;
|
volatile uint32 S0=0;
|
||||||
volatile uint8 STATE_LIGHT=0;
|
volatile uint8 STATE_LIGHT=0;
|
||||||
volatile uint8 STATE_LED=0;
|
volatile uint8 STATE_LED=0;
|
||||||
|
|
||||||
|
uint8 TEMP_SENSOR=0;
|
||||||
|
|||||||
@@ -12,3 +12,5 @@ extern uint16 zclZigUPSeqNum;
|
|||||||
extern volatile uint32 S0;
|
extern volatile uint32 S0;
|
||||||
extern volatile uint8 STATE_LIGHT;
|
extern volatile uint8 STATE_LIGHT;
|
||||||
extern volatile uint8 STATE_LED;
|
extern volatile uint8 STATE_LED;
|
||||||
|
|
||||||
|
extern uint8 TEMP_SENSOR;
|
||||||
|
|||||||
@@ -45,14 +45,13 @@ void Measure(void)
|
|||||||
ADC_Voltage = ADC_GetVoltage();
|
ADC_Voltage = ADC_GetVoltage();
|
||||||
CPU_Temperature = ADC_GetTemperature();
|
CPU_Temperature = ADC_GetTemperature();
|
||||||
|
|
||||||
if (!DHT22_Measure())
|
// invalidate old measurements
|
||||||
{
|
EXT_Temperature = -1000;
|
||||||
EXT_Humidity = -1000;
|
EXT_Humidity = -1000;
|
||||||
if (!ds18b20_get_temp())
|
|
||||||
{
|
// make new measurement depending of autodetected sensor type
|
||||||
EXT_Temperature = -1000;
|
if (TEMP_SENSOR == 1) DHT22_Measure();
|
||||||
}
|
else if (TEMP_SENSOR == 2) ds18b20_get_temp();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void zclZigUP_Reporting(void)
|
void zclZigUP_Reporting(void)
|
||||||
@@ -313,17 +312,23 @@ void zclZigUP_Init( byte task_id )
|
|||||||
// WS2812_SendLED(0, 0, 0);
|
// WS2812_SendLED(0, 0, 0);
|
||||||
UART_Init();
|
UART_Init();
|
||||||
|
|
||||||
if (P0_7) UART_String("Sensor: High.");
|
// autodetecting sensor type
|
||||||
else UART_String("Sensor: Low.");
|
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 );
|
// osal_start_reload_timer( zclZigUP_TaskID, ZIGUP_REPORTING_EVT, ZIGUP_REPORTING_INTERVAL );
|
||||||
|
|
||||||
|
|
||||||
UART_String("Init done.");
|
UART_String("Init done.");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
|
|||||||
Reference in New Issue
Block a user