Skip to content

Commit ad0089e

Browse files
author
JP
committed
split do433() into GUID=0 and GUID=1 for V12 and V11 respectively, README
for more
1 parent 1aa3d4d commit ad0089e

File tree

6 files changed

+3585
-81
lines changed

6 files changed

+3585
-81
lines changed

Ninja/Ninja.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
// This part defines which version to use when compile
55
// Only one define is allowed.
66

7-
#define V11 1
8-
//#define V12 1
9-
#define VERSION_NO "040"
7+
//#define V11 1
8+
#define V12 1
9+
#define VERSION_NO "041"
1010

1111
#if defined(V12) && defined(V11)
1212
#error Please select only a version by setting either V11 or V12.

NinjaObjects/NinjaObjects.cpp

Lines changed: 32 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -279,31 +279,6 @@ void NinjaObjects::doReactors()
279279
{
280280
if(decodeJSON())
281281
{
282-
// Print out decoded Params
283-
/*
284-
Serial.println();
285-
Serial.print("GUID=");
286-
Serial.print(strGUID);
287-
Serial.print(",");
288-
289-
Serial.print("VID=");
290-
Serial.print(intVID);
291-
Serial.print(",");
292-
293-
Serial.print("DID=");
294-
Serial.print(intDID);
295-
Serial.print(",");
296-
297-
Serial.print("DATA=");
298-
299-
if (IsDATAString)
300-
Serial.println(strDATA);
301-
else
302-
Serial.println(intDATA);
303-
304-
Serial.println();
305-
*/
306-
307282
if(intVID==0) // VID 0 is reserved for Ninja Blocks
308283
{
309284
switch (intDID)
@@ -327,10 +302,9 @@ void NinjaObjects::doReactors()
327302

328303
BLUE_LED_VALUE = int((colorVal&0x0000ff)>>0);
329304
analogWrite(BLUE_LED_PIN, 255-BLUE_LED_VALUE);
330-
#endif
305+
#endif
331306

332307
doJSONResponse();
333-
// memset(strDATA,0, DATA_LEN);
334308
break;
335309
}
336310

@@ -360,7 +334,6 @@ void NinjaObjects::doReactors()
360334
mySwitch.send(strDATA);
361335
mySwitch.disableTransmit();
362336
doJSONResponse();
363-
//memset(strDATA,0, DATA_LEN);
364337
break;
365338
}
366339

@@ -669,58 +642,46 @@ void NinjaObjects::doLacrosseWS2355(unsigned long long ws2344value)
669642
checksum=checksum & 0xf;
670643
if ((nibble[0]==0x9) && (nibble[11]==checksum))
671644
{
672-
// good packet
673-
674645
byte SensorAddress = (nibble[2]<<4) + nibble[3];
675646
sprintf(strAddress,"%X", SensorAddress);
676647
byte Type = nibble[1] & 0x3;
677648

678649
switch(Type)
679650
{
680-
case 0:
651+
case 0: // temperature in Celsius
681652
double temperature;
682653
temperature =nibble[6] *100;
683654
temperature +=nibble[7] *10;
684655
temperature +=nibble[8];
685656
temperature =(temperature-300)/10;
686657
doJSONData(strAddress, 0, 20, NULL, temperature, false);
687-
//Serial.print (" Temp=");
688-
//printDouble(temperature,1);
689658
break;
690-
case 1:
659+
660+
case 1: // humidity in %
691661
int humidity;
692662
humidity = nibble[6]*10;
693663
humidity += nibble[7];
694664
doJSONData(strAddress, 0, 21, NULL, humidity, false);
695-
//Serial.print(" Humidity=");
696-
//Serial.print(humidity);
697665
break;
698-
case 2:
666+
667+
case 2: // total rainfall in mm
699668
double rainfall;
700669
rainfall = nibble[6]<<8;
701670
rainfall += nibble[7]<<4;
702671
rainfall += nibble[8];
703672
rainfall = (rainfall*518)/1000;
704673
doJSONData(strAddress, 0, 22, NULL, rainfall, false);
705-
//Serial.print(" Rainfall=");
706-
//printDouble(rainfall,2);
707-
//Serial.print("mm");
708674
break;
709-
case 3:
675+
676+
case 3: // wind direction in NSEW and wind spped in KMH
710677
double windspeed;
711678
windir = (byte)nibble[8];
712679
windspeed = (nibble[5] & 0x1)<<8;
713680
windspeed += nibble[6]<<4;
714681
windspeed += nibble[7];
715682
windspeed =(windspeed/10)*3.6;
716683
doJSONData(strAddress, 0, 23, (char *)strWindDirection[windir], 0, true);
717-
718684
doJSONData(strAddress, 0, 24, NULL, windspeed, false);
719-
//Serial.print(" Wind ");
720-
//Serial.print( strWindDirection[windir]);
721-
//Serial.print(" ");
722-
//printDouble(windspeed,1);
723-
//Serial.print("KMH");
724685
break;
725686

726687
default:
@@ -743,7 +704,13 @@ void NinjaObjects::do433(void)
743704
unsigned long long value = mySwitch.getReceivedValue();
744705
if (value == 0) // unknown encoding
745706
{
707+
#ifdef V11
708+
doJSONData("1", 0, tempID, "0", 0, true);
709+
#endif
710+
711+
#ifdef V12
746712
doJSONData("0", 0, tempID, "0", 0, true);
713+
#endif
747714
}
748715
else
749716
{
@@ -757,17 +724,29 @@ void NinjaObjects::do433(void)
757724
else
758725
{
759726
if (mySwitch.getReceivedBitlength()> (DATA_LEN/2))
727+
#ifdef V11
728+
doJSONData("1", 0, tempID, "0", 0, true);
729+
#endif
730+
731+
#ifdef V12
760732
doJSONData("0", 0, tempID, "0", 0, true);
733+
#endif
761734
else
762735
{
763736
dec2binWzerofill(strDATA, mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength());
737+
#ifdef V11
738+
doJSONData("1", 0, tempID, strDATA, 0, true);
739+
#endif
740+
741+
#ifdef V12
764742
doJSONData("0", 0, tempID, strDATA, 0, true);
743+
#endif
765744
}
766745
}
767746
}
768747
mySwitch.resetAvailable();
769748
}
770-
else
749+
//else
771750
//doJSONData("0", 0, tempID, "-1", 0, true);
772751

773752
if (Serial.available()>0) doReactors();
@@ -808,34 +787,9 @@ boolean NinjaObjects::doPort1(byte* DHT22_PORT)
808787
#ifdef V11
809788
else if(tempID==11) // 433Mhz Receiver
810789
{
790+
if(_lastPort1ID != tempID)
791+
doJSONData("1",0,tempID, "-1",0,true);
811792
do433();
812-
/*
813-
if (mySwitch.available())
814-
{
815-
int value = mySwitch.getReceivedValue();
816-
if (value == 0) // unknown encoding
817-
{
818-
doJSONData("1", 0, tempID, "0", 0, true);
819-
}
820-
else
821-
{
822-
// Blink Green LED to show data valid
823-
blinkLED(GREEN_LED_PIN);
824-
//String recvSTR = String(mySwitch.getReceivedValue(), BIN);
825-
//recvSTR.toCharArray(strDATA, DATA_LEN);
826-
if (mySwitch.getReceivedBitlength()> (DATA_LEN/2))
827-
doJSONData("1", 0, tempID, "0", 0, true);
828-
else
829-
{
830-
dec2binWzerofill(strDATA, mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength());
831-
doJSONData("1", 0, tempID, strDATA,0, true);
832-
}
833-
}
834-
mySwitch.resetAvailable();
835-
}
836-
else
837-
doJSONData("1", 0, tempID, "-1", 0, true);
838-
*/
839793
}
840794
#endif
841795
else
@@ -866,7 +820,7 @@ boolean NinjaObjects::doPort2(byte* DHT22_PORT)
866820
}
867821
else
868822
{
869-
if (tempID>-1)
823+
if ((tempID>-1) && (tempID !=11))
870824
{
871825
if (tempID==0)
872826
doJSONData("2", 0, tempID, NULL, getIDPinReading(ID_PIN_P2),false);
@@ -899,7 +853,7 @@ boolean NinjaObjects::doPort3(byte* DHT22_PORT)
899853
}
900854
else
901855
{
902-
if (tempID>-1)
856+
if ((tempID>-1) && (tempID !=11))
903857
{
904858
if (tempID==0)
905859
doJSONData("3", 0, tempID, NULL, getIDPinReading(ID_PIN_P3), false);
@@ -946,7 +900,7 @@ void NinjaObjects::sendObjects()
946900
byte DHT22_PORT=0;
947901

948902
#ifdef V11
949-
//doOnBoardAccelerometer();
903+
doOnBoardAccelerometer();
950904
#endif
951905

952906
#ifdef V12

NinjaObjects/README

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Based on the aJson example from http://interactive-matter.eu/how-to/ajson-arduin
77
- changed doDHT22() to continue poll data when first plugin until valid before obeying the heartbeat delay
88
- tidied doPort1(), doPort2() and doPort3() when dealing with DHT22
99
- disabled DHT22 from sending -99 or 0
10+
- cleaned commented codes
11+
- enabled accelerometer for V11 after testing
12+
- split do433() into GUID=0 and GUID=1 for V12 and V11 respectively
1013

1114
17th August 2012 by JP Liew
1215
- added support for LaCrosse WS2355 protocol for emp, humidity, rain, wind, win direction

README

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Ninja Blocks Arduino Source Code.
22
Developed by www.ninjablocks.com based on Arduino and other Open Source libraries.
33

4+
Version 0.41: 20th August 2012 by JP Liew
5+
- cleaned commented codes
6+
- enabled accelerometer for V11 after testing
7+
- split do433() into GUID=0 and GUID=1 for V12 and V11 respectively
8+
49
Version 0.40: 20th August 2012 by JP Liew
510
- changed doOnBoardRGB(), doOnBoardTemperature(), doDHT22() to slow down to 30 seconds per update
611
- changed doDHT22() to continue poll data when first plugin until valid before obeying the heartbeat delay

0 commit comments

Comments
 (0)