ARDUINO plugin discussion

Posted on
Tue May 05, 2015 11:15 am
kw123 offline
User avatar
Posts: 6817
Joined: May 12, 2013
Location: Dallas, TX

ARDUINO plugin discussion

Is anyone interested in an arduino plugin.
It should be able to do:

1. for each pin define what it is:
- analog in
- analog out
- digital in
- digital out / relay

2. for each arduino set update frequency and IP number

The plugin will expose each of the input pin values as device states (e.g. device=arduino 1/ state pin1 = 300mV, state pin9 = 1)

What will not be covered is the program running on the arduino that receives and sends the http commands and executes them
We could add some examples for that. They are actually not that complicated and many examples are available for download


Karl

Posted on
Tue May 05, 2015 12:22 pm
SpencerJRoberts offline
User avatar
Posts: 248
Joined: Dec 09, 2012
Location: Mountain View, CA

Re: ARDUINO plugin discussion

I would definitely use it! And happy to test too :D

Posted on
Tue May 05, 2015 4:37 pm
richo offline
Posts: 155
Joined: Nov 25, 2014
Location: Pomorskie, Poland

Re: ARDUINO plugin discussion

Very nice idea. If it can be extended to ESP8266 I would be happy to get involved in such a project as well. Got some experience in integrating it with Indigo over Restfull.


Wysłane z iPhone za pomocą Tapatalk

Ryszard

Posted on
Tue May 05, 2015 6:30 pm
ckeyes888 offline
Posts: 2151
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: ARDUINO plugin discussion

If it could send a "sketch" to an Arduino I'd definitely be interested.

Carl

Posted on
Tue May 05, 2015 6:32 pm
kw123 offline
User avatar
Posts: 6817
Joined: May 12, 2013
Location: Dallas, TX

Re: ARDUINO plugin discussion

here the first shot at the menus, nothing else is happening in the background, just install the plugin and check out the device menu(create a device select arduino .. and edit)


https://www.dropbox.com/s/v83q8b6wxv27qjv/arduino.indigoPlugin.zip?dl=0

again the idea is
1 select the pins you like to use
2. define if in/out .. analog/digital
3. poll or push data to arduino depending on pin mode

this way it should be independent off the arduino

Posted on
Tue May 05, 2015 10:06 pm
kw123 offline
User avatar
Posts: 6817
Joined: May 12, 2013
Location: Dallas, TX

Re: ARDUINO plugin discussion

