[SOLVED] Config/Setup for PHOTON WiFi bridge connection to LOCAL SERVER

Is it possible to WiFi connect a PHOTON to a Local Server running on PC (hard wired to modem)?? Still UNABLE to connect to local server… I find other HW examples but not PHOTON… PLEASE, Please help… (Please)

I need the model for:

  1. connecting two PHOTONs
  2. Using Bridge … WidgetBridge bridge1(V3);
  3. To a private LOCAL server (Win 10 PC based, HARD WIRED to Comcast modem)
  4. Connecting wireless, Photon to Comcast Modem, to wired to PC Server

Have been successful connecting to Blynk Server, but never to LOCAL server.

This is my current FAILing setup:

SYSTEM_MODE(SEMI_AUTOMATIC);

WiFi.on();

delay (1000);

Blynk.config(ssid,pass); // actual connection will happen in the AUTO start section

Blynk.config(CV_Transmitter,localserver,8442 );

// tried this in frustration Blynk.disconnect();

//NOTE: this errors… has no member Blynk.connectWiFi(ssid,pass);

// WiFi.connect(); // tried this

// Blynk.begin(CV_Transmitter,localserver,8442 )// tried this

//Blynk.connect(); // tried to force this here

Both attempts below at starting and restarting continually fail…

SETUP USES THIS…

int mytimeout = millis() / 1000;
while (Blynk.connect(1000) == false)
{        // wait here until connected to the server
	if ((millis() / 1000) > mytimeout + 8)
	{      // try to connect to the server for less than 9 seconds
		break;                                    
	}  // END IF
}  // End WHILE

Timer triggers THIS RESTART…

