technobly / Simple-Spark-Core-Controller

11 stars 12 forks source link

Keeps Defaulting to Button 1 #1

Closed valleyapps closed 10 years ago

valleyapps commented 10 years ago

Hi, first thank you so much, this has helped me learn and its was working great. For some reason now out of the blue its defaulting to button 1 instead of posting the buttons from the top part of the code. I renamed them Fan 1, Lamp, so on, and it was working fine for 24 hours but now its defaulting back to the Button 1, Button 2, Button 3, Button 4 and no longer working. Do you have any suggestions on what I am doing wrong?

Thanks Mike

technobly commented 10 years ago

Awexome! Glad you're getting some use out of this :)

It sounds like jQuery is not running for you. Double check that you have all of the files in all directories still (css, js) along side your index.html file.

If that's ok, try looking at the debugging console. Press F12 in Chrome ... or right-click and select "Inspect Element" and then click the Console tab. Once that's open, refresh your page and let me know if any errors pop up... a screenshot would be good.

valleyapps commented 10 years ago

Thank you so much I will give it a try, its odd bc even when I download it directly and do not change anything from the download its still does it, where it did not in the past. Thanks for giving me support I greatly appreciate it and great work!!!!

On Mon, Jun 30, 2014 at 9:47 AM, Technobly notifications@github.com wrote:

It sounds like jQuery is not running for you. Double check that you have all of the files in all directories still (css, js) along side your index.html file.

If that's ok, try looking at the debugging console. Press F12 in Chrome ... or right-click and select "Inspect Element" and then click the Console tab. Once that's open, refresh your page and let me know if any errors pop up... a screenshot would be good.

Reply to this email directly or view it on GitHub https://github.com/technobly/Simple-Spark-Core-Controller/issues/1#issuecomment-47533027 .

Mike Vanderpool CEO ValleyApps http://www.valleyapps.com Office (540) 999- 8847 Direct (540) 746-7009

technobly commented 10 years ago

If you download the Zip and unzip to your favorite directory, and then open the index.html file... you should see this:

button 3 is hidden because it has no label defined.

valleyapps commented 10 years ago

Thank you sir, I got it to work, I have to assume it was something to do with my server, I appreciate the help greatly. I was wondering, sometimes when I hit the buttons online it says success but does not click on the relay, so I have to hit it twice, any idea where to look to help this issue? If not no worries, I really appreciate it and its making learning so fun, I can not thank you and the entire open source community enough

On Mon, Jun 30, 2014 at 10:52 AM, Technobly notifications@github.com wrote:

If you download the Zip and unzip to your favorite directory, and then open the index.html file... you should see this:

https://camo.githubusercontent.com/e01fb2e5d465712dbccdd53273401d9266817a7d/687474703a2f2f692e696d6775722e636f6d2f4347416f4451352e706e67 button 3 is hidden because it has no label defined.

https://camo.githubusercontent.com/6785dae3c22e2e47c3175e1b342740c6e273966c/687474703a2f2f692e696d6775722e636f6d2f6e3955797063682e706e67

Reply to this email directly or view it on GitHub https://github.com/technobly/Simple-Spark-Core-Controller/issues/1#issuecomment-47541128 .

Mike Vanderpool CEO ValleyApps http://www.valleyapps.com Office (540) 999- 8847 Direct (540) 746-7009

technobly commented 10 years ago

No problem!

So if you have to click it twice the first time, but not every time, it sounds like it's toggling the output, and the first time it's toggling the output such that the relay is off first. Then toggling again it it turns it on. If your outputs were initially defined in setup() with pinMode(...,OUTPUT); and given a default state digitalWrite(..., LOW); then the first time you toggle them they should turn ON the relays. I'm assuming you are using the Spark Relay Shield. You can paste your code here if you want and I can take a look. Format it nicely with:

