ARDUINO plugin discussion

Posted on
Sun Aug 30, 2015 10:05 pm
mclass offline
Posts: 314
Joined: May 13, 2015
Location: Melbourne, Australia

Re: ARDUINO plugin discussion

ESP01 Progress Report:

Having successfully got a Sparkfun ESP8266 Thing connected and working with the Arduino plugin, I decided to live dangerously and attempt the same stunt with an ESP01 module. Limited success so far so thought I'd spread the joy!!

The first issue was getting the sketch uploaded! I did so using a Sparkfun Basic FTDI 3.3V adapter. Rather than use breadboard (the ESP01 is NOT breadboard friendly) and/or patch leads, I knocked up a small board (see attachments).

Using the Arduino IDE (with board set to Generic ESP Module, and using the ESP8266WiFi library) I was able to successfully flash Karl's ESP.ino sketch with "define ESP1" selected into the module . The computer usb port was capable of powering the process.

On completion of the flash, the link pulling GPIO0 to ground was removed and the device repowered using the 3.3V regulator of the Sparkfun FTDI Basic. However the usb port was insufficient to power the module and a 5V USB "wall wart" was used.

After adding a device with the model selected to ESP01, and with D02 selected as input, Indigo recognised that the ESP01 was online, but not configured. The event log presents the following:

Code: Select all
arduino                          looping to check devices for updates:
  arduino                         http://192.168.XX.XX/?st&?
  arduino                         msg from arduino: >>notConfigured
  arduino                         http round trip incl jsonloads: 0.119888067245
  arduino                         not configured, break loop {'Status': 'Online, Not Configured'}
  arduino Error                   Error in plugin execution runConcurrentThread:

Traceback (most recent call last):
  File "plugin.py", line 170, in runConcurrentThread
<type 'exceptions.ValueError'>: IllegalParameterError -- variable names may not contain spaces

  arduino Error                   plugin runConcurrentThread function returned or failed (will attempt again in 10 seconds)



Again, time has escaped me to carry out any further mods, and would be interested in any suggestions/ideas of where to now.

The Sparkfun Thing was certainly a lot less hassle, and may be worth the additional cost/size.

Thanks again to Karl for the work he's put into this plugin!

Mclass
Attachments
FullSizeRender.jpg
Here's a view of the back of the board in response to a query received re type of board used
FullSizeRender.jpg (106.42 KiB) Viewed 4889 times
ESP8266-Flasher.jpg
ESP8266-Flasher.jpg (54.62 KiB) Viewed 4939 times
ESP01_ - 2.jpg
Populated board. Not link for flashing. GPIO2 brought out to header for testing.
ESP01_ - 2.jpg (41.66 KiB) Viewed 4939 times
ESP01_ - 1.jpg
ESP01_ - 1.jpg (47.3 KiB) Viewed 4939 times
Last edited by mclass on Mon Aug 31, 2015 11:20 pm, edited 1 time in total.

Posted on
Mon Aug 31, 2015 4:49 am
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: ARDUINO plugin discussion

here the fix for the error message:

<type 'exceptions.ValueError'>: IllegalParameterError -- variable names may not contain spaces

http://forums.indigodomo.com/viewtopic.php?f=178&t=14043&p=96424#p96424

The plugin wants to create a variable with the name of the device, but variables can not contain spaces. It will now create a variable with the spaces removed.


and thanks for testing the small ESP

Karl

Posted on
Mon Aug 31, 2015 8:32 pm
mclass offline
Posts: 314
Joined: May 13, 2015
Location: Melbourne, Australia

Re: ARDUINO plugin discussion

Karl,

ESP01 works a treat now! Many thanks. :lol:

Mclass

Posted on
Sun Sep 06, 2015 2:03 pm
BassMint offline
Posts: 105
Joined: Dec 24, 2013

Re: ARDUINO plugin discussion

This is great! Just what I needed.

What pins would be the "virtual" or S0 etc pins?

Posted on
Sun Sep 06, 2015 4:19 pm
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: ARDUINO plugin discussion

They are not pins They are a way to send / receive text to from arduino. The plugin looks at them as pins.

Check the "domystuff()" section in the esp/arduino sketch for how to use them.
You could use them to send calculated values or when you use eg digital barometers YOU have to get the data in domystuff() and populate an Sx variable then read Sx with the plugin


Sent from my iPhone using Tapatalk

