That is very odd, since the message would be independet of the WiFi connection.
What happens if you enter any other character? Do you get this displayed in your serial monitor?
But just to be on the safe side you can add some other cases to which shoul connect
like this
void loop()
{
int c = Serial.read();
switch (c)
{
case -1:
// nothing to read, so ignore
break;
case '\r': // hit emter to connect
case 'c': // or c
case ' ': // or spacebar / blank
Serial.println("Try to connect to cloud");
Particle.connect();
Serial.println("See cyan blinking?");
default:
Serial.write(c); // echo what we got
}
}
I actually did something similar but it never got the case. I tried with added space and âcâ but I still donât see the âTry to connect to cloudâ message in the serial.
On the other hand. I find if I turn hotspot on my phone, turn airplane mode on and off again, Reboot the phone, turn on hotspot, then reset the Photon it almost always connects and gets an IP Address. As a result Iâm able to try the code snippets again and again.
Whatâs strange is that:
I get a different IP Address each time
On the phone I never see a device connected. When I connect my Surface to my phone for example, I see it appear on the phone instantly and I can see itâs IP address and MAC on the phone.
Holly crap!
It connected.
press Enter
I got a blue led for a split second (2 breadths) and then it switched to flashing green
Never see a âTry to connectâ message in the terminal window, though
I did put a 1 second delay in the loop maybe that helps with capturing just one key press (I donât know)
This happens with all my phones too. They seem to never hand out the same IP twice.
Try this sequence:
Safe Mode
flash above code
clear WiFi credentials
provide only phone hotspot credentials via serial monitor (press w and supply info)
reset device once going to green
try code above
I'm still very puzzled about the missing "Try to connect to cloud" message, since this has to happen.
There is no need for a delay, since the device buffers 64 byte of serial input and will process one by one (unless you type faster than 10k characters per second )
I just edited my earlier post.
I donât ever see the âTry to connect to cloudâ in the terminal window. So Iâm guessing it never gets to the line, so the blue breathing LED may not be indicating connection to the cloud.
Is there a way to:
get the device to connect to the cloud using an IP Address (not sure if thatâs what itâs doing already). I want to see if I
Specify and DNS the device can use (rather than use one from the phone).
As it seems your WiFi is working, but the cloud connection not.
So the next thing to test in between those two states is how good the WiFi actually works.
For that reason Iâll just post you a simple TCPServer code which you can connect to via telnet.
SYSTEM_MODE(SEMI_AUTOMATIC)
TCPClient client;
TCPServer server(79); // first try a safe port
//TCPServer server(5683); // later try the CoAP port for the cloud
void setup() {
Serial.begin(115200);
WiFi.on();
WiFi.connect();
waitUntil(WiFi.ready);
server.begin();
while(Serial.read() < 0) Particle.process();
Serial.printlnf("SSID\t: %s" , (const char*)WiFi.SSID());
Serial.printlnf("Local IP\t: %s", (const char*)WiFi.localIP().toString());
}
void loop() {
char x;
if(!client.connected())
{
client = server.available();
if (client.connected())
{
client.printlnf(" Hi, I am Photon!\r\nHow can I serve you? (%s)", (const char*)client.remoteIP().toString());
}
}
else
{
while(client.available())
{
switch(x = client.read())
{
case '?': // disconnect client
client.println("Good Bye!");
client.stop();
break;
case 'c': // hit c to connect
Serial.println("Try to connect to cloud");
Particle.connect();
Serial.println("See cyan blinking?");
default:
Serial.write(x);
}
}
}
}
first press any key in serial monitor to get the server IP address
the try telnet <ip> 79
type in anything (not containing ?, c) and hit ENTER to test transmission
try c + ENTER to test cloud connection
try ? + ENTER to close the telnet connection
If this works apart from cloud, then change the port number to 5683 and retest to test if the cloud port is blocked on your hotspot - if cloud already works, just the better
On this one Photon, I have cleared credentials (setup down for 10 seconds).So the only credentials I have on there for my phone.
Iâll try the Safe mode step first and see
Here is something else I just tried. I used my wifeâs phoneâs hotspot. Again, the only credentials on the Photon are for that hotspot.
Flashed code
It connects without a problem
Never see the âTry to connect to the cloudâ.
So I tried flashing one of my other apps that works against the eclipse MQTT broker. This app works as expected when connected to WiFi router.
Cleared credentials
Set credentials for Wifeâs phone
Flashed code
Reset the device
I see it connecting and connected to the phone. Phone also reports 1 guest connected (this phone doesnât show IP or MAC)
However, the app doesnât actually work. Basically I can send it messages via the broker and it switches LED color. Doesnât work. The device also sends message to a different topic on the broker. Never receive messages from the device either. Rebooted phone and device and tried all over again. No luck. That is the device is never actually getting on the Internet.
Tried the TCPServer code.
For the first attempt I decided to use the Wifi router to ensure Iâm using the app correctly.
So I cleared credential and set credentials for the Wifi router.
Flashed the code
reset the device and started the serial monitor using CLI
I see the device connected to my router (green breathing LED).
Press any key does not seem to do anything. That is I donât see the IP (or SSSID)
I jumped on to my router and I can see the device is connected, so I got the IP address from there and using telnet, I attempted to connect to it on port 79
No luck there either.
Iâm looking at the code above but I canât see what Iâm missing
Are both phones going via the same provider/carrier?
Can other Photons get online via these phones?
Yes, they use AT&T
I use my Surface via my phone almost every day. I just tried connecting each phone to the other and browsing various websites. All works as expected.
That explains some things
AFAIK CLI is only a monitor which does just display serial output, but does not actually send things to the device.
Try PuTTY or any other duplex serial monitor - even Particel Dev Serial Monitor would do.
By the way, I originally had the same misunderstanding with particle serial monitor. I kept wondering why my code wasnât allowing me to hit a key to continue! Itâs because it literally only monitors, and does not allow you to send.
Tried the original code (not the TCP Server code)
Device connects to my phone
I see the various messages in terminal program
Press âcâ and I see the message as well as the blinking blue led (blinking, not breathing).
Yay!
HmmrphâŚ
The see the led go to a dim blue (almost like it went into listen mode) for a split second. Then green flashing LED.
Tried the same with my wifeâs phone (clearing credentials before). Same result.
I think I saw a short orange/red blip/burst there after the cyan, which would indicate a problem with the key exchange during cloud handshake.
But the device connects fine when you are going through your router?
If not, you could try
particle keys doctor
to repair the keys, but if it does work with the router, the phone hotspot seems to interfere.
BTW: Did you give the TCPServer a go? This might also show if the connection is flaky which is especially problematic during key exchange.
I donât know if this makes a difference, but Iâve never used the Particle cloud except for the Web IDE and flashing my devices. I know the devices can get on the Internet via my router since everything Iâm doing is Internet dependent. I mainly use http://iot.eclipse.org as my MQTT broker or I run Mosquito locally while developing/testing.
I tried the TCP server app. I had to get my desktop connected to the cell phones hotspot. I tried my wifeâs cell phone first. And the program works as expected using port 79.
Now Iâm going to try my cell phone also using port 79.