Show Posts
Pages: [1] 2 3 ... 8
1  Using Arduino / Programming Questions / Re: Break/Stop loop with MQTT payload/message on: May 02, 2014, 01:25:01 am
You don't know It?
http://deluxevideoonline.org/wp-content/uploads/2013/10/it-laugh.jpg
 smiley-grin

With it i meant the none compiling part.
And i was now looking for 10 minutes on the screen to find out what was wrong.
strncmp instead of strcmp

Ok the output is if i send my commands in that order:
Quote
1. "volume-ups"
Payload: volume-ups
Message:
Output: Run Code

2. "volume-ups"
Payload: volume-ups
Message: volume-ups
Output: Run Code

3. "volume-stop"
Payload: volume-stop
Message: volume-ups
Output: Stop Code

4. "volume-stop"
Payload: volume-stop
Message:
Output: Stop Code

5. "volume-ups"
Payload: volume-ups
Message:

6.
Payload: volume-ups
Message: volume-upsp
So after "volume-stop" the output (code that needs to be running) is empty on "volume-up".
By other words i can't turn the volume up after stopping it before.
Look at 6. after calling "volume-ups" a second time there is a "p" at the end of the message.
Where does that come from?

And before i forged: THANKS for helping.
2  Using Arduino / Programming Questions / Re: Break/Stop loop with MQTT payload/message on: April 30, 2014, 01:13:55 am
Yes,
Code:
void loop() {
  client.loop();
}
is lets the MQTT client run. If not you lose connection to the broker (HiveMQ on my Debian server)
http://knolleary.net/arduino-client-for-mqtt/api/#loop

Yes i need to subscript to the whole topic in the callback. I tested also "*/IR-SonyTV" and "#/IR-SonyTV" because i thought
it would work because i already subscribe in the setup.

This part does not compile:
Code:
  if (strncmp(message,"volume-stop")==0) {
    // do whatever you need to stop the volume-up
    Serial.println("stop volume-up");
    message[0] = '\0';
  }
Quote
c:/programme (zip)/arduino/hardware/tools/avr/lib/gcc/../../avr/include/string.h: In function 'void callback(char*, byte*, unsigned int)':
c:/programme (zip)/arduino/hardware/tools/avr/lib/gcc/../../avr/include/string.h:135: error: too few arguments to function 'int strncmp(const char*, const char*, size_t)'
sketch_apr30a:58: error: at this point in file
If i take it out the "volume-ups" part works. "Up" is printed one time.
3  Using Arduino / Programming Questions / Re: Break/Stop loop with MQTT payload/message on: April 29, 2014, 05:50:05 pm
Ok first full code:
Code:
#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>
#include <IRremote.h>

/**************************************************************
*                                               Ethernet Settings                                         *
**************************************************************/