Posted on
Tue Sep 08, 2015 5:30 pm
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: ARDUINO plugin discussion

adding a adafruit HUZZAH to a minka handheld remote

what you need:
1. one ADAFRUIT HUZZAH with FTDI to usb connector (you could use a regular ARDUINO - but that would not fit into the remote, a spark fun thing , the nodeMCU - but also too big to fit into the remote.
2. five opto couplers (I used the cheapest, I could find : Photo Coupler PC817 $3.62 for 10)
3. five SMALL resistors 470 Ohm (I used SMD types they are REALLY tiny YOU MUST BE GOOD AT SOLDERING to get those done)
4. some thin cables
5. an old USB cable
6. load the ESP sketch onto the HUZZAH, no changes needed (besides your SID and password)
7. install the arduino plugin

- connect the FTDI to the adafruit, load the sketch

- disconnect the FTDI and all its pins etc.


now the Hardware part begins:

- setup OPT COUPLER: - Solder the optocoupler input Anode direct to the GPIO pin. The cathode pin goes through a 470 Ohm to ground on the HUZZAH
you can connect all of the resistors through one (thin) cable to ground.

- on the output side of the Opto coupler connect all "emitter" outputs( the bottom right pin) to ground on the remote control (one cable) and the collector output(top right) to the proper pin on the remote (5 cables)
When the GPIO pin goes "HIGH" the output of the opto coupler shorts the collector and emitter pins i.e. connects the remote control pin to ground
- be aware some remotes have it the other way around: the common is not negative but positive, there you have to connect the emitter to the switched cable and combine the collectors

using an Opto coupler makes it easier to isolate the 2 systems (HUZZAH and remote)

now do this 5 times for FAN: OFF/LOW/MED/HIGH and Light ON/OFF/DIM (light is just one button on this remote)

Finally add power: use an old USB cable cut off the small end and use the ground cable and the red cable to connect to ground and +Volt on the Huzzah.

attached

1. the electronics drawing
Screen Shot 2015-09-08 at 5.56.24 PM.png
Screen Shot 2015-09-08 at 5.56.24 PM.png (39.94 KiB) Viewed 4705 times

2. some pictures of the setup and how to fit it into the remote
Screen Shot 2015-09-08 at 6.06.38 PM.png
Screen Shot 2015-09-08 at 6.06.38 PM.png (820.55 KiB) Viewed 4705 times

Screen Shot 2015-09-08 at 6.07.57 PM.png
Screen Shot 2015-09-08 at 6.07.57 PM.png (730.46 KiB) Viewed 4705 times

Screen Shot 2015-09-08 at 6.08.26 PM.png
Screen Shot 2015-09-08 at 6.08.26 PM.png (368.74 KiB) Viewed 4705 times

Screen Shot 2015-09-08 at 6.10.19 PM.png
Screen Shot 2015-09-08 at 6.10.19 PM.png (200.22 KiB) Viewed 4705 times

Screen Shot 2015-09-08 at 6.11.29 PM.png
Screen Shot 2015-09-08 at 6.11.29 PM.png (332.48 KiB) Viewed 4705 times

Screen Shot 2015-09-08 at 6.10.47 PM.png
Screen Shot 2015-09-08 at 6.10.47 PM.png (196.38 KiB) Viewed 4705 times

3. screen shots of the action to "press" the buttons.
define the indigo ESP device
Screen Shot 2015-09-08 at 5.28.38 PM.png
Screen Shot 2015-09-08 at 5.28.38 PM.png (96.35 KiB) Viewed 4705 times

define the action
Screen Shot 2015-09-08 at 5.29.25 PM.png
Screen Shot 2015-09-08 at 5.29.25 PM.png (28.81 KiB) Viewed 4705 times

define the signal send to the ESP (we send a pulse of 0.5 seconds = press the button for 1/2 second
Screen Shot 2015-09-08 at 5.29.13 PM.png
Screen Shot 2015-09-08 at 5.29.13 PM.png (26.61 KiB) Viewed 4705 times

define one action for each remote button
Screen Shot 2015-09-08 at 5.29.35 PM.png
Screen Shot 2015-09-08 at 5.29.35 PM.png (14.36 KiB) Viewed 4705 times


You can continue to use the remote as before. When you connect the USB cable to a power outlet you then can use indigo to set the remote.

I would like to add a photo cell to check if there is light as with this remote it can only toggle on/off and you don't know if if it is on/off when indigo "presses" the button Also when you press the light button longer (< 1.2 seconds) it starts to dim up/down

This was a fun project combining a plugin,wifi, an Arduino/ESP, a remote, some electronics .. and it actually works and is useful.

If you need more info ping me.

Karl

Posted on
Wed Sep 09, 2015 7:43 pm
mclass offline
Posts: 314
Joined: May 13, 2015
Location: Melbourne, Australia

Re: ARDUINO plugin discussion

Great stuff, Karl - demonstrates the possibilities of this module!

Meanwhile, on the other side of the world ......

With summer on it's way Down Under, I've turned my attention to automating the plantation shutters at home.

I have acquired a Firgelli linear actuator and have been working on the mechanical aspects. The actuator is the model that can be controlled with a 0-10V, RC Servo or PWM.

With the advent of the ESP8266, and Karl's Arduino plugin, my mind has wandered to control ...

So out of interest, I loaded the example Arduino "Sweep" servo sketch into an ESP01 module, hooked up the actuator and it cycled nicely. (See photo). Next steps are to:

    - insert servo control into "My Stuff" in Karl's Indigo sketch to establish control through Indigo (thinking store preset positions into variables?)
    - assemble into a much more compact package
    - see if I can make the whole thing (including the actuator) battery operated to avoid wiring to 6 different windows
    - try and get GPIO0 on the ESP01 module operational (I understand it should be able to be used as an output, but not as input, as that pin is used to set the "Flash" mode). With two outputs I can either control two separate shutter panels, or use GPIO0 to control, and GPIO1 as a monitoring input)
    - conquer the mechanical linkage to the shutter blades!

So, it's back to the bench, with thanks to Karl for all his efforts! :lol:

Mclass

PS. Maybe it's time for a separate ESP8266 thread??
Attachments
Servo Proof of Concept (1).jpg
Servo Proof of Concept (1).jpg (17.51 KiB) Viewed 4671 times

Posted on
Wed Sep 09, 2015 8:05 pm
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: ARDUINO plugin discussion

"My Stuff" and S variables:

1. you can use them as you see fit
2. the plugin can write to them i.e. send any text in an Sx variable to the sketch. in doMyStuff() they are then available as Sx
don't forget to set them to "" after you used them, other wise your will do it over and over again.
3. the plugin can read them: do a read on e.g. S2 in doMyStuff set S2 to any text you like. The state SX in the ESP/Arduino Indigo-device will be populated with that string.

so a flow could be like this:

in plugin create action:
(A) write S1 "On",
delay 1 second;
(B) action: read S2
in doMyStuff(){
if (S1=="ON") {
// do what ever you like here;
S2="finished"; //set result of action in S2
S1=""; // reset S1 so that we don't do it again.
}
}


[EDIT]
the only reason I can up with where you need use the Sx variables is for using the ESP/Arduino for e.g. I2C communication with digital devices there you need to add your own code and send the results back to indigo via Sx
you would need to add sorting like this:
https://www.arduino.cc/en/Tutorial/SFRRangerReader into doMySTuff()

you can do ramps/on/off/ ONEpulse/Continuouspulse out of the box.


Karl

just got my "BITSCOPE" from down under

Posted on
Thu Sep 10, 2015 7:34 am
jens offline
Posts: 265
Joined: May 03, 2015
Location: Sweden

Re: ARDUINO plugin discussion

Hello,

Have an Arduino UNO with ethernet, how do I do, so that it is possible control 4x relays?

It was necessary to install any type of server software on the Mac ??

Get this error when upploding it to UNO

Arduino:1.7.6 (Mac OS X), Kort:"Arduino Uno"

unoMega.ino:126:18: error: expected '}' before ':' token
unoMega.ino:126:18: error: expected ',' or ';' before ':' token
unoMega.ino:126:34: error: expected declaration before '}' token
Fel vid kompilering.

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.


And this is what i typed:

//
// UNO/MEGA w ethernet/WIFI sketch by karl wachs August 28 2015 v 1.2
// this is used together with INDIGO plugin
// command to be send: curl 192.168.1.155"?--command-string--?"
// command string has the form command:pin=value& eg: command:pin=value1,value2&command:pin&command:pin=value1&
// commands implemented:
// rd:A1&rd:D3& ==> will read analog pins 1 and 3
// wr:D1=0&wr:D4=0& ==> set digital pins 1 to 0 and digital pin4 to 1
// aw:D3=55& ==> analogWrite(3,55) will set digital pin3 to 55
// pg:D5=O&pgD4=I& ==> will reprogram digital pin 5 to output and digital pin 4 to input
// mU:D5=100& ==> will reprogram digital pin 5 to do: 500msec up then down
// mD:D5=5555& ==> will reprogram digital pin 5 to do: 5555 msec down then up
// pU:D5=100,5555& ==> will reprogram digital pin 5 to do: 100msec up, then 5555 msec down and repeat
// pD:D5=2000,3000& ==> will reprogram digital pin 5 to do: 3000 msec down and 2000 msec up and repeat
// rd:S1& ==> will read contents of variable S1
// aw:S1=abc -=; def& ==> will write abc -=; def to varibale S1
// aw:F0=123.7& ==> will write 123.7 to varibale F0
// aw:N4=123& ==> will write 123 to varibale N4
//
// pins can be D0..Dxx A0.. Axx F0..F4, N0..N4, S0..S4
// Dx are digital i/o pins they can be read ==> 0/1; digital write 0/1 or analogWrite 0..255
// Ax are anlog input pins delivery values 0..1023
// Fx are float variables can be written to and read from eg 1.23 or -45.3
// Nx are integer variables can be written to and read from eg 0, 100 ..
// Sx are String variables can be written to and read from eg kajshdlkjh=-: but NOT a & that will end the string
//
// here a more complex example:
// command curl http://192.168.1.155/"?rd:a1&wr:d5=1&pg:d7=O&wr:d7=1&?" note the "
// you can combine multiple commands, each command must end with a &
// in python it is
// ret= urllib2.urlopen("http://ipnumber/?rd:a1&wr:d5=1&pg:d7=O&wr:d7=1&?").read()
// would send ret =">>rd:A1=311&wr:D5=1&pg:D7=O&wr:D7=0&wr:D7=1&"
//
// excution times: for mega reading 70 pins ... use this for time out setting, default is 5 seconds
// debug on ethernet: 0.4 secs
// debug off 0.2 secs
// debug on wifi : 0.9 secs
// debug off : 0.6 secs

// UNO reading 15 pins
// debug off ethernet: 0.05 secs
// debug on : 0.2 secs
// debug off wifi : 0.3
// debug on : 0.5 secs
//
// this needs to be set : 1. #define DEBUG only for testing
// 2. #define ETHERNET or WIFI not both
// 3. #define UNO or MEGA not both --- in the tools menue in ARDUINO IDE you have to select the proper board also
// for ethernet you need to set the IP number and the MAC number, WIFI gets it from the router, so you have to figure out the IP number either in debug mode or on the router
//
// byte mac[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x53 }; // pick one thats not on your network
// IPAddress ip(192,168,1, 183);
// some of the pins are diabled / enabled automatically: pin D10,11,12,13 are used to communicate to the ethernet/wifi boards
//
// pins d0 d1 are used for usb communication, so in debug mode they are diabled, debug off they can used as all other pins
//
////////////////////////////////////////////////////////////////////////////////////
// enable serial monitor for debugging, if in production do not send data to serial port
#define DEBUG
//
// select which board you use
//#define MEGA
#define UNO
//
//
#include <SPI.h> // needed for WIFI and ethernet, not for ESP
//select which network card:
#define ETHERNET
#include <Ethernet.h>
//
//#define WIFI
//#include <WiFi.h>
//
//
//
//
char cmd[20];
char command[3];
int pin = 0 ;
int value1 = -1;
int value2 = -1;
String valueS="";
int cmdL = 0;
char c=' ';
char mode = 'I';
int kk=1;
int eIndex=-1;
int kIndex=-1;
int cIndex=-1;

// free values to read from and write to
String S[10]={"","","","","","","","","",""};

String out ; // this can get: 68* 12 = 800+ for mega and 14*12 = 170 for uno

#if defined(MEGA)
int activeDPins =54;
int activeAPins =16;
char dConfig[60] ;
char pulseCMD[60] ;
unsigned long pulseEND[60] ;
unsigned long pulseV1[60] ;
unsigned long pulseV2[60] ;
bool doNotUsePin[60];
#endif

#if defined(UNO)
//char buf1[115] ={'\0'}; // this is for input buffer; 16 pins, 8 char per pin max = 112 should be enough for uno!!
int activeDPins =14;
int activeAPins =6;
char dConfig[14] ;
char pulseCMD[14] ;
unsigned long pulseEND[14] ;
unsigned long pulseV1[14] ;
unsigned long pulseV2[14] ;
bool doNotUsePin[14];
#endif

String configured ="no";




//////////////////////////////// configure network here
#if defined(ETHERNET)
byte mac[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x53 }; // pick one thats not on your network
IPAddress ip(192,168,0, 185);
EthernetServer server(80);
#endif

//#if defined(WIFI)
//char ssid[] = "xxxx"; // your network SSID (name)
//char pass[] = "yyyy"; // your network password
//int keyIndex = 0; // your network key Index number (needed only for WEP)
//int status = WL_IDLE_STATUS;
//WiFiServer server(80);
#endif
//////////////////////////////// configure network here END




void setup() {
for (int i =0;i< activeDPins;i++){
dConfig[i] ='0';
pulseCMD[i] ='0';
pulseEND[i] =0;
pulseV1[i] =0;
pulseV2[i] =0;
doNotUsePin[i]=false;
}

#if defined(DEBUG)
doNotUsePin[0] = true;
doNotUsePin[1] = true;
Serial.begin(57600);
Serial.print("server starting");
#endif



// start the Ethernet connection and the server:
#if defined(ETHERNET)
doNotUsePin[10] = true;
doNotUsePin[11] = true;
doNotUsePin[12] = true;
doNotUsePin[13] = true;
Ethernet.begin(mac, ip);
server.begin();
delay(1000);
// Open serial communications and wait for port to open:
#if defined(DEBUG)
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
#endif
#endif // ETHERNET


#if defined(WIFI)
// check for the presence of the shield:
doNotUsePin[10] = true;
doNotUsePin[11] = true;
doNotUsePin[12] = true;
doNotUsePin[13] = true;
if (WiFi.status() == WL_NO_SHIELD) {
#if defined(DEBUG)
Serial.println("WiFi shield not present");
#endif
// don't continue:
while(true);
}

// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
#if defined(DEBUG)
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
#endif
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
server.begin();
printWifiStatus();
#endif // WIFI
}



void doMyStuff(){
// examples of what can be done
//S[0]= "Temperature= "+String(analogRead(A0)/100.)+"C"; // do a read of variable S0
//S[1]= "Humidity: 50%"; // do a read of variable S0
//S[2]= analogRead(A0); // do a read of variable S0
//if (S[5]== "switch D5 on" ){ digitalWrite(5,1) ;S[5]="switched D5 on" ;} // do a write to variable S5
//if (S[5]== "switch D5 off"){ digitalWrite(5,0) ;S[5]="switched D5 off";} // do a write to variable S5
}

void loop(){
delay(1);
// here the stuff that should be done at every loop besides listening to the network commands
SpecialOutputs();
delay(1);
// put your code here use and fill the N and F vaiables to communicate your struff eg temp to the plugin.
//doMyStuff();
////////////////////////


// listen for incoming clients
#if defined(WIFI)
WiFiClient client = server.available();
#endif
#if defined(ETHERNET)
EthernetClient client = server.available();
#endif
if (client) {
#if defined(DEBUG)
Serial.println("new client");
#endif
char c4 =' '; char c3=' ' ; char c2=' '; char c1=' '; c=' ';int GETfound =0;
while (client.connected()) {
if (client.available()) {
c4=c3;c3=c2;c2=c1;c1=c;
c = client.read();
#if defined(DEBUG)
Serial.write(c);
#endif
if (GETfound ==0){ if ( c4=='G' and c3=='E' and c2=='T' and c1 ==' ' and c=='/'){ // "GET /"
#if defined(DEBUG)
Serial.println("getfound =1");
#endif
GETfound =1; c = client.read();// skip "?"
#if defined(DEBUG)
Serial.write(c);
#endif
cmdL=-1; c = client.read(); out =">>";
#if defined(DEBUG)
Serial.write(c);
#endif
} // skip "?" and read first char (avoid another loop)
}
if (GETfound ==1) {
if (c != '?' and out !=">>notConfigured" ) { // skip if not configured, otherwise read until ending "?"
cmdL+=1;
cmd[cmdL]=c;

if (c==':' and kIndex ==-1){kIndex=cmdL;} // use the first occurence
if (c=='=' and eIndex ==-1){eIndex=cmdL;}
if (c==',' and cIndex ==-1){cIndex=cmdL;}
if (c=='&'){
cmd[cmdL+1]= '\0';
parseCMD(); doNextCMD();
cmdL=-1;cIndex=-1,eIndex=-1;kIndex=-1;}
}
else{ GETfound=2;
#if defined(DEBUG)
Serial.println(" GETfound =2" );
#endif
}
}
}
if (GETfound ==2) { // here we send the header and the composed data
GETfound=3;
client.println("HTTP/1.1 200 OK");
client.print("Content-Length: "); client.println(out.length());
client.println("Content-Type: text/html");
client.println();
client.print(out);
client.stop();
delay(5); // 10 msecs
#if defined(DEBUG)
Serial.println(out.length());
Serial.println(out);
Serial.println("GETFOUND: 3");
#endif
}
}
//yield();// give ESP time to do its background stuff
#if defined(DEBUG)
Serial.println("client disconnected");
#endif
}
}




void doNextCMD(){

if ( (configured == "no") and (strcmp(command,"pg") !=0 ) ) {
out=">>notConfigured";
#if defined(DEBUG)
Serial.println(">>notConfigured");
#endif
return;
}
if ( strcmp(command,"st") ==0 and configured =="yes" ) { out=">>Configured"; return; }
if ( strcmp(command,"st") ==0 and configured =="no" ) { out=">>notConfigured"; return; }

if (doNotUsePin[pin] and cmd[3]=='D' ) { out+=command;out+=":D";out+=String(pin);out+="=notUseable&"; return; }
if ( cmd[3]=='I' and pin >=activeAPins ) { return; }
if ( cmd[3]=='D' and pin >=activeDPins ) { return; }
if ( cmd[3]=='S' and pin >9 ) { return; }
configured="yes";

if ( strcmp(command,"cf") ==0 or strcmp(command,"lc")==0 ) {
if ( strcmp(command,"cf") ==0 ) {
#if defined(DEBUG)
Serial.println("command = cf ");
#endif
for (int i=0;i<activeDPins;i++){out+="cf:D"+String(i)+'='+dConfig[i]+'&';}
}
return ;
}
if ( strcmp(command, "i2") ==0 ){ // not implemented yet, dummy function
if (cmd[3]=='I') { //= read i2c devices
return;
}
}
if (strcmp(command, "pg")==0 and cmd[3]=='D' ){
#if defined(DEBUG)
Serial.println("command =pg "+ String(pin) +" to mode=" + mode +", cmd="+ cmd);
#endif
if (doNotUsePin[pin] ) { return; }
if (mode =='I'){ pinMode(pin, INPUT); dConfig[pin] ='I';out+=cmd ; out+='&';}
if (mode =='O'){ pinMode(pin, OUTPUT);dConfig[pin] ='O';out+=cmd ; out+='&';}
pulseCMD[pin]='0';
pulseEND[pin]=0;
pulseEND[pin]=0;
return;
}
if ( strcmp(command, "rd")==0 ){
if ( cmd[3]=='A') { // ANALOG
int val = analogRead(A0); // ESP has only one pin and it must be address as A0
#if defined(DEBUG)
Serial.print("command = A-read "); Serial.println(val);
#endif
out+="rd:A"+String(pin)+'='+String(val)+'&';
return;
}
if (cmd[3]=='D'){ // Digital
int val = digitalRead(pin);
#if defined(DEBUG)
Serial.print("command = D-read ");Serial.println(val);
#endif
out+="rd:D"+String(pin)+'='+String(val)+'&';
pulseCMD[pin]='0';
pulseEND[pin]=0;
pulseEND[pin]=0;
return;
}
if (cmd[3]=='S'){ // this will return the S[pin] string
#if defined(DEBUG)
Serial.print("command = S-read ");Serial.println(S[pin]);
#endif
out+="rd:S"+String(pin)+'='+S[pin]+'&';
return;
}
}



if (strcmp(command, "wr") ==0 and cmd[3]=='S'){
S[pin]= valueS;
out+=cmd; out+='&';
return;
}

if ( cmd[3]=='D'){
if (strcmp(command, "wr")==0 ){
//#if defined(DEBUG)
Serial.println("command = wr");
//#endif
digitalWrite(pin,value1);
pulseCMD[pin]='0';
out+=cmd; out+='&';
return;
}


if (strcmp(command, "aw") ==0 and cmd[3]=='D'){
#if defined(DEBUG)
Serial.print("command = aw, value=" );Serial.println(value1);
#endif
analogWrite(pin,value1);
pulseCMD[pin]='0';
out+=cmd; out+='&';
return;
}

if (strcmp(command, "pU")==0 ){ // pulse Down / pulse Up
pulseEND[pin]= millis()+ value1;
pulseV1[pin]=value1;
pulseV2[pin]=value2;
pulseCMD[pin]='P';
//analogWrite(pin,255);
digitalWrite(pin,1);
#if defined(DEBUG)
Serial.println("command = pU");
#endif
out+=cmd; out+='&';
return;
}

if (strcmp(command, "pD")==0 ){ // pulse up / pulse down
pulseEND[pin]= millis()+ value2;
pulseV1[pin]=value1;
pulseV2[pin]=value2;
pulseCMD[pin]='p';
//analogWrite(pin,0);
digitalWrite(pin,0);
#if defined(DEBUG)
Serial.println("command = pD");
#endif
out+=cmd; out+='&';
return;
}

if (strcmp(command, "mU")==0 ){ // moment UP
pulseEND[pin]= millis()+ value1;
pulseCMD[pin]='M';
#if defined(DEBUG)
Serial.println("command = mU");Serial.println(value1);
#endif
digitalWrite(pin,1);
out+=cmd; out+='&';
return;
}

if (strcmp(command, "mD")==0 ){ // moment Down
pulseEND[pin]= millis()+ value1;
pulseCMD[pin]='m';
#if defined(DEBUG)
Serial.println("command = mD");Serial.println(value1);
#endif
digitalWrite(pin,0);
out+=cmd; out+='&';
return;
}
if (strcmp(command, "rD")==0 ){ // ramp up
pulseEND[pin]= millis()+ value1;
pulseV1[pin]=value1;
pulseCMD[pin]='r';
#if defined(DEBUG)
Serial.println("command = rD");Serial.println(value1);
#endif
analogWrite(pin,255);
out+=cmd; out+='&';
return;
}
if (strcmp(command, "rU")==0 ){ // ramp down
pulseEND[pin]= millis()+ value1;
pulseV1[pin]=value1;
pulseCMD[pin]='R';
#if defined(DEBUG)
Serial.println("command = rU");Serial.println(value1);
#endif
analogWrite(pin,0);
out+=cmd; out+='&';
return;
}

}

}


void SpecialOutputs() {
for ( int j = 0; j< activeDPins; j++){ // check for all digital pins
if (pulseCMD[j] != '0') {
////// moment up or down
if (pulseCMD[j] =='M'){ // UP
if (millis() > pulseEND[j]) { pulseCMD[j] ='0'; digitalWrite(j,0);}
}
if (pulseCMD[j] =='m'){ // down
if (millis() > pulseEND[j]) { pulseCMD[j] ='0'; digitalWrite(j,1);}

}
/////// pulses up and down
if (pulseCMD[j] =='P'){ // UP
if (millis() > pulseEND[j]) { pulseCMD[j] ='p'; digitalWrite(j,0); pulseEND[j] = millis()+ pulseV2[j];}
}
if (pulseCMD[j] =='p' ){ //down
if (millis() > pulseEND[j]) { pulseCMD[j] ='P'; digitalWrite(j,1); pulseEND[j] = millis()+ pulseV1[j];}
}

/////// ramp up or down
if (pulseCMD[j] =='R'){ // UP
if (millis() > pulseEND[j] ) { pulseCMD[j]='0';}
else {analogWrite(j, (int) ( 255. * (1.- ((float)pulseEND[j] - (float) millis()) / ((float)pulseV1[j]) ) ));}
}
if (pulseCMD[j] =='r'){ // down
if (millis() > pulseEND[j] ) { pulseCMD[j]='0';}
else {analogWrite(j, (int) ( 255. * ( ((float)pulseEND[j] - (float) millis()) / ((float)pulseV1[j]) ) ));}
}
}
}
}


int findCinCMD( char x){
for ( int i=0;i<cmdL;i++){ if (cmd[i] == x){ return i;}}
return -1;
}

void parseCMD() { // structure: rd:D09& or wr:D55=1234& or mU:d3=1234,4321& or pg:d33=I&
int i; String xx="";
value1 =-1; value2 =-1;mode=' ';

command[0]=cmd[0]; command[1]= cmd[1];command[2]='\0';

//Serial.print("\n ki: ");Serial.print(kIndex);Serial.print(" ei: ");Serial.print(eIndex);Serial.print(" c: ");Serial.print(cIndex);

if (eIndex==-1){eIndex=cmdL;}; if (cIndex==-1){cIndex=cmdL;} // if no "=" or "," signs

// get pin # is integer 0.. 99 allowed
if (eIndex > 0) { xx=""; for (i = kIndex+2; i< eIndex; i++ ) { xx+=cmd[i]; }; pin=xx.toInt(); }

// now get values
if (eIndex>3){ // any "=" sign?
if (eIndex == cmdL-1){return;} // no values given

// this is for programming to Input or Output
if (cmd[eIndex+1] =='I'){mode = 'I';return;}
if (cmd[eIndex+1] =='O'){mode = 'O';return;}

// get integer numbers may by one or 2 , if "," present then it has 2 numbers
if (cmd[3]=='S'){
xx=""; for ( i = eIndex+1; i< cmdL; i++ ){ xx+=cmd[i];}; valueS=xx; // ignore , for strings
return;
}

if (cIndex>0 and eIndex <cmdL-1){ // we have 2 number separated by a ","
xx=""; for ( i = eIndex+1; i< cIndex; i++ ){ xx+=cmd[i];}; value1=xx.toInt(); //
xx=""; for ( i = cIndex+1; i< cmdL; i++ ){ xx+=cmd[i];}; value2=xx.toInt(); //
return;
}

// just one number/ string, no "," present
xx=""; for ( i = eIndex+1; i< cmdL; i++ ) { xx+=cmd[i];}; value1=xx.toInt(); return;
}
return ;
}


void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
Serial.println(" text ");


// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);

// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}



// Jens

Posted on
Thu Sep 10, 2015 8:35 am
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: ARDUINO plugin discussion

Jens,
did you change anything in the sketch source code?

Karl

Posted on
Thu Sep 10, 2015 8:40 am
jens offline
Posts: 265
Joined: May 03, 2015
Location: Sweden

Re: ARDUINO plugin discussion

Only my ip and ethernet and uno


Sent from my iPhone 6 using Tapatalk
Last edited by jens on Thu Sep 10, 2015 8:49 am, edited 1 time in total.

Posted on
Thu Sep 10, 2015 8:48 am
jens offline
Posts: 265
Joined: May 03, 2015
Location: Sweden

Re: ARDUINO plugin discussion

Started ower and get this:

Arduino:1.7.6 (Mac OS X), Kort:"Arduino Uno"

unoMega.ino: In function 'void printWifiStatus()':
unoMega.ino:569:26: error: 'WiFi' was not declared in this scope
Fel vid kompilering.

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

Posted on
Thu Sep 10, 2015 9:09 am
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: ARDUINO plugin discussion

delete these lines, or surround them with
#if defined(WIFI)
#endif

Code: Select all
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
Serial.println(" text ");


// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);

// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}

Posted on
Thu Sep 10, 2015 9:21 am
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: ARDUINO plugin discussion

posted a new version that fixes the 'WiFi' was not declared in this scope error
http://forums.indigodomo.com/viewtopic.php?f=178&t=14043

Karl

Posted on
Thu Sep 10, 2015 9:38 am
jens offline
Posts: 265
Joined: May 03, 2015
Location: Sweden

Re: ARDUINO plugin discussion

And now this but feels that it was ok, but not

Arduino:1.7.6 (Mac OS X), Kort:"Arduino Uno"

Sketch uses 21 052 bytes (65%) of program storage space. Maximum is 32 256 bytes.
Global variables use 1 181 bytes (57%) of dynamic memory, leaving 867 bytes for local variables. Maximum is 2 048 bytes.
avrdude: ser_open(): can't open device "COM1": No such file or directory
ioctl("TIOCMGET"): Inappropriate ioctl for device
Problem vid uppladdning till brädan. Se http://www.arduino.cc/en/Guide/Troubleshooting#upload för förslag.

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

Page 5 of 34 1, 2, 3, 4, 5, 6, 7, 8 ... 34

Who is online

Users browsing this forum: No registered users and 4 guests

cron