Since you dropped the [] in your use of zTemp you don't need the & anymore, otherwise you actually write &&someVar which is not what you want here.
You could rather write
Spark.variable("resultX", zTemp, STRING);
// or
Spark.variable("resultX", &zTemp[0], STRING);
Otherwise the string you put into zTemp[] will be used as a pointer, pointing who knows where, next time you want to retrieve the variable via the cloud.
Since I've not looked into DHT22 I can't say if this does cause any harm, but I'd put a Spark.process(); into the loop to allow the Core to do the cloud "housekeeping".
Can you also give some more detail about the problem you are experiencing and put in some Serial.print() checkpoints to narrow down the location of the problem and the status of your variables?
Some unrelated hints:
You could use #define led2 D7 and #define idDHT22pin D4 instead of using int ... = ...; This would save some mem space and add speed (in small projects it wouldn't matter, but ...)
If you want someones direct attention in this forum, you could address (tag) them via (e.g.) @Marcus1 , then they will be notified to have a look at this thread.
@Marcus1, I have a lot of experience with the DHT22 lib (I ported it!) and it could be the cause if the sensor hangs, which is something I have found happens often with the library. I would highly recommend piettetech’s updated version of this library here.
Second, I am not sure why you have all the single quotes in the sprintf statement. These are not needed and I am not sure if they will cause problems.
The single quotes have no special meaning within double quotes C-string generally and specifically no special meaning in a printf format string - they appear in the output.
Fortunately, this is not a question that has to rely on faith alone. In a literal C string (a formal way of saying “within double-quotes”) a single quote never has a special meaning. In a printf format string it only has a special meaning within a conversion specification - between the ‘%’ character and the conversion specifier character e.g. "%'.2f"
The reference provided by @peekay123 says “Escape sequences are used to represent certain special characters within string literals and character literals.” Here we are talking about string literals.
String literals are delimited by double quotes. Character literals are delimited by single quotes. There is no need to escape a single quote within a string literal and there is no need to escape a double quote in a character literal.
I’d agree with @psb777 in this regard, but there is also an easy way to test and settle this.
As suggested above, try to Serial.print the string. If the char appears in the output as expected, escaping is not required, if it doesn’t or the string looks wrong, it’s likely to require escaping.
@mdma: I’ll try to bare the #define alternative in mind
You can verify it if you like, but remember the gcc compiler is being used. It’s standard C. It’s well understood or ought to be. It really is not helpful to make suggestions like this. There are a million things which could possibly be wrong, and I reckon we could come up with many other suggestions as to how the compiler might be broken. But it is not broken in this respect. And it isn’t helpful to suggest it is. Better than suggesting this it ought to have been tested beforehand.
But I want to reassure the OP again. There is no problem using single quotes as he does, and he would be wasting his time replacing the sprintf with serial.print except that sprintf takes lots of memory. Let’s be plain: If he sees a difference in behaviour it will be memory which is the issue.
In the interim we can each of us run this on every machine with every C compiler and report back
@psb777, I don't quite understand the undertone there. Could it be that you have actually misunderstood my post?
Actually I agreed with you and nothing else - but
You yourself suggested to check the output and since there is still an unresolved issue wit the OPs project my suggestion further up was to add checkpoints (e.g. Serial.print) to narrow down the cause of it - and hence these checkpoints could be put to further use to prove, what you and I already "know".
And I never suggested to replace sprintf() with Serial.print() but to check the sprintf()-output by Serial.print()ing it.
So what was actually "unhelpful" in that?
If you insist, you could maybe help @Marcus1 in a better way than I tried right from his first post on.
Don't confuse a friend for a foe, please - in this community we shouldn't expect a foe anyhow.
@Marcus1, I stand corrected on the use of the quote in a string literal. I sometimes have selective vision and oft-not-so-total recall
The one question no one asked so far is what you mean by “crashed”? Can you be more specific?
If what you mean by “crash” is actually “hang” then I highly suspect it is @ScruffR’s previous suggestion that the while (DHT22.acquiring()); is stuck (from my own experience) and though adding Spark.process() to the loop would prevent the cloud connection from dropping, it will not prevent it from running endlessly. Are you using piettetech’s updated DHT22 library?
This is what I actually wanted to find out, only less clear
Thanks @peekay123 for bringing the discussion back on track after some background noise hid it a bit
For the purpose of establishing if it's a crash or a hang, some Serial.print() - or any other means if someone does disagree with the use of this approach - would be helpful.
@ScruffR, all I was doing, however grumpily, was trying to avoid any misinformation being passed to the OP. I started off with a simple contradiction, an assertion there was no problem with the embedded single quotes. If there’s a problem with the brakes, being told to check the windscreen wipers, especially if they’re working fine, is a little annoying, especially if the suggestion is persisted with.
@psb777, I think you hit it! I think @Marcus1’s brakes have failed and that’s why he crashed! We are all on the same page now and @ScruffR latest suggestions are dead on. @Marcus1, just put a Serial.print() before and after the suspect while() loop and it should become very obvious if that is the problem. If that’s not the issue, then add more to follow the flow of the code.
Yes, but the single quotes were not the pivitol point here.
They were only one well meant (but not completely correct) “guess” of one of the biggest contributors in this community, to help the OP to narrow down all possible causes.
And actually we don’t know if it’s the brakes or something else.
And if the OP doesn’t want to rely on second hand insight but wants to actually learn and know how to nail down some unexpected behavior than even seemingly useless tests might help him to learn from them for the future.
If you hand someone in need a fish, you feed him for a day - If you teach him how to fish, you feed him for life.