Hello! So I am currently unable to connect to my Photon over serial using Putty or Particle Dev. However, if close Particle Dev and then unplug and plug everything back in, suddenly serial will work for me again. The really strange part however is that it’s running an old version of the code which I can tell by the wrong Serial.print() outputs showing up on the serial terminal. I reflash the photon back to the new code and the serial stops once again. If I reflash to the old code that it seems to somehow still have on there, the serial stops as well. I can only open serial after I restart everything like I mentioned before.
I’ve tried safe mode and listening mode and in both I can see the device and which COM it’s on, but I can’t connect to it for some reason. I’ve tried switching out cables and adding a USB2.0 hub like I’ve seen some other threads mention and still no luck. Any help would be greatly appreciated!
Here’s the new code:
//Here we declare our server and our client objects
TCPServer server = TCPServer(80);
TCPClient client;
//Here we have the IP address for the other photon we're communication with and
//it's port number.
byte IP[4] = {192,168,11,101};
int port = 81;
//This is a value unique to this code to send out
byte val = 0x0f;
//Here's the pin for the button we're using
/*int buttonPin = D0;
//User LED pin
int userLED = D7;
//Array used for debouncing the switch
uint8_t debounce = 0b00000000;
//Holds the state of the userLED
bool userLED_state = false;*/
void setup() {
//Turn off wifi so we can set up our static ip
WiFi.off();
//Set static ip info
IPAddress myAddress(192,168,11,100);
IPAddress netmask(255,255,255,0);
IPAddress gateway(192,168,11,1);
IPAddress dns(192,168,11,1);
//Actually set the static ip
WiFi.setStaticIP(myAddress, netmask, gateway, dns);
//Tell the photon to use the static ip
WiFi.useStaticIP();
//Reconnect to wifi
WiFi.on();
WiFi.connect();
//Start listening for clients
server.begin();
//Start up serial so we can communicate various commands
Serial.begin(9600);
//Hold still and check wifi until we're connected over serial
while(!Serial.available()) Particle.process();
Serial.println("Sup guys! I'm Photon 1!");
//Print out wifi credentials, just to make sure everything is ok
Serial.print("Local IP: ");
Serial.println(WiFi.localIP());
Serial.print("Subnet Mask: ");
Serial.println(WiFi.subnetMask());
Serial.print("gateway IP: ");
Serial.println(WiFi.gatewayIP());
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
//Some pinMode calls to initialize our GPIO
/*pinMode(buttonPin, INPUT);
pinMode(userLED, OUTPUT);
digitalWrite(userLED, LOW);*/
}
void loop() {
//Runs for maintenance
Particle.process();
//If we're connected to a client, which we should be most of the time, send
//a value to the client to make sure we're connected. If not try to connect
//to a client.
if(client.connected())
{
Serial.println("Oh hey there!");
server.write(val);
}
else
{
Serial.println("And nobody came....");
client = server.available();
}
//Here we read
/*debounce = debounce<<1;
debounce |= digitalRead(buttonPin);
Serial.print("debounce: ");
Serial.print(debounce,BIN);
if(debounce == 0b10000000)
{
userLED_state = true;
}
else if(debounce == 0b01111111)
{
userLED_state = false;
}
Serial.print("\tUser LED state: ");
Serial.println(userLED_state);
digitalWrite(userLED, userLED_state);*/
delay(100);
}
Here’s the persistent old code:
TCPServer server = TCPServer(81);
TCPClient client;
byte IP[4] = {192,168,11,100};
int port = 80;
byte val = 0x0f;
void setup() {
//Turn off wifi so we can set up our static ip
WiFi.off();
//Set static ip info
IPAddress myAddress(192,168,11,101);
IPAddress netmask(255,255,255,0);
IPAddress gateway(192,168,11,1);
IPAddress dns(192,168,11,1);
//Actually set the static ip
WiFi.setStaticIP(myAddress, netmask, gateway, dns);
//Tell the photon to use the static ip
WiFi.useStaticIP();
//Reconnect to wifi
WiFi.on();
WiFi.connect();
//Start listening for clients
server.begin();
//Start up serial
Serial.begin(9600);
while(!Serial.available()) Particle.process();
Serial.println("Sup guys! I'm a client!");
//Print out wifi credentials, just to make sure everything is ok
Serial.print("Local IP: ");
Serial.println(WiFi.localIP());
Serial.print("Subnet Mask: ");
Serial.println(WiFi.subnetMask());
Serial.print("gateway IP: ");
Serial.println(WiFi.gatewayIP());
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
if(client.connect(IP,port))
{
Serial.print("Oh hey there!");
}
else
{
Serial.print("And nobody came....");
}
}
void loop() {
Particle.process();
if(client.available())
{
Serial.println("Here's a value! ");
val = client.read();
Serial.println(val);
}
if(!client.connected())
{
Serial.println();
Serial.println("Ok bye...");
client.stop();
for(;;) Particle.process();
}
delay(100);
}