Code: Select all
Started plugin "arduino 0.0.1"
  arduino                         ARDUINO --V 0.0.1   initializing     might take some minutes depending on # of Ardunios
  arduino                          device :dev007 in deviceStartComm
  arduino                          device :deviceII in deviceStartComm
  arduino                         ------------------------------------------------------------------------------
  arduino                         init done ..   
  arduino                         -------------------------------------------------------------------------------
  arduino                          check devices for updates:
  arduino                          dev:  dev007              ;  id:  641526965;  update freq: 10;   last update: 0
  arduino                                               time to update:  49:26  https://192.168.1.77 -d "A1,AnalogIn=0"
  arduino                                               time to update:  49:26  https://192.168.1.77 -d "D1,DigitalOut=1"
  arduino                                               time to update:  49:26  https://192.168.1.77 -d "A9,AnalogOut=2"
  arduino                          dev:  deviceII            ;  id:   20703028;  update freq: 20;   last update: 0
  arduino                                               time to update:  49:26  https://192.168.1.77 -d "A4,AnalogIn=0"
  arduino                                               time to update:  49:26  https://192.168.1.77 -d "D3,DigitalIn=1"
  arduino                                               time to update:  49:26  https://192.168.1.77 -d "A3,AnalogIn=2"
  arduino                          dev:  dev007              ;  id:  641526965;  update freq: 10;   last update: 1430884166.11
  arduino                          dev:  deviceII            ;  id:   20703028;  update freq: 20;   last update: 1430884166.11
  arduino                          dev:  dev007              ;  id:  641526965;  update freq: 10;   last update: 1430884166.11
  arduino                                               time to update:  49:36  https://192.168.1.77 -d "A1,AnalogIn=0"
  arduino                                               time to update:  49:36  https://192.168.1.77 -d "D1,DigitalOut=1"
  arduino                                               time to update:  49:36  https://192.168.1.77 -d "A9,AnalogOut=2"
  arduino                          dev:  deviceII            ;  id:   20703028;  update freq: 20;   last update: 1430884166.11
  arduino                          dev:  dev007              ;  id:  641526965;  update freq: 10;   last update: 1430884176.13
  arduino                          dev:  deviceII            ;  id:   20703028;  update freq: 20;   last update: 1430884166.11
  arduino                          dev:  dev007              ;  id:  641526965;  update freq: 10;   last update: 1430884176.13
  arduino                                               time to update:  49:46  https://192.168.1.77 -d "A1,AnalogIn=0"
  arduino                                               time to update:  49:46  https://192.168.1.77 -d "D1,DigitalOut=1"
  arduino                                               time to update:  49:46  https://192.168.1.77 -d "A9,AnalogOut=2"
  arduino                          dev:  deviceII            ;  id:   20703028;  update freq: 20;   last update: 1430884166.11
  arduino                                               time to update:  49:46  https://192.168.1.77 -d "A4,AnalogIn=0"
  arduino                                               time to update:  49:46  https://192.168.1.77 -d "D3,DigitalIn=1"
  arduino                                               time to update:  49:46  https://192.168.1.77 -d "A3,AnalogIn=2"
  arduino                          dev:  dev007              ;  id:  641526965;  update freq: 10;   last update: 1430884186.15
  arduino                          dev:  deviceII            ;  id:   20703028;  update freq: 20;   last update: 1430884186.15
  arduino                          dev:  dev007              ;  id:  641526965;  update freq: 10;   last update: 1430884186.15
  arduino                                               time to update:  49:56  https://192.168.1.77 -d "A1,AnalogIn=0"
  arduino                                               time to update:  49:56  https://192.168.1.77 -d "D1,DigitalOut=1"
  arduino                                               time to update:  49:56  https://192.168.1.77 -d "A9,AnalogOut=2"
  arduino                          dev:  deviceII            ;  id:   20703028;  update freq: 20;   last update: 1430884186.15
here loop in the plugin checking 5 seconds if an update to / from arduino for the different devices is needed.
the device names and pins and modes are set in the device edit menus and the HTTP string is just a fake string to show what should happen there

Now the next question is " which commands to send to the arduinos?".
The arduino language is pretty simple and there is e.g. no json.loads etc .. too little memory.

something like:
A5,R;D7,W=500;D8,R .. would be
pin analog 5 read
pin Digital7 write 500
pin Digital8 read

that should be easy to parse on the Arduino side (first the ";" then the "," ..)


We could also include programming of the pins:

A8,P=I would be analog pin8 program to be a INPUT pin
D9,P=W would be set pin Digital9 to write mode

";" = separate the pin command
"," = separate pin and command
"=" value if write to pin, or programming command

any comments or suggestions?

here the plugin, you could play around with. change the settings in the device settings and you will see different outputs generated.
https://www.dropbox.com/s/fgdbk0or0a35r9u/arduino.indigoPlugin-v-0-0-2.zip?dl=0
The translation to actual HTTP code is the smallest step.


==> NEXT BIG thing we have to agree on is the syntax/grammar of commands to be send to the arduinos.


Karl

Posted on
Tue May 05, 2015 10:10 pm
kw123 offline
User avatar
Posts: 6817
Joined: May 12, 2013
Location: Dallas, TX

Re: ARDUINO plugin discussion

