Skills Dev V: Working with Networking

Made by Yi Sun

Created: December 11th, 2022

0

Outcome

    • In this project, we realized communication between two devices through webhook. If my teammate press the button on his side, it will trigger the fan to run in my side.

0

Process

We first generated tokens and creates webhook in each side. It is named as "doPairedPublish" and will trigger "activate" function on the other side. Then we added the button and did some modifications on the code.

At first we tested our circuit on our own side, and my fan didn't run. I found it was because we did not use external power this time and I forgot to connect to microcontroller’s power. 

Then we found one fan cannot be triggered. But we saw on the console that it did receive the event. Then we checked the circuit and found no problems. Finally we figured out that it was because windows have limitations on the power supply to usb-connected device. So the fan didn't get enough power. It only had very small movements.

0
int solPin = D2;
int buttonPin = D3;
bool shouldActivate = false;

void setup() {

    pinMode( solPin, OUTPUT);
    pinMode( buttonPin, INPUT_PULLUP);

    Particle.subscribe( "activate", activateSolenoid );
    // blinkLED( 3, ledPin );

}

void loop() {

    int buttonValue = digitalRead( buttonPin );
    if( buttonValue == LOW ){
        Particle.publish( "doPairedPublish" );
    }

    if( shouldActivate == true ){
       doSolenoid(  );
       shouldActivate = false;
    }

    delay( 1000 );

}

void activateSolenoid( const char *event, const char *data)
{
   shouldActivate = true;
}

void doSolenoid(  ){
  for( int i = 0; i < 5; i++ )
  {
    digitalWrite(solPin, HIGH);
    delay( 2000 ) ;
    digitalWrite(solPin, LOW);
    delay( 1000 );
  }
}
Click to Expand
0

Reflection & Next Steps

From this project, I learned how to use webhook to realize the communication and interaction between devices. It enables us to realize remote control or remote interaction between two persons. In the future, we need to use webhook to pass parameters to pass more information to the other side, to implement our final project.  

x