Test your home made controller with MockMySensors (w/ tutorial)
-
@akbooer , just curious to know, what version of AltUI do you have? Did you adjust anything into the mySensors plugin json?
I'm asking that because, my plugin display a bit different:

Yes, I made a mod to the Arduino plugin. The changes are on GitHub:
https://github.com/akbooer/Vera/blob/features-for-altui/L_Arduino.lua
I'm hoping to get this merged with the master branch in due course, but I've not finished.
-
Yes, I made a mod to the Arduino plugin. The changes are on GitHub:
https://github.com/akbooer/Vera/blob/features-for-altui/L_Arduino.lua
I'm hoping to get this merged with the master branch in due course, but I've not finished.
-
Hi Folks,
@GizMoCuz just commited a new version of MockMySensors and I'm about to commit another (MockMySensors.ino) (need to merge with his changes).
This will complete the 1.4 lib sensors and Giz has already started adding more.
In the mean time here is a picture of MockMySensors running on the MYSController

And here is how it look on the HAALL controller

If you have used this skecth in other controller would you mind posting screen shots of it here?
Cheers
-
Hello, is it possible to MockMySensors without physical radio on the gateway?
I ordered/received wrong radios and I am now waiting (most likely a month) for the new ones, but I would like to setup the controller without actual sensors. How can I mock them, or somehow simulate sensors without the radio?
Thanks -
Depending on what you want to run your controller on, and your own experience level with hacking stuff, you can use node-red to simulate sensors, and inject fake sensors into the controller of your choice. (Not all controllers support this though)
head over to http://forum.mysensors.org/topic/1965/nodered-injected-between-domoticz-and-mysensors for more info on setup..
-
Hello, is it possible to MockMySensors without physical radio on the gateway?
I ordered/received wrong radios and I am now waiting (most likely a month) for the new ones, but I would like to setup the controller without actual sensors. How can I mock them, or somehow simulate sensors without the radio?
ThanksI use nodeJS to read from the serial gatweay and send the information to my my controller HAALL, similar to what @tbowmo is suggesting.
Now depending on how your controller accepts information you might pull this off with some hacking. (In HAALL case it accepts via REST service). I've attached my nodeJS example for convenience.
Cheers
-
Thank you. I installed MajorDoMo controller on a old laptop, just because it is written in php - which I do professionally so that I could optimize or debug it. And it looks decent too :)
I just started with the MySensors and Arduino so I guess it will take me some time to get familiar with how everything works.My initial idea was to just use mockMySensors without radio and other sensors, but when I try initiate MySensors lib on the arduino I get "radio init fail" which is expected as I do not have the radio attached (it will arrive soon).
I messed a bit inside MySensors library, trying to comment out the part that initializes the radio but then I get some other messages. I guess it is never needed in practice to turn off radio portion of MySensors.Maybe my question is more related to Network Stress test thread http://forum.mysensors.org/topic/2000/mysensors-network-stress-test on which I also get the same "radio init fail" message, as again radio is missing.
If I find the time I will try to make some software emulation for sensors, based on your NodeJS example. That could be useful for prepping the Controller before even making new sensors, also for simulating scenarios and test how would controller react in certain situations (how different scenes work etc).
-
The mock example is written to use radio communications. Can be pretty hairy to fix it. Suggest you run the development branch which allows sensors to be attached to gateway. It should run twith the mock example if you configure it as a serial gateway (radio disabled).. See Serial Gateway example for how to activate gateway.
Here is a couple of nodejs modules that might be helpful:
http://forum.mysensors.org/topic/2208/node-js-modules-for-mysensors -
Hi Folks,
The guys at MySensors were kind to convert this to 1.6 lib.
So being back in Europe for the holidays I decided to create a post with some explanations/tutorial about the code.
This example MockMySensors from the MySensors examples actually combines 30 sensors in a single node.
It may have a poor architecture but it will give you an idea of how to combine sensors and with some feedback we can always improve on the architecture.
It has been designed for you to customize it for the sensor you want to test by uncomment the initial lines.
This line defines your NODE ID, you can always change it to AUTO or to your specification
#define MY_NODE_ID 254This part of the code defines the sensors you want to work with and their ids
#define ID_S_ARMED 0 // dummy to controll armed stated for several sensors #define ID_S_DOOR 1 //#define ID_S_MOTION 2 //#define ID_S_SMOKE 3 //#define ID_S_LIGHT 4 //#define ID_S_DIMMER 5 //#define ID_S_COVER 6 //#define ID_S_TEMP 7 //#define ID_S_HUM 8 //#define ID_S_BARO 9 ... code lines snipped ... //#define ID_S_MOISTURE 33 // //#define ID_S_CUSTOM 99This part of the code defines the messages you want to instantiate to work with your sensors
#ifdef ID_S_DOOR // V_TRIPPED, V_ARMED MyMessage msg_S_DOOR_T(ID_S_DOOR,V_TRIPPED); MyMessage msg_S_DOOR_A(ID_S_DOOR,V_ARMED); #endif #ifdef ID_S_MOTION // V_TRIPPED, V_ARMED MyMessage msg_S_MOTION_A(ID_S_MOTION,V_ARMED); MyMessage msg_S_MOTION_T(ID_S_MOTION,V_TRIPPED); #endif #ifdef ID_S_SMOKE // V_TRIPPED, V_ARMED MyMessage msg_S_SMOKE_T(ID_S_SMOKE,V_TRIPPED); MyMessage msg_S_SMOKE_A(ID_S_SMOKE,V_ARMED); #endif #ifdef ID_S_LIGHT MyMessage msg_S_LIGHT(ID_S_LIGHT,V_LIGHT); bool isLightOn=0; #endif ... code lines snipped ... #ifdef ID_S_MOISTURE // To be implemented #endifOn the presentation section, you have all the sensors being presented, along with some debugging
void presentation() { #ifdef ID_S_DOOR Serial.println(" S_DOOR"); present(ID_S_DOOR,S_DOOR,"Outside Door"); wait(SHORT_WAIT); #endif #ifdef ID_S_MOTION Serial.println(" S_MOTION"); present(ID_S_MOTION,S_MOTION,"Outside Motion"); wait(SHORT_WAIT); #endif #ifdef ID_S_SMOKE Serial.println(" S_SMOKE"); present(ID_S_SMOKE,S_SMOKE,"Kitchen Smoke"); wait(SHORT_WAIT); #endif ... code lines snipped ... #ifdef ID_S_CUSTOM Serial.println(" S_CUSTOM"); present(ID_S_CUSTOM,S_CUSTOM,"Other Stuff"); wait(SHORT_WAIT); #endifOn the loop section you have methods which will trigger each sensor to report. This will happen periodically on the SLEEP_TIME, 15 minutes by default
void loop()[ //Read Sensors #ifdef ID_S_DOOR door(); #endif #ifdef ID_S_MOTION motion(); #endif #ifdef ID_S_SMOKE smoke(); #endif ... code lines snipped ... #ifdef ID_S_CUSTOM custom(); #endifLets take a look at one of them, the dimmer. As you can see its just reporting the dimmerVal which was declared as a global variable.
Sometimes these values are saved in the EPROM, for this example I wanted to avoid that.#ifdef ID_S_DIMMER void dimmer(){ Serial.print("Dimmer is set to: " ); Serial.println(dimmerVal); send(msg_S_DIMMER.set(dimmerVal)); } #endifFinally the incoming message section.
void receive(const MyMessage &message) { ... code lines snipped ... #ifdef ID_S_DIMMER case V_DIMMER: if ((message.getInt()<0)||(message.getInt()>100)) { Serial.println( "V_DIMMER data invalid (should be 0..100)" ); break; } dimmerVal= message.getInt(); Serial.print("Incoming change for ID_S_DIMMER:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getInt()); dimmer();// temp ack break; #endif ... code lines snipped ...The temp ack mean I'm just forcing the sensor to report back the new value to the controller.
And this is basically what it takes to combine sensors in the MySensors library.
One node can have many sensors and each sensor can receive any number or combinations of messages.
So for the dimmer example
#define ID_S_DIMMER 5 ... code lines snipped ... #ifdef ID_S_DIMMER MyMessage msg_S_DIMMER(ID_S_DIMMER,V_DIMMER); int dimmerVal=100; #endif ... code lines snipped ... void presentation() { ... code lines snipped ... #ifdef ID_S_DIMMER Serial.println(" S_DIMMER"); present(ID_S_DIMMER,S_DIMMER,"Living room dimmer"); wait(SHORT_WAIT); #endif ... code lines snipped ...There is nothing stoping me to add another message type to the dimmer. So for example if the dimmer does have an on/off button I could add
MyMessage msg_S_DIMMER_BUTTON(ID_S_DIMMER,V_STATUS)Note that your controller might not be expecting all this freedom of combinations of messages.
So although I could report a temperature on a dimmer sensor using
MyMessage msg_S_DIMMER_BUTTON(ID_S_DIMMER,V_TEMP)Your controller might not like it.
As always feddback is welcome
Cheers