Carl
If it could send a "sketch" to an Arduino I'd definitely be interested.
I would not know how to do it === BUT ===we can program the pins through http commands .. so you could set any pin to read or write and poll the current pins, or write to them. That should cover most simple i/o things .. the other thing a little bit later..

Karl

Posted on
Wed May 06, 2015 5:10 am
DrLove offline
Posts: 200
Joined: Dec 12, 2014
Location: Sweden

Re: ARDUINO plugin discussion

Sounds very promising and useful!

But is it just me or is there no information on the Arduino code or interface?
Is the plugin only a simulation for now?

I would really love to see this plug-in working w/ Arduino+ESP8266!!!
Let me know if I can help in any way. I have allot of Arduino projects running right now that needs a wireless communication link to Indigo.

Best regards, L

Love Kull (yes it's my name)
Blog (in Swedish)
Sweden

Posted on
Wed May 06, 2015 7:44 am
kw123 offline
User avatar
Posts: 6817
Joined: May 12, 2013
Location: Dallas, TX

Re: ARDUINO plugin discussion

This is just the indigo side. In order to move forward we need the arduino receiving side. I have one in production I can not use. and a spare mega+wifiboard. Have to get that started.


Sent from my iPhone using Tapatalk

Posted on
Wed May 06, 2015 11:17 am
kw123 offline
User avatar
Posts: 6817
Joined: May 12, 2013
Location: Dallas, TX

Re: ARDUINO plugin discussion

I can't find my old arduino mega, need to order a new one.. will take some days before I can do anything else.

Posted on
Wed May 06, 2015 11:29 pm
kw123 offline
User avatar
Posts: 6817
Joined: May 12, 2013
Location: Dallas, TX

Re: ARDUINO plugin discussion

If it can be extended to ESP8266 I would be happy to get involved


This plugin and the soft ware on the arduino should be independent on the hardware config of the arduino.
You will always need to adapt the arduino software a little (arduino version, wifi/ethernet..): some of the include and server loads call will be different (~ 3-5 lines), but the core of the receive and send logic should not. --- i.e. receive a command from the plugin and execute it, and send back data should be exactly the same.

Karl

Posted on
Thu May 07, 2015 5:50 am
jblackburn offline
Posts: 69
Joined: Dec 11, 2013
Location: Quebec, Canada

Re: ARDUINO plugin discussion

kw123 wrote:
This plugin and the soft ware on the arduino should be independent on the hardware config of the arduino.
You will always need to adapt the arduino software a little (arduino version, wifi/ethernet..): some of the include and server loads call will be different (~ 3-5 lines), but the core of the receive and send logic should not. --- i.e. receive a command from the plugin and execute it, and send back data should be exactly the same.

Karl


It's why you should create a class (or Library) for the Arduino sketch with your protocol standard. The connection between your plugin and the Arduino sketch will always be functional.

Code: Select all
class Indigo
{
    public:
        ...
    private:
        int _pin;
        ....
};


I like your project! :D

Thanks!

Joêl

Posted on
Thu May 07, 2015 8:18 am
kw123 offline
User avatar
Posts: 6817
Joined: May 12, 2013
Location: Dallas, TX

Re: ARDUINO plugin discussion

just got the uno w ethernet.. I know what I will do tonight

Posted on
Thu May 07, 2015 8:41 am
SpencerJRoberts offline
User avatar
Posts: 248
Joined: Dec 09, 2012
Location: Mountain View, CA

Re: ARDUINO plugin discussion


Posted on
Thu May 07, 2015 11:56 pm
kw123 offline
User avatar
Posts: 6817
Joined: May 12, 2013
Location: Dallas, TX

Re: ARDUINO plugin discussion

here my first draft of the arduino sketch.

copy this to an arduino editor change the IP number and mac if you like and load onto and arduino with ethernet
for a wifi setup you will need to replace the ethernet library calls to wifi.

testing as is:
with

curl --max-time 3 192.168.1.151"?read:a1&read:d3=&write:d7=0&prog:d7=O&?"

will return:

returnValues:a1=298&a3=0&

thats easy to parse in the indigo plugin
Code: Select all
p= (ret)strip("&").split(":")[1].split("&")
pinValues={}
for a in p:
   a=p.split("=")
   pinValues[a[0]]=a[1]

gives: pinValues = {"a1":"298","a3":"0"}



or in python:
Code: Select all
import urllib2
url='http://192.168.1.151"?read:a1&write:d1=1&?"'
r = urllib2.urlopen(url).read()
print r

Karl


Code: Select all
#include <SPI.h>
#include <Ethernet.h>
//
//  uno w ethernet sketch  by karl wachs May 7 2015 v 0.1
//  this is used together with INDIGO plugin
//  command to be send:  curl 192.168.1.151"?--command-string--?"
//  command string has the form command:pin=value&  eg:  command:pin=value1,value2&command:pin&command:pin=value1&
//  commands implemented: 
//  read:a1&read:d3&         ==> will read analog pins 1 and 3     
//  write:d1=0&write:d4=0&   ==> set digital pins 1 to 0 and digital pin4 to 1
//  awrite:d3=55&            ==> analogWrite(3,55)  will set digital pin3 to 55
//  prog:d5=O&prog:D4=I&      ==> will reprogram digital pin 5 to output and digital pin 4 to input
//
//  not yet done: pulse, moment, rampU, rampD
//
//  here a more complex example:
//  command   curl 192.168.1.151"?reada1&write:d5=1&prog:d7=O&write:d7=1&?"
//  you can combin multiple commands each command must end with a &
//
//
// set server params:
byte mac[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x51 }; // pick one thats not on your network
IPAddress ip(192,168,1, 155);
EthernetServer server(80);
String line0;
String temp="";
String cmd="";
String command ="";
bool analog=true;
int pin = 0 ;
int value1 = -1;
int value2 = -1;
char mode = 'I';
int i =0;
void setup() {
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
//  while (!Serial) {
//    ; // wait for serial port to connect. Needed for Leonardo only
//  }
  pinMode(0, INPUT);
  pinMode(1, INPUT);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  pinMode(6, INPUT);
  pinMode(7, INPUT);
  pinMode(8, INPUT);
  pinMode(9, INPUT);
// PWR pins: 3,5,9 
// do not use 10-13, used for ethernet connection  10, 11, 12 and 13

  delay(3000);
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}



void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  bool endFound =false;
  if (client) {
      Serial.println("new client");
      // an http request ends with a blank line
      char lastC =' ';
      char c=' ';
      while (client.connected()) {
                if (client.available()) {
                          lastC = c;
                          c = client.read();
                          //Serial.write(c);
                 
                          if (c =='\n' and lastC=='\n' and endFound ==false) {
                                // if you've gotten to the end of the line (received a newline character) and the line is blank, the http request has ended,so you can send a reply
                                  endFound=true;
                                  // send a standard http response header
                                  client.println("HTTP/1.1 200 OK");
                                  client.println("Content-Type: text/html");
                                  client.println();
                                 String line0="";
                           }
                           else{       
                                   // now get commands
                                   if (c != '\n' ) {
                                         if ( lastC !='\n'){ line0 +=c; }     
                                   }       
                                   else{
                                         Serial.println("\n here the line:>>>");
                                         Serial.println(line0);
                                          // found a cmplete line output the value of each analog input pin
                                         temp = line0.substring(line0.indexOf('?')+1);
                                         //Serial.println(temp);
                                         line0 = temp.substring(0,temp.indexOf('?'));
                                         Serial.println(line0);
                                         Serial.println("<<<abc \n");
                                         String out ="returnValues:";
                                         while ( line0.length() > 3) {
                                               nextCmd();
                                               Serial.println (" ");
                                               Serial.println (cmd);
                                               getANALOG();
                                               getPIN();
                                               getCOMMAND();
                                               
                                               
                                               if (command == "read"){
                                                         if (analog) {
                                                             int val = analogRead(pin);
                                                             Serial.print("command = A-read ");
                                                             Serial.println(val);
                                                             out+='a'+String(pin)+'='+String(val)+'&';
                                                         }
                                                         else{
                                                             int val = digitalRead(pin);
                                                             Serial.print("command = D-read ");
                                                             Serial.println(val);
                                                             out+='a'+String(pin)+'='+String(val)+'&';
                                                         }
                                               }
                                               else{   
                                                      getVALUES();
                                                      Serial.print("value 1:"); Serial.print(value1);Serial.print("; 2:"); Serial.print(value2);Serial.print("  mode:");Serial.println(mode);

                                                       if (command == "write"){
                                                                Serial.println("command = write");
                                                                digitalWrite(pin,value1);                                                       
                                                       }   
                                                       
                                                       if (command == "awrite"){
                                                                Serial.println("command = awrite");
                                                                analogWrite(pin,value1);                                                       
                                                       } 
                                                       
                                                       if (command == "pulseU"){
                                                                 Serial.println("command = pulseUP");
                                                       }
                                                           
                                                       if (command == "pulseD"){
                                                                 Serial.println("command = pulseDown");
                                                       }
                                                           
                                                       if (command == "moment"){
                                                                 Serial.println("command = moment");
                                                       }
                                                           
                                                       if (command == "rampU"){
                                                                 Serial.println("command = ramp UP");
                                                       }
                                                           
                                                       if (command == "rampD"){
                                                                 Serial.println("command = ramp DOWN");
                                                       }
                                                       if (command == "prog"){
                                                                 Serial.println("command = set mode  "+ String(pin) +" to " + mode );
                                                                 if (mode =='I'){ pinMode(pin, INPUT);}
                                                                 if (mode =='O'){ pinMode(pin, OUTPUT);}
                                                       }
                                               }     
 
                                         } 
                                         line0="";
                                         client.println(out);
                                         // String readLine="";
//                                         client.println("Connection: close");  // the connection will be closed after completion of the response
                                         client.stop();
                                   }
                           }
                }           
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    Serial.println("client disconnected");
  }
}
void nextCmd() {
     i = line0.indexOf('&');
     if ( i <= 1 )
         { cmd = "" ; line0 ="" ; return ;}
     cmd = line0.substring(0,i);
//     Serial.println(cmd);
//     Serial.println(i);
     if (line0.length() > i+3) {
         temp = line0.substring(i+1);
         line0 = temp;
     }
     else {line0="";}
//     Serial.println(line0);
}

void getANALOG() {
         i = line0.indexOf(':');
         if (cmd.charAt(i+1) =='a')  {analog=true; }
         else                        {analog=false;}
}


void getPIN() {
         i = cmd.indexOf(':');
         temp= cmd.substring(i+2);
         i = temp.indexOf('=');
         if (i == 2){
             pin= temp.substring(0,2).toInt();
         }
         else{
             pin= temp.substring(0,1).toInt();
         }   
}

void getCOMMAND() {
         i = cmd.indexOf(':');
         if (i>1){
             command = cmd.substring(0,i);
         }   
         else{ command="";}
}

void getVALUES() {
         value1 =-1; value2 =-1;mode=' ';
         i = cmd.indexOf('=');
         if (i>3){
             if (i == cmd.length()-1){return;}
                 
             String Values = cmd.substring(i+1);
             i = Values.indexOf(',');
             if (i>0 and i != Values.length()-1){
                  value1 = Values.substring(0,i).toInt();
                  value2 = Values.substring(i+1).toInt();
                  return;
             }
             else {
                  if (Values.charAt(0) =='I'){mode = 'I';return;}   
                  if (Values.charAt(0) =='O'){mode = 'O';return;}
                  }   
             value1 = Values.toInt();
         }
         return ;   
}


Who is online

Users browsing this forum: No registered users and 1 guest