// Ethernet Card Mac Address
byte mac[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
// IPv4 address
byte ip[] = {192, 168, 0, 99};
// Subnet mask
byte subnet[] = {255, 255, 255, 0};
// Default gateway
byte gateway[] = {192, 168, 0, 1};
// MQTT Broker
byte MqttBroker[] = { 192, 168, 0, 12 };
// Preferred DNS sever
// byte dns[] = {192, 168, 0, 1};

/**************************************************************
*                                                       Declare                                                    *
**************************************************************/

IRsend irsend;
int test = 0;

/**************************************************************
*                                                          MQTT                                                    *
**************************************************************/

// MQTT Callback
void callback(char* topic, byte* payload, unsigned int length) {
 
  Serial.print("New message from broker on topic: ");
  Serial.println(topic);

  Serial.print("Payload: ");
  Serial.write(payload, length);
  Serial.println();
  Serial.print("Test: ");
  Serial.println(test);

  // IR Remote Sony TV
  if (strcmp(topic,"skulltronics.net/hive/floor/optimus-prime/IR-SonyTV")==0) {
   
    // Volume Up Nonstop
    if (length == 10 && strncmp((char*)payload,"volume-ups",10)==0) {
      for (int i = 0; i < 250; i++) {
        Serial.println("running");
        delay(50);
        if (test == 1) {
          break;
        }
      }
    }// End Volume Up Nonstop

    // Stop Volume Up Nonstop
    if (length == 11 && strncmp((char*)payload,"volume-stop",11)==0) {
      test = 1;
    } // End Stop Volume Up Nonstop

  } // End IR Remote Sony TV

} // End MQTT Callback

// Fire up PubSub client
EthernetClient ethClient;
PubSubClient client(MqttBroker, 1883, callback, ethClient);

/**************************************************************
*                                                       Setup                                                       *
**************************************************************/

void setup() {

  // Open serial communications and wait for port to open:
  Serial.begin(9600);
    while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Ethernet.begin(mac, ip, subnet, gateway);
  Serial.print(" IPv4 address: ");
  Serial.println(Ethernet.localIP());
   
  // Connect to Broker, give it Optimus Prime as the name
  if (client.connect("Optimus Prime")) {
    // Publish a message to the status topic
    client.publish("status","Optimus Prime is now online");
    // Listen for messages on the control topic
    client.subscribe("skulltronics.net/hive/floor/optimus-prime/#");
  }

}

void loop() {
  client.loop();
}
If i don't do the "strncmp length test" then my "for loop" is not running.
There is another way with a running for loop:
Code:
// MQTT Callback
void callback(char* topic, byte* payload, unsigned int length) {
 
  // ********** IR Remote Sony TV ********** //
  // Volume Up Nonstop
  if (strcmp(topic,"skulltronics.net/hive/floor/optimus-prime/IR-SonyTV/volume-ups")==0) {
    if (payload[0] == '1') {
      for (int i = 0; i < 250; i++) {
        Serial.println("running");
        irsend.sendSony(0x490, 12);
        delay(50);
        if (test == 1) {
          break;
        }
      }
    }
  } // End Volume Up Nonstop

  // Stop Volume Up Nonstop
  if (strcmp(topic,"skulltronics.net/hive/floor/optimus-prime/IR-SonyTV/volume-stop")==0) {
    if (payload[0] == '1') {
      test = 1;
    }
  } // End Stop Volume Up Nonstop
  // ********** End IR Remote Sony TV ********** //

} // End MQTT Callback
The second example means i have to call every command with his own topic and send "1" as message.
From my point of view it makes more sense to call the remote (IR-SonyTV) and send as message
what to do (volume-up) instead of calling the remote, then the button and tell the button what to do.
It has to do with null- termination and there is more about it here (comment 50 to 60): http://knolleary.net/arduino-client-for-mqtt/
Also i have to do it like in the first example if i want to send the IR-Remote hex code over MQTT.

Ok, what this code now does is printing "running" if i send "volume-ups".
I the send "volume-stop" and "running" is still printed.
After the 250 "running" prints i get my:
Quote
New message from broker on topic: skulltronics.net/hive/floor/optimus-prime/IR-SonyTV
Payload: volume-stop
Test: 0
print.

If i send then "volume-ups" as expected "running" is only printed once and Test: 1
So setting "test" works.

I need to send every command minimum 3 times to the IR-LED. That is how Sony remotes work.
You press a button and the IR-LED blinks 3 times.
So for my non-stop volume up i normally need:
3 blinks 50ms pause 3 blinks 50ms pause...
until i say "volume-stop"
4  Using Arduino / Programming Questions / Re: Break/Stop loop with MQTT payload/message on: April 27, 2014, 12:06:19 am
Ok, another 4 hours. I don't get it.
I also tested it with
Code:
while(test == 1) {
    Serial.println("up");
    if (test == 0) {
      goto outer;
    }
 }
outer:;
in the void loop.
What i'm missing or doing not how all the other examples i see are done:
http://forum.arduino.cc/index.php?topic=41706.msg302984#msg302984
First answer: http://stackoverflow.com/questions/863172/how-can-i-break-out-of-two-nested-for-loops-in-objective-c
http://letsmakerobots.com/node/37905




5  Using Arduino / Programming Questions / Re: Break/Stop loop with MQTT payload/message on: April 21, 2014, 10:34:54 am
Quote
Well, that's perfectly obvious. To you.
It is cause its the payload.
The topic says MQTT so this is about the Arduino pubsubclient.
Quote
But it sure doesn't have to have the meaningless name "callback".
It is not meaningless if you know MQTT in conjunction with Arduino cause it's part of
the pubsubclient (Arduino client for MQTT).

And everything is working great. Switching house lights, TV  programs, Doorbell ring through Asterisk over VoIP
to Softphones, 1-Wire sensor logging to MariaDB....
I only can't get this stupid loop stop to work.

I do it with voice commands.
The idea was if i say "TV volume up" that the Arduino sends the IR signal until i say "volume stop".
Volume up works but i can't stop it.

The server sends payload "volume-up" to the Arduino and runs it and it's working.
But if i send then the payload "volume-stop" it does not stop running "volume-up".
If i check my "int test" after sending "volume-stop" it's set to "1" but does not effect the running  "volume-up" loop.
6  Using Arduino / Programming Questions / Re: Break/Stop loop with MQTT payload/message on: April 21, 2014, 05:40:24 am
@lar3ry, you don't know MQTT? Then for sure my code makes no sense to you.
MQTT = Message Queue Telemetry Transport: http://en.wikipedia.org/wiki/MQ_Telemetry_Transport

Callback is part of http://knolleary.net/arduino-client-for-mqtt/

So "volume-up" runs if my MQTT broker on my server sends: "/mytopic/mytopic/IR-SonyTV/volume-up"
And "test" gets changed if i call/send: "/mytopic/mytopic/IR-SonyTV/volume-stop"
7  Using Arduino / Programming Questions / Break/Stop loop with MQTT payload/message on: April 20, 2014, 07:39:59 pm
Hi,

after almost two days i give up.
I want to stop a loop with MQTT but can't get it to work.
I tried endless possibilities. Here is one:
Code:
int test = 0;
void callback(char* topic, byte* payload, unsigned int length) {

  if (length == 9 && strncmp((char*)payload,"volume-up",9)==0) {
    for (int i = 0; i < 1000; i++) {
      Serial.println("up");
      Serial.println(test);
      delay(50);
      if (test == 1) {
        break;
      }
    }
  }


  if (length == 11 && strncmp((char*)payload,"volume-stop",11)==0) {
    Serial.println("stop");
    Serial.println(test);
    test = 1;
  }

}
If i call "volume-up" and get my test prints and then call "volume-stop" nothing happens.
If i call "volume-stop" first and then again i see that "test" has a value of "1".
Also "volume-up" is then printed just once.

I also tried it in "void loop()" with:
Code:
while (test == 0) {
  Serial.println("its running");
  Serial.println(test);
  // delay(20);
  if (test == 1){
    break;
  }
}
But that also doesn't stop if i call "volume-stop".

I'm out off ideas smiley-sad
8  Using Arduino / Networking, Protocols, and Devices / Re: 1-Wire Vcc GND - connect to Data GND on sensors? on: April 02, 2014, 02:33:47 pm
beside the sensor
Then 1-Wire would not make sense smiley

I don't sum it up yet. But 15, 20,  30 meters is nothing in a house.
From living room to bed room 8m...
From bed room to bath room 8m...
To the sensor and back in the cement flooring is 4+4=8m
That alone makes 16 meters!
Then i go to the windows (each 2 reed switches and a glass breakage detector)...

I found one guy who uses the Loxone Smart Home Automation and has 1 ring
for each floor of his house. Every window, door, temp in every room and so on...
And Maxim writes about 100, 200, 500 meters - so it should not be a problem if you do it right.
But now i have S/FTP PiMF everywhere and its to late cause i thought its the best.
I use CAT6 for one wire and my light switches and CAT7 for Ethernet.

Quote
Try it in an environment as identical as possible to the final installation
How can somebody to that? How to replicate all the wires/electric in your house (walls, ceiling)?
Especially if you just start to build your house...

No Apple stuff in da house smiley-evil

I extra bought two books about EMC/EMI from VDE (http://en.wikipedia.org/wiki/Verband_der_Elektrotechnik,_Elektronik_und_Informationstechnik)
9  Using Arduino / Networking, Protocols, and Devices / Re: 1-Wire Vcc GND - connect to Data GND on sensors? on: April 02, 2014, 07:19:09 am
Quote
Cat 5/6 cables make sense if your devices are quite far away, they are a waste of material if the distance is less than half a meter in a not so noisy environment.
Looks like thats not really the case.
Dallas recommendation is UNSHIELDED CAT5 cable and to not use shielded cable as the capacitance increases.
You can read stuff like (from 1-Wire-Design Guide v1.0): For short runs (where the total length of the 1-Wire bus is < 30 meters and the network only has a few slave devices on it), cable selection for use on the MicroLAN is reasonably simple, as even flat modular phone cable can work with a small numbers of 1-Wire slave devices.
On the other hand you have people who have problems with just 20 meters and CAT5/6 where you can read in docs that
100 or 200 meters shouldn't be a problem.

Then you can read:
Grounding unused wires or shields in a cable adds capacitance, which can significantly increase the RC time constant, they should be left disconnected. You want to limit capacitance throughout a 1-wire system as much as possible to maximize cable length and limit RC effects. Dallas Semiconductor recommends that unused wires and shields be left unconnected at both ends of the cable. The wires should be left floating.
But then you have the docs from companies that sell 1-Wire systems that make recommendations like i showed you.
Also some say "loop the shielding trough" others say "loop the shielding trough and connect it on one side".


When i looked at 1-Wire first before 2 years and decide to use it everything was clear.
Now i have everywhere CAT 6 for everything cause its relatively cheap.
It's time to connect now everything and maybe i was reading to much in forums and
on seller stuff and it confused me.

If i look at Dallas/Maxim and "1-Wire-Design Guide v1.0-1" or "1-Wire Application Guide 1.03" i think
its best to really just use 3 wires (DATA/GND/5Vcc).

Only thing is that i used shielded CAT6 and didn't even know that unshielded CAT6 exist.
I know that in the U.S. they use allot of unshielded CAT5 (UTP) cable but CAT6 UTP is new to me.
Here in Germany since years shielded cable is standard.
Even for my AC power i used shielded cables to have no EMC/EMI between them and my Network/Home Automation.

Hm, so the only question left is: To loop or not to loop the unused wires and shield from slave to slave.
10  Using Arduino / Networking, Protocols, and Devices / Re: 1-Wire Vcc GND - connect to Data GND on sensors? on: April 01, 2014, 12:54:39 pm
There are allot of places...
For example: http://1wire.org/index.html?target=p_2.html&lang=en-us
and: http://www.fischer-net.de/hausautomation/haustechnik/1-wire/26-1-wire-belegung-kabel-stecker.html

I don't like parasite mode - extra 5Vcc is more stable and the CAT cable has enough wires smiley

Sure, the idea is to also shield the 5Vcc - but nowhere i found what to do with the second GND.
It only makes sense to me like i draw it. If you only connect one side you have a big antenna.

I was looking for a circuit off a ready made sensor from some company's to see what they to.
But sure, they don't show it that you don't steel there circuit.
Also all the PCB pictures are so blurry and small that you see nothing.

I already made the temp sensor from my circuit on a 0,32x0,98" veroboard (damn that 0805 SMD ferrite bead is small).
Now i need to solder the sensor to the CAT cable (for the in-floor heating) that i can lay my laminate floor and then i have
no longer access to it.
Unsure what to do with the GND.
11  Using Arduino / Networking, Protocols, and Devices / 1-Wire Vcc GND - connect to Data GND on sensors? on: April 01, 2014, 09:32:51 am
Hi,

I'm a little confused.
The suggestion is to use one pair of the CAT cable for Data and Data GND
and another pair for Vcc (5V) and GND.

Does that mean on my sensors i connect them together?
If not i think the extra GND for Vcc would be useless.
But on this premade DS18B20 they just pass the GND through: http://www.fuchs-shop.com/download/manuals_for_t-sense_05-22-08.pdf

In the attachment are my own sensor circuits - there you can see better what i mean.
12  Community / Exhibition / Gallery / Re: Library for time zone conversions and automatic DST adjustments on: October 31, 2013, 12:48:24 pm
NTP sends UTC only, without adjustments for daylight time or time zone.
Thats the reason i was asking. So i can do it like my router with your library.
There i can set the Time Zone and NTP Time Server and have a Auto Daylight Savings Time checkbox.

Now i see "the Time library will function as a software RTC without additional hardware" in the readme.
So the first sentence "A primary aim of this library is to allow a Real Time Clock (RTC)" did confuse me.
13  Community / Exhibition / Gallery / Re: Library for time zone conversions and automatic DST adjustments on: October 31, 2013, 08:51:45 am
Hi,

this library works only with RTC's?
Is there something like "Auto Daylight Savings Time" for ntp?
14  Using Arduino / Project Guidance / Re: Need advice: NodeJS + Arduino wirelessly on: October 30, 2013, 11:58:38 am
Why are you hung up on using NodeJS, whatever it is?
Its beside Websockets the biggest thing since years: https://www.udemy.com/blog/learn-node-js/
Johnny-Five at  NodeConf 2012:

@neilff, i don't know what exactly you want to do. Johnny-Five is great but i think for stuff like Home Automation i don't
like the idea of having the logic on the Server.
I'm also locking for the best way for my interface and i thing MQTT is the way to go.
With Johnny-Five there is to much data if you want to use Ethernet.
I also thing MQTT is more secure: http://readwrite.com/2011/11/22/ibms-andy-piper-part-2-how-mqt

At the moment I'm testing HiveMQ with Paho MQTT JavaScript Client (Eclipse/IBM).
HiveMQ has build in Websocket and there is no need for other stuff like node.js, socket.io, Mosquitto...
Sure you need a machine running with a MQTT Broker (HiveMQ) and for me the decision to make now
is if i use Paho MQTT JavaScript (client-side) or node.js (server-side).
15  Using Arduino / Project Guidance / Re: what do you call the thing that connects to the spinning part of the motor? on: February 18, 2013, 01:11:33 am
The thing that sticks out and you can attach things to it smiley-yell
Pages: [1] 2 3 ... 8