Skills Dev V: Working with Networking

Made by Alp Erbug, bmkaufma, Tyler Howe and pgomezte

This projects connects 2 Particle Argons. Using one of the Argons, we are able to control components connected to the other Argon.

Created: December 13th, 2022

0

Outcome

For this project, we created a pair of connected devices. Both devices are composed of a Particle Argon, a push button, a diode, and a transistor. The only difference between them is that the first one has a fan, and the second one has a solenoid as an output indicator. The devices communicate through Particle Cloud, and pushing on a button on one device triggers the output action on the other device.

0

Process

The first step in creating these two devices was to assemble the circuits. For one circuit, we had a pushbutton and a fan, and for the other, we had a pushbutton and a solenoid. After the circuits were built, we modified the code from Skills Dev IV to trigger the actuator from the other device. We utilized three particle cloud features - particle.function, particle.subscribe, and particle.publish. We essentially had each board publish an event when its button was pressed, and we had the other board subscribe to that published event. To do this we created webhooks that were triggered by these published events. These webhooks were set up to use the other particle board's access token. We learned that we needed to be very careful when naming our events because we had an issue where we used the same event names and both devices actuating at the same time which caused a recursive loop where we were sending a never-ending stream of events to our particle clouds.

0

Reflection

Leveraging the previous labs, wiring the circuit and controlling the circuit elements were not challenging. The hardest part of the project was figuring out how to set up multiple Particle Argons to communicate with one another, and this took us a while to achieve, but we were ale to successfully pair our devices. The interaction between the devices was very seamless, and it was entertaining to see this happen instantly. 

0
Events and Networking
Alp Erbug - DIoT - https://youtube.com/shorts/54vIBhPDgDo
0
// We will be using D2 to control our LED
int ledPin = D2;

// Our button wired to D0
int buttonPin = D3;

bool doButton = false;

void setup()
{

  pinMode( buttonPin , INPUT_PULLUP); // sets pin as input

  // We also want to use the LED

  pinMode( ledPin , OUTPUT ); // sets pin as output
  
  Particle.function("spinFan", spinFan);
  Particle.subscribe( "buttonPressed", handleButtonPressed );

}

void loop()
{
   // find out if the button is pushed
   // or not by reading from it.
   int buttonState = digitalRead( buttonPin );


  if( buttonState == LOW )
  {
    // turn the LED On
    digitalWrite( ledPin, HIGH);
    Particle.publish("buttonPressed2");
    delay(1000);
  }else{
    // otherwise
    // turn the LED Off
    digitalWrite( ledPin, LOW);

  }

 if( doButton == true ){
        digitalWrite( ledPin, HIGH);
        delay(1000);
        doButton = false;
    }

}


void handleButtonPressed( const char *event, const char *data)
{
   doButton = true;
}

int spinFan(String command)
{
   digitalWrite( ledPin, HIGH);
   int runTime = command.toInt() * 1000;
   delay(runTime);;
   return 1;
}
Click to Expand
0
int ledPin = D3;

int buttonPin = D5;

bool doButton = false;

void setup()
{

  pinMode( buttonPin , INPUT_PULLUP); 



  pinMode( ledPin , OUTPUT ); // sets pin as output
  
  Particle.subscribe( "buttonPressed2", handleButtonPressed );

}

void loop()
{
   // find out if the button is pushed
   // or not by reading from it.
   int buttonState = digitalRead( buttonPin );


  if( buttonState == LOW )
  {
    // turn the LED On
    digitalWrite( ledPin, HIGH);
    Particle.publish("buttonPressed");
    delay(1000);
  }else{
    // otherwise
    // turn the LED Off
    digitalWrite( ledPin, LOW);

  }

 if( doButton == true ){
        digitalWrite( ledPin, HIGH);
        delay(1000);
        doButton = false;
    }

}


void handleButtonPressed( const char *event, const char *data)
{
   doButton = true;
}
Click to Expand
x
Share this Project

Courses

About

This projects connects 2 Particle Argons. Using one of the Argons, we are able to control components connected to the other Argon.