void reconnectBlynk() // reconnect to server if disconnected, timer checks every 15 seconds
{
if (!Blynk.connected())
{
if (Blynk.connect()) { BLYNK_LOG(“Reconnected”); Serial.println(“DDD Reconnected”); } // END if

	else { BLYNK_LOG("Not reconnected");    Serial.println("           EEEE  Not reconnected"); }  // END else
}  // End if

Hello and Welcome to the Blynk Forum.

There are many resources here to help you learn how Blynk works, so that you can learn to control anything you want.

At the Upper Right of this page there are links to the Documents, Help Center and Sketch Builder, where you can learn the commands and see many example sketches that will help you get started.

We (other Forum Users) are not part of a code factory, but we will assist you, each as best able, along your journey.

First off, I recommend you spend some time searching this forum for other Photon & Local Server topics (i.e. check out the SOLVED one)

https://community.blynk.cc/search?q=photon%20local%20server

Then study how Bridge works and search for examples here as well as in the Sketch builder:

https://examples.blynk.cc/?board=Particle%20Photon&shield=Particle%20WiFi&example=Widgets%2FBridge

Thanks for the fast reply. I looked at the recommended posts. I have invested a significant amount time researching, still looking for advise, not code creation.
I have completed code that operates correctly using the BLYNK cloud server.

I fear that my new effort, setup of the LOCAL server is the issue, since the new code attempt does not connect.

Gunner, I have learned a lot from looking at your recommendations over the past 4 days; please recommend how to debug the server connection.

1 What is the proper sequence of commands to initialize the connection?

WiFi.on();
Blynk.config (ssid,pass); // set the PW

Blynk.config(CV_Transmitter,localserver,8442 );
OR
Blynk.begin(CV_Transmitter,localserver,8442 );

Blynk.connect();

2 Should the server logs be indicating my attempts at connection? Where can I look? My logs have nothing except the time the server was started.

Or, do you see something easier I have missed?

Thanks…

I am not familiar enough with the Photon, but a bit of trial & error may be required, perhaps something like:

Blynk.begin(auth, IPAddress(xx,xx,xx,xx);
// Or
Blynk.begin(auth, SSID, pass, IPAddress(XXX,XXX,XXX,XXX));  
// Note use of commas not periods and port appears assumed but perhaps could be added with :XXXX

As per these directions:
https://github.com/blynkkk/blynk-server#app-and-sketch-changes

Thanks again.
#1.
I already have over 7 hours experimenting and researching getting the functional CLOUD operating code running on the LOCAL server. I will quit for tonight and start with a fresh perspective tomorrow… I hope.

#2
The I think this command is “defective”:
Blynk.begin(auth, SSID, pass, IPAddress(XXX,XXX,XXX,XXX));

This 4 argument structure compiles in the ARDUINO IDE for the ESP8266, but will NOT compile in the Particle IDE. This was an 1.5 hour investment discovering the problem, looking at working examples of the 8266 code that may not be debugged for PHOTON.

#3
Another documentation issue… this command does not compile in the Particle IDE.

//NOTE: this errors… has no member
Blynk.connectWiFi(ssid,pass);

Are you skilled at notification of errors for the BLYNK team?

Thanks for the advice… I will struggle on.

No, just a forum volunteer.

However I don’t think the issues are “defective” commands, rather how the Particle IDE handles them. And the commands will generate errors if they are not recognised by the installed libraries… solution, install correct libraries (for MCU type) or remove incorrect commands (for MCU type).

If you are still having problems, perhaps also ask over on the Particle forum:

Above commands work fine for me in Particle IDE. @vshymanskyy please advice


here in BlynkParticle class you’ll find all possible begin and configure methods.

On photon, better to leave wifi ssid and pass management to the core itself…

Thanks to you all for looking at my function issues. I am not skilled at looking deep into analyzing how code overwrites function.

Errors for the two commands are below. Would like suggestions for aligning my PC setup. Should I be discussing these with Particle IDE folks rather than BLYNK? Could it be that the ESP8266 libraries (where the functions work correctly in ARDUINO IDE) are different than PHOTON libraries?

Blynk.connectWiFi(ssid,pass);

deletemeifyouwant.ino: In function ‘void setup()’:
deletemeifyouwant.ino:18:7: error: ‘class BlynkParticle’ has no member named ‘connectWiFi’
deletemeifyouwant.ino:21:1: error: a function-definition is not allowed here before ‘{’ token

Blynk.begin( CV_Transmitter, ssid, pass, localserver );

deletemeifyouwant.ino:20:54: error: no matching function for call to ‘BlynkParticle::begin(char [33], char [13], char [9], char [16])’
deletemeifyouwant.ino:20:54: note: candidates are:
In file included from lib/blynk/src/BlynkSimpleParticle.h:14:0,
from lib/blynk/src/blynk.h:11,
from deletemeifyouwant.ino:2:
lib/blynk/src/BlynkParticle.h:92:10: note: void BlynkParticle::begin(const char*, const char*, uint16_t)
void begin( const char* auth,
^
lib/blynk/src/BlynkParticle.h:92:10: note: candidate expects 3 arguments, 4 provided
lib/blynk/src/BlynkParticle.h:101:10: note: void BlynkParticle::begin(const char*, IPAddress, uint16_t)
void begin( const char* auth,
^
lib/blynk/src/BlynkParticle.h:101:10: note: candidate expects 3 arguments, 4 provided

I am a bit afraid when you say this…but also possibly encouraged by BLYNK simplicity. So…

PHOTON is properly pre-configured with my ssid and pass.

Then I should ONLY need:

Blynk.disconnect(); // assure Blynk cloud server is gone
Blynk.config(CV_Transmitter,localserver,8442 ); // where definition is… char localserver[16] = “10.0.0.13”;
Blynk.connect();

to correctly connect to my LOCAL server???

Followed by logic for…
Blynk.run();

Advise please… thanks…

You don’t need this.

Thank you Costas… your posted information has been a huge resource to my learning over the past 3 weeks.

Costas… Do you have any advise for debugging how to connect to my local server? Server is the new adventure for my week; do not have any previous experience. Will be back working later in the day. Thanks for reading…

I just followed the guide (for Pi as local server) and it was pretty straightforward.

Paste your server logs if it’s not working.

Again, you should not specify wifi ssid and password at all.

Please help by confirming that the SERVER setup is proper. Then, I am off to the PARTICLE community to see what may be an issue in the PHOTON. Thanks

Here is the server setup…
Microsoft Windows [Version 10.0.14393]
© 2016 Microsoft Corporation. All rights reserved.

C:\Users\r>D:\BLYNK_Server_Data\zStartBlynkServer.cmd


Starting Blynk Server
Script created by
Waleed El-Badry
waleed.elbadry@must.edu.eg


Your working directory is D:\BLYNK_Server_Data\



Local Server IP Address is: 10.0.0.166
Hardware Port : 8442
Application Port : 8443


Available server files
Volume in drive D is H BOOT 1TB
Volume Serial Number is D068-4CDD

Directory of D:\BLYNK_Server_Data

07/06/17 08:52 PM 16,806,240 server-0.25.3.jar
1 File(s) 16,806,240 bytes
0 Dir(s) 471,476,023,296 bytes free

D:\BLYNK_Server_Data>echo Server latest version on folder is server-0.25.3.jar
Server latest version on folder is server-0.25.3.jar

D:\BLYNK_Server_Data>java -jar server-0.25.3.jar -dataFolder /path
WARNING : ‘/path’ does not exists. Please specify correct -dataFolder parameter.
Your data may be lost during server restart. Using temp folder : C:\Users\r\AppData\Local\Temp\blynk

Blynk Server 0.25.3 successfully started.
All server output is stored in folder ‘D:\BLYNK_Server_Data.\logs’ file.

Code Lockup
This is the code that LOCKS FOREVER waiting for something at the server…

With these Definitions…
char CV_Transmitter[] = “xxxxxxxxxx”; // Special token for Transmitter
IPAddress server_ip (10,0,0,166) ; // COMCAST modem… I forced for this ip

This line “locks” the progress of code; never get past this and out of SETUP

Blynk.begin(CV_Transmitter, server_ip, 8442 );

Particle Cloud
While progress is locked, PHOTON is blinking and communicating with the PARTICLE cloud, so I assume that the micro is blocking another connection to the LOCAL???

Posting your entire (current) code will help give us a clearer picture.

Thank you for the great interest… tried to keep the code away and focus on what I thought was the issue, but relish the hope that you can find a simple issue remaining. I am thinking it is the PHOTON, so I do not look silly with simple code errors. Thanks…again…

CODE FOLLOWS

// This #include statement was automatically added by the Particle IDE.
#include <blynk.h>

//  BlynkTransmitterLOCAL_3

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

//SYSTEM_MODE(AUTOMATIC);
//SYSTEM_MODE(SEMI_AUTOMATIC);   // WiFI is OFF until manually started

char CV_Transmitter[]	= "zzzz";  // Special token for Transmitter
char CV_receiver_11[]	= "zzzz";  // Token for Reciever
char CV_master[]		= "zzzz";  // Original Token for Phone APP

char ssid[] = "CV_HOME-7AA8";
char pass[] = "xxxxx";

char localserver[16] = "10.0.0.166";
IPAddress server_ip (10,0,0,166) ; 
int RemoteLED1 = D7;  // pin D7
static bool value = true;
static bool valueRemoteLED1 = true;

// Bridge widget on virtual pin 
WidgetBridge bridge1(V3);  // changed to new V just because 

// Timer for blynking
BlynkTimer timer;

// Here we will send HIGH or LOW once per second
void blynkAnotherDevice()
{
	if (value)
	{
		bridge1.digitalWrite(7, HIGH);  // Digital Pin 9 on the second board will be set HIGH
		digitalWrite(7, HIGH);          // LOCAL LED	
										// Sends  value to BLYNK_WRITE(Vx) handler on receiving side.
										// do not know which is the proper format.. sample code had NO ""
		bridge1.virtualWrite(V1, "99");
		bridge1.virtualWrite(V25, 99);
		Serial.println("222 blink ON  and V35 = 99 ");
	} // end if 

	else {
		Serial.println("333 blink OFF and V35 = 11 ");
		bridge1.digitalWrite(7, LOW); // Digital Pin 9 on the second board will be set LOW
		digitalWrite(7, LOW);   // LOCAL LED	

		bridge1.virtualWrite(V1, "11");
		bridge1.virtualWrite(V25, 11);   // this sample code had NO ""
	    }  // ENd else 

	 // Toggle value
	value = !value;
}

BLYNK_CONNECTED() {
	bridge1.setAuthToken("CV_receiver_11"); // Place the AuthToken of the second hardware here
}

void setup()
{
	Serial.begin(9600);

	// Use LEDs  as a diagnostic
	pinMode(0, OUTPUT);
	pinMode(1, OUTPUT);
	pinMode(2, OUTPUT);
	pinMode(3, OUTPUT);
	pinMode(4, OUTPUT);
	pinMode(5, OUTPUT);
	pinMode(6, OUTPUT);
	pinMode(7, OUTPUT);
	
	digitalWrite(1, HIGH);   // Turn ON the LED
    ///	  Serial.println("111 WiFI ON");


    delay (300);

///Blynk.config(CV_Transmitter,localserver,8442  );
// this locks 	Blynk.begin(CV_Transmitter,localserver,8442  );
//	this locks 	Blynk.begin(CV_Transmitter,"10.0.0.166",8442  );
// this locks 	Blynk.begin(CV_Transmitter,(10,0,0,166),8442  );	
// this locks	
Blynk.begin(CV_Transmitter, server_ip, 8442  );

// ths also locks  	Blynk.begin(CV_Transmitter,localserver,8443  );  // try another port 
//Blynk.connect(); 
	digitalWrite(2, HIGH); 
    //	  Serial.println("222 WiFi Connected ");

// for Phone Server	Blynk.begin(CV_Transmitter);

//IPAddress server_ip (10,0,0,13) ;  
//	  digitalWrite(2, HIGH);   // Turn ON the LED
// hangs here??? 	Blynk.begin(CV_Transmitter,localserver,8442  );

  digitalWrite(3, HIGH);   // Turn ON the LED
	  
	int mytimeout = millis() / 1000;
	while (Blynk.connect(1000) == false)
	{        // wait here until connected to the server
		if ((millis() / 1000) > mytimeout + 4)
		{      // try to connect to the server for less than 9 seconds
		
		digitalWrite(1, LOW);
		digitalWrite(2, LOW);
			break;                    // continue with the sketch regardless of connection to the s
		}  // END IF
	} // END WHILE

// DIAGNOSTIC remove later
	if ( Blynk.connected() )	{	   Serial.println("BBB  Connected"); } // END if 
	if (!Blynk.connected() )	{	   Serial.println(" CCC  NOT Connected"); } // END if 

					   /// delay(2000);
	//Serial.println("Exiting SETUP JUL 6 V 2");
	// Call blynkAnotherDevice every x second
	timer.setInterval(3000L, blynkAnotherDevice);
	timer.setInterval(1000L, reconnectBlynk); // check every x seconds if we are connected to the server
}  // END Setup 


void reconnectBlynk() // reconnect to server if disconnected, timer checks every 15 seconds
{
	if (!Blynk.connected())
	{
		if (Blynk.connect()) { BLYNK_LOG("Reconnected");      Serial.println("DDD  Reconnected"); } // END if 
		else                 { BLYNK_LOG("Not reconnected");  Serial.println("      EEEE  Not reconnected"); }  // END else
	}  // End if
}  // END reconnectBlynk

void loop()
{

	// to ensure that Blynk.run() function is only called if we are still connected to the server
	if (Blynk.connected()) { Blynk.run(); 	 digitalWrite(5, LOW ); digitalWrite(0, HIGH); }  // ENd if  
	if (!Blynk.connected()) { 	 digitalWrite(0, LOW ); digitalWrite(5, HIGH); }     //  Serial.println("99  DISconnect detected in LOOP  "); }

	timer.run();
}

I’m not quite sure what you were attempting here, but I believe Blynk.run() needs to be called all the time in order to even be connectable to the server.

Try this…

void loop()
{
Blynk.run();
timer.run();
	if (Blynk.connected()) {  // Runs if connected
          digitalWrite(5, LOW ); digitalWrite(0, HIGH);  
          } else {  // Runs if disconnected
         digitalWrite(0, LOW ); digitalWrite(5, HIGH);
         Serial.println("99  DISconnect detected in LOOP  "); 
         } // ENd if
}