```cpp
// replace this line with your code


If it's just happening sometimes... then it's probably not really "successful" like the app is giving you a false reassurance of.  But that shouldn't be happening since the javascript looks for a return code of 200 from the Spark Core to let it know that the command was received, before displaying the success message.  At least that's how it's designed to work.  Seeing your code might be helpful.
valleyapps commented 10 years ago

Hi! Just replaced my code down below. I am a hobbyist and ameature so I do applogize if its very odd. :)

Thanks

On Mon, Jun 30, 2014 at 3:37 PM, Technobly notifications@github.com wrote:

No problem!

So if you have to click it twice the first time, but not every time, it sounds like it's toggling the output, and the first time it's toggling the output such that the relay is off first. Then toggling again it it turns it on. If your outputs were initially defined in setup() with pinMode(...,OUTPUT); and given a default state digitalWrite(..., LOW); then the first time you toggle them they should turn ON the relays. I'm assuming you are using the Spark Relay Shield. You can paste your code here if you want and I can take a look. Format it nicely with:

bool state = HIGH;

void setup() {
    pinMode(D3,OUTPUT);
    digitalWrite(D3,HIGH); // turn on D7 by default
    Spark.function("test", testFunction);

    pinMode(D2,OUTPUT);
    digitalWrite(D2,HIGH); // turn on D7 by default
    Spark.function("test2", test2Function);

       pinMode(D1,OUTPUT);
    digitalWrite(D1,HIGH); // turn on D7 by default
    Spark.function("test4", test4Function);

    pinMode(D0,OUTPUT);
    digitalWrite(D0,HIGH); // turn on D7 by default
    Spark.function("test3", test3Function);
}

void loop() {
  // do nothing

}

int testFunction(String args) {
    state = !state; // toggle the state
    digitalWrite(D3,state); // update the LED so we can see some action
    return 200; // This is checked in the web app controller for validation
}

int test2Function(String args) {
    state = !state; // toggle the state
    digitalWrite(D2,state); // update the LED so we can see some action
    return 200; // This is checked in the web app controller for validation
}

int test4Function(String args) {
    state = !state; // toggle the state
    digitalWrite(D1,state); // update the LED so we can see some action
    return 200; // This is checked in the web app controller for validation
}
int test3Function(String args) {
    state = !state; // toggle the state
    digitalWrite(D0,state); // update the LED so we can see some action
    return 200; // This is checked in the web app controller for validation
}

If it's just happening sometimes... then it's probably not really "successful" like the app is giving you a false reassurance of. But that shouldn't be happening since the javascript looks for a return code of 200 from the Spark Core to let it know that the command was received, before displaying the success message. At least that's how it's designed to work. Seeing your code might be helpful.

Reply to this email directly or view it on GitHub https://github.com/technobly/Simple-Spark-Core-Controller/issues/1#issuecomment-47576438 .

Mike Vanderpool CEO ValleyApps http://www.valleyapps.com Office (540) 999- 8847 Direct (540) 746-7009

technobly commented 10 years ago

I see the problem :)

Start all D0-D3 outputs LOW digitalWrite(Dx,LOW);

and most importantly create separate state variables for each relay, so they don't "tongue tied" together. I also cleaned up all of the names to match the states and put them in order. You may have to fix your index.html now to match the funcKeys desired, but it will be worth it in the long run.

 bool state0 = LOW;
 bool state1 = LOW;
 bool state2 = LOW;
 bool state3 = LOW;

void setup() {
  pinMode(D0,OUTPUT);
  digitalWrite(D0,state0); // turn off D0 by default
  Spark.function("test0", test0Function);

  pinMode(D1,OUTPUT);
  digitalWrite(D1,state1); // turn on D1 by default
  Spark.function("test1", test1Function);

  pinMode(D2,OUTPUT);
  digitalWrite(D2,state2); // turn off D2 by default
  Spark.function("test2", test2Function);

  pinMode(D3,OUTPUT);
  digitalWrite(D3,state3); // turn off D3 by default
  Spark.function("test3", test3Function);
}

void loop() {
  // do nothing
}

int test0Function(String args) {
  state0 = !state0; // toggle state0
  digitalWrite(D0,state0); // update the LED so we can see some action
  return 200; // This is checked in the web app controller for validation
}

int test1Function(String args) {
  state1 = !state1; // toggle state1
  digitalWrite(D1,state1); // update the LED so we can see some action
  return 200; // This is checked in the web app controller for validation
}

int test2Function(String args) {
  state2 = !state2; // toggle state2
  digitalWrite(D2,state2); // update the LED so we can see some action
  return 200; // This is checked in the web app controller for validation
}

int test3Function(String args) {
  state3 = !state3; // toggle state3
  digitalWrite(D3,state3); // update the LED so we can see some action
  return 200; // This is checked in the web app controller for validation
}
valleyapps commented 10 years ago

Can not thank you enough. I intend to learn more so hopefully I can be a bit more tidy in my code. I appreciate all your help!

Mike ᐧ

On Tue, Jul 1, 2014 at 2:42 AM, Technobly notifications@github.com wrote:

I see the problem :)

Start all D0-D3 outputs LOW digitalWrite(Dx,LOW);

and most importantly create separate state variables for each relay, so they don't "tongue tied" together. I also cleaned up all of the names to match the states and put them in order. You may have to fix your index.html now to match the funcKeys desired, but it will be worth it in the long run.

bool state0 = LOW; bool state1 = LOW; bool state2 = LOW; bool state3 = LOW; void setup() { pinMode(D0,OUTPUT); digitalWrite(D0,state0); // turn off D0 by default Spark.function("test0", test0Function);

pinMode(D1,OUTPUT); digitalWrite(D1,state1); // turn on D1 by default Spark.function("test1", test1Function);

pinMode(D2,OUTPUT); digitalWrite(D2,state2); // turn off D2 by default Spark.function("test2", test2Function);

pinMode(D3,OUTPUT); digitalWrite(D3,state3); // turn off D3 by default

Spark.function("test3", test3Function);} void loop() { // do nothing} int test0Function(String args) { state0 = !state0; // toggle state0 digitalWrite(D0,state0); // update the LED so we can see some action

return 200; // This is checked in the web app controller for validation} int test1Function(String args) { state1 = !state1; // toggle state1 digitalWrite(D1,state1); // update the LED so we can see some action

return 200; // This is checked in the web app controller for validation} int test2Function(String args) {

state2 = !state2; // toggle state2 digitalWrite(D2,state2); // update the LED so we can see some action

return 200; // This is checked in the web app controller for validation} int test3Function(String args) {

state3 = !state3; // toggle state3 digitalWrite(D3,state3); // update the LED so we can see some action

return 200; // This is checked in the web app controller for validation}

— Reply to this email directly or view it on GitHub https://github.com/technobly/Simple-Spark-Core-Controller/issues/1#issuecomment-47622066 .

Mike Vanderpool CEO ValleyApps http://www.valleyapps.com Office (540) 999- 8847 Direct (540) 746-7009

technobly commented 10 years ago

Glad to hear it and you're very welcome! I hope you're having as much fun as I am with the Spark Core ;-)

valleyapps commented 10 years ago

Sir, Sorry to bother you again, but I wanted to make sure I thanked you again. I have learned everything through the internet and am not trained and consider myself a student of life and of many masters like yourself. It is very promising for humanity that there is still people out there in this open source and tech world that are willing to help others learn and grow.

One last question I have for you, is this all written in C? I am wondering as I want to purchase some books on some programming languages and trying to figure which would be best to learn if I am interested in IOT.

Thanks again and I appreciate it.

Mike

On Tue, Jul 1, 2014 at 1:06 PM, Technobly notifications@github.com wrote:

Closed #1 https://github.com/technobly/Simple-Spark-Core-Controller/issues/1.

Reply to this email directly or view it on GitHub https://github.com/technobly/Simple-Spark-Core-Controller/issues/1#event-137065434 .

Mike Vanderpool CEO ValleyApps http://www.valleyapps.com Office (540) 999- 8847 Direct (540) 746-7009

technobly commented 10 years ago

:smiley_cat: No bother really... glad to help out, and spread the knowledge around.

Coding for the Spark Core code can mostly be thought of as C programming, but it's compiled with a C++ compiler, and most of the background code is C++. Arduino code is 99% C though. If you get yourself a good book on C you'll be fine. There are also good online resources like: http://www.learn-c.org/

This is the book that was handed down to me, and I passed on to another new coder. You'll learn the fundamentals of C by Dennis Ritchie himself, who designed the C computer programming language in 1972. http://www.abebooks.com/servlet/BookDetailsPL?bi=12198575309&searchurl=kn%3Dansi%2Bc%2Bprogramming%26amp%3Btn%3Dc%2Bprogramming%2Blanguage

They make specific books for Arduino too which is probably even more helpful if you just want to focus on that... Spark Core is trying to be as compatible with the Arduino coding language as possible. That just means all of the wrapper functions for controlling pins and inputs work the same way. http://www.amazon.com/s/ref=nb_sb_noss_1?url=search-alias%3Dstripbooks&field-keywords=arduino&rh=n%3A283155%2Ck%3Aarduino

Javascript is very C like as well... so once you learn C, Javascript becomes easy to understand. HTML and CSS are fun as well... tons of resources out there for that like http://codecademy.com

Good luck, I'm sure you'll do great!

valleyapps commented 10 years ago

Thank you! I just got a GPRS shield for $9.00 at Radio Shack. It was on sale but I have a feeling it was mislabeled. I got it on vacation otherwise I would take it back to let them know but I figure I build up some good Karma so why not keep it. Maybe it was not a mistake but I still kinda feel bad. Anyway I just hooked up a PIR sensor and am trying to get it to text me when it goes off. I am close but another cool project.

One last thing, do you think it possible to use an arduino and a spark core together. Maybe have the arduino power the PIR and GPRS and then click on a relay connected to the spark?

Thanks Mike ᐧ

On Wed, Jul 2, 2014 at 2:37 AM, Technobly notifications@github.com wrote:

[image: :smiley_cat:] No bother really... glad to help out, and spread the knowledge around.

Coding for the Spark Core code can mostly be thought of as C programming, but it's compiled with a C++ compiler, and most of the background code is C++. Arduino code is 99% C though. If you get yourself a good book on C you'll be fine. There are also good online resources like: http://www.learn-c.org/

This is the book that was handed down to me, and I passed on to another new coder. You'll learn the fundamentals of C.

http://www.abebooks.com/servlet/BookDetailsPL?bi=12198575309&searchurl=kn%3Dansi%2Bc%2Bprogramming%26amp%3Btn%3Dc%2Bprogramming%2Blanguage

They make specific books for Arduino too which is probably even more helpful if you just want to focus on that... Spark Core is trying to be as compatible with the Arduino coding language as possible. That just means all of the wrapper functions for controlling pins and inputs work the same way.

http://www.amazon.com/s/ref=nb_sb_noss_1?url=search-alias%3Dstripbooks&field-keywords=arduino&rh=n%3A283155%2Ck%3Aarduino

Good luck, I'm sure you'll do great!

— Reply to this email directly or view it on GitHub https://github.com/technobly/Simple-Spark-Core-Controller/issues/1#issuecomment-47741927 .

Mike Vanderpool CEO ValleyApps http://www.valleyapps.com Office (540) 999- 8847 Direct (540) 746-7009

technobly commented 10 years ago

Nice! Radio Shack clearances stuff out all of the time super cheap so you might have gotten one of those deals. Don't sweat it. Clearance items can have weird stuff that's not know though... so you might have to discover what that is. Like some NeoPixel type LED strips they sell for $30, they clearanced out for $6.99. They didn't say why... but I found out it was because the Red and Blue color traces on the strip are swapped... easy enough to fix in code though :)

I got a PIR sensor from RS as well... very sensitive! Are you trying to catch Ding-dong-ditchers? haha.. that's come up on the Spark Community Forums before. Easy enough to do... there are many ways to send a Push Notification which is probably even faster than a SMS.

You can use the Arduino and Spark together in many ways. If it's just one action... Digital output on the arduino controls a Digital input on the Spark. Or you could wire up the Arduino Serial TX to Spark RX, or Arduino I2C Master to Spark I2C Slave. Many of these have examples already on the Spark Forums too. If you are not on the Spark Forums already, definitely go there and check out all of the projects.

valleyapps commented 10 years ago

Thanks mate! I have built a couple projects and I am like a kid on Christmas lately. I have this one guy who wanted me to build out a boat alarm, but he has not wifi connection so when I as the GPRS shield I thought I would give it a try. Combined with a reed switch and or PIR sensor and a SIM card I think I have found a way to secure his boat. We leave in a great time, that a simple person like me who knows a little code, and can use GIT, and do great things. I just now have an obligation to give back to the GIT community. I actually started a working relationship with someone I met on instructables and he helped me build out two ideas I am applying for patents on. I have one patent already for a product I invented but its not really in this field so I am happy that I can get into the IOT game. Anyway, I appreciate it and if you every are available for some freelance work, let me know. I own Vision Studios, ValleyApps, and ZipGripGo ( my patened product) and am always looking for talent like yourself.

PS - Damn Din Dong Knocks have no clue what I have for them now! Maybe even a low voltage shock to remind them, this door bell bites back! LOL

Cheers, Mike ᐧ

On Wed, Jul 2, 2014 at 2:53 AM, Technobly notifications@github.com wrote:

Nice! Radio Shack clearances stuff out all of the time super cheap so you might have gotten one of those deals. Don't sweat it. Clearance items can have weird stuff that's not know though... so you might have to discover what that is. Like some NeoPixel type LED strips they sell for $30, they clearanced out for $6.99. They didn't say why... but I found out it was because the Red and Blue color traces on the strip are swapped... easy enough to fix in code though :)

I got a PIR sensor from RS as well... very sensitive! Are you trying to catch Ding-dong-ditchers? haha.. that's come up on the Spark Community Forums before. Easy enough to do... there are many ways to send a Push Notification which is probably even faster than a SMS.

You can use the Arduino and Spark together in many ways. If it's just one action... Digital output on the arduino controls a Digital input on the Spark. Or you could wire up the Arduino Serial TX to Spark RX, or Arduino I2C Master to Spark I2C Slave. Many of these have examples already on the Spark Forums too. If you are not on the Spark Forums already, definitely go there and check out all of the projects.

— Reply to this email directly or view it on GitHub https://github.com/technobly/Simple-Spark-Core-Controller/issues/1#issuecomment-47742872 .

Mike Vanderpool CEO ValleyApps http://www.valleyapps.com Office (540) 999- 8847 Direct (540) 746-7009