Triggering Blue Iris (Camera Software) with a nodeMCU (esp8266)

My application is for a trip wire to make a digital input go high, then send a GET (I think this is what it is but really not so sure about this) request to Blue Iris on my PC that triggers a camera to record. Bonus of doing it this way is I also believe I will also be able to talk to tasker in the same manner (on a separate android box) to turn lights on etc.

I have seen post around but they are either using the serial trigger, or using IOT, or sending commands/triggers each way which complicates things over what I require..

I should note I am using just a Nodemcu for this task, where I used an arduino/esp8266 combo for my last project.

I really don't understand much depth in what I am trying to do, so the following code could be completely wrong.

I used another example of where they were using an ethernet shield and communicating both ways, but I copied (and modified) the components I thought where relevant to triggering motion on my camera's when a digital input goes high.

I believe the command to send to the Blue Iris server is (and is what the function at the end of my code does, but with more details ??required??)

http://110.146.%%%.%%:818/admin?camera=Car&trigger&user=admin&pw=password

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Social networks:            http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  This example runs directly on NodeMCU.

  Note: This requires ESP8266 support package:
    https://github.com/esp8266/Arduino

  Please be sure to select the right NodeMCU module
  in the Tools -> Board menu!

  For advanced settings please follow ESP examples :
   - ESP8266_Standalone_Manual_IP.ino
   - ESP8266_Standalone_SmartConfig.ino
   - ESP8266_Standalone_SSL.ino

  Change WiFi ssid, pass, and Blynk auth token to run :)
  Feel free to apply it to any other example. It's simple!
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

int sideGate = 0;
int drivewayGate = 0;
int triggerDrivewayGate = 0;
int triggerSideGate = 0;

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "###";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "###";
char pass[] = "###";

  // BlueIris
  
WiFiClient client;
char BIserver[] = "###.###.###.###"; // IP Adres of Blue Iris Server. // CHANGE THIS

char user[] = "###"; //Username for Blue Iris Server // CHANGE THIS
char pass2[] = "###"; //Password for Blue Iris Server // CHANGE THIS
String stringOne = "camera";

void setup()
{
  // Debug console

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);



  // digitial pin states

  pinMode(5, INPUT); // box led switch
  pinMode(4, INPUT);  // onboard led switch
}



void loop()
{
  Blynk.run();

  //read digital switch pins
  sideGate = digitalRead(5); // read push button switch
  drivewayGate = digitalRead(4); // read pedal switch

  if (sideGate == 1)
  {
    if (triggerSideGate == 0) // stops multiple triggers while high
    {
      Blynk.email("#######", "Side Gate triggered", " ");
      triggerSideGate = 1;
      stringOne = "Car";                     //"Cam1" = Short camera name in blue iris
      triggerBI();
    }
  }
  else
  {
    triggerSideGate = 0;
  }

  if (drivewayGate == 1)
  {
    if (triggerDrivewayGate == 0)
    {
      Blynk.email("####", "Driveway Gate triggered", " ");
      triggerDrivewayGate = 1;
      stringOne = "BackPatio";                     //"Cam1" = Short camera name in blue iris, this will be triggered if digital input 2 is high // CHANGE THIS
      triggerBI();
    }
  }
  else
  {
    triggerDrivewayGate = 0;
  }
}

void triggerBI() {                            // sending the trigger to Blue Iris web-server

  WiFiClient client;

  if (client.connect(BIserver, 818)) {             // (81) Port number of the Blue Iris web server //CHANGE THIS if you don't use port 81.
    // Make a HTTP request:
    client.print( "GET /admin?camera=");
    client.print(stringOne);
    client.print( "&trigger&user=");
    client.print( user);
    client.print( "&pw=");
    client.print( pass2);
    client.println( " HTTP/1.1");
    client.print( "Host: " );
    client.println(BIserver);
    client.println( "Connection: close" );
    client.println();
    client.println();
    client.stop();
  }

}

Updated my text to explain what I am trying to do a little better.

What are you really sending to Blynk.email()? How is that supposed to trigger a GET request?

Sorry. The send email was so I could easily detect when the digital inputs went high. More to ensure that the system was behaving properly (the circuit and digital inputs).

The triggerBI() at the bottom of the code is the function I thought should be doing the GET request.

Problem is it called the Ethernet.h library so I changed it to the wifi.h library which I don't think works with the nodemcu so the changed to the esp8266wifi library but not sure about the lines with ' WiFiClient client;" as" esp8266wifi" client doesn't work..

As you can see, I'm new here and don't really understand what I've copied and modified very well at this stage so can't even start debugging easily. I understand the digital channels and if conditions however.

  if (client.connect(BIserver, 818)) {             // (81) Port number of the Blue Iris web server //CHANGE THIS if you don't use port 81.

If you are going to have useless comments, they MUST be accurate useless comments.

    client.print( "&trigger&user=");

The data in the GET request is usually in the form of name=value pairs, separated by &s. What is the value associated with trigger?

which I don't think works with the nodemcu

If the code compiles, WiFiClient is a class defined in the ESP8266WiFi header file, so it must be able to work with the ESP8266 device.

Are you able to connect to the camera server?

Thanks.

I've now posted in the Blue Iris forum to see why the url don't seem to work properly in triggering through a web browser. It keeps asking for the user name and password with the url I've tried and then goes to another address on my blue iris server.

I guess I'll need to get the url working first before continuing on the arduino ide coding huh.

I will be back once i can get it working through a browser as I'm keen to get this going.

I've now posted in the Blue Iris forum to see why the url don't seem to work properly in triggering through a web browser. It keeps asking for the user name and password with the url I've tried and then goes to another address on my blue iris server.

Take a break for a couple of hours. Then, come back and read this. Can you figure out what "it" is that keeps asking for the user name and password? I can't.

Ok. I've sorted out an issue in blue iris. It was still asking for authentication with the admin/password in the url. I have made my phone excluded (its fixed ip address) from needing authentication so can now go to the url below and it triggers the camera now.

So will now fix the ip of the esp8266 in the router setup, then spend some time to look more deeply into how to make the esp8266 go to this address now. Maybe start from scratch rather than copying and modifying someone else code as I have done above.

The url that worked was the following so I'm pretty confident I can work that out now... Always welcome to given advice, but I should probably make more of an effort and more mistakes before posted here I admit.

http://192.168.1.100:818/admin?camera=Carport&trigger

PaulS:
Take a break for a couple of hours. Then, come back and read this. Can you figure out what "it" is that keeps asking for the user name and password? I can't.

"It" was the browser, well the blue iris server, asking for a login still. Think that was some of the problem.

I have changed my code to the following. I'm somewhat more confident now I understand the code a little more, but won't have a chance to test it for another 12 hours.

cameraname is a string of the camera's name I want to trigger. BIserver is the fixed local ip of the bluebirds server.

void triggerBI() {                            // sending the trigger to Blue Iris web-server

  WiFiClient client;

  if (client.connect(BIserver, 818)) {             //Port number of the Blue Iris web server
    // Make a HTTP request:
    client.print( "GET /admin?camera=");
    client.print(cameraname);
    client.print( "&trigger");
    client.println( " HTTP/1.1");
    client.print( "Host: " );
    client.println(BIserver);
    client.println( "Connection: close" );
    client.println();
    client.println();
    client.stop();
  }

Works well. I've modified the if conditions and made more camera trigger functions and will likely make further polishing but I'm happy for easily it came together