Cloud Wifi Attachment

Expansion modules and attachments
benjy1234
Posts: 19
Joined: Mon May 23, 2016 7:22 pm

Re: Cloud Wifi Attachment

Post by benjy1234 »

Any idea when it will be back in stock Roberto?
Image
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Cloud Wifi Attachment

Post by slm222 »

I just ordered mine!

is the controller moving away from the desktop app for uploading code and going to the web based app from now on?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Cloud Wifi Attachment

Post by rimai »

That's the plan.
It's much easier to get updates to the wizard.
Roberto.
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Cloud Wifi Attachment

Post by slm222 »

I got it in and working. I am running into two issues after switching it out and using the iphone app

1. I changed my labels, below, and now they are not showing up on my reef angel screen and on the uapp when i click download from portal it is pulling the old labels.

Code: Select all

    ReefAngel.CustomLabels[0]="OPEN"; //1
    ReefAngel.CustomLabels[1]="Skimmer"; //2
    ReefAngel.CustomLabels[2]="FugeLight"; //3
    ReefAngel.CustomLabels[3]="Heater"; //4
    ReefAngel.CustomLabels[4]="OPEN"; //5
    ReefAngel.CustomLabels[5]="OPEN"; //6
    ReefAngel.CustomLabels[6]="ATO"; //7
    ReefAngel.CustomLabels[7]="OPEN"; //8
2. i changed my settings on the iphone app to the cloud server with correct password and username and it just keeps saying connecting
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Cloud Wifi Attachment

Post by rimai »

RA cannot download labels.
You need to change them in the code.
You can only download labels in the iphone app that you have setup on the portal.
So, the portal and the uapp share the same labels, but the ones in the screen need to be setup on your code.
The problem is that I think I screwed it up.
I changed the custom lables on the new libraries to be pulled from flash instead of using up RAM memory to avoid RAM memory usage, which was causing undesirable results.
When I created the web wizard, which uses the new libraries, I didn't give you the ability to change them :(
The iphone uapp also needs to be updated to be able to connect to the cloud server. We have not released the update yet.
The only way to get the cloud server connection is to use the web based uapp: http://forum.reefangel.com/uapp
I wanted to make sure the framework was good before I release a new update for iphone.
Roberto.
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Cloud Wifi Attachment

Post by slm222 »

Thanks for the quick reply. And a big 10/4 on the future app release. That code above is from my sketch loaded with the web-based loader. With that it's not showing up in the display. Do I need to do something different?
dapg8gt
Posts: 104
Joined: Tue Apr 16, 2013 7:33 pm
Location: 650 Bay Area..

Re: Cloud Wifi Attachment

Post by dapg8gt »

Add me to the list of wanting to order one as soon as they are available.

I have my raceway in my garage on an RA without any means to add it to an app or control it, it's more of a monitoring thing due to my all in one xfinity gateway not allowing me to change internal port forwarding channels so I can only control one RA remotely. Was just thinking of bridging my router and buying a new better one just for the RA's but this is so much easier =) .. So I can use this big time for the second tank..

Guessing it won't be an issue having two of these on the same app.. Or will there be an issue? Most likely gonna just keep the main tank going with the standard wifi for now but curious if it is possible with the u app..

Shoot me a Pm or whatever with an Eta for the next shipment I'll grab one ASAP..
My other hobby has 450rwhp and eats tires instead of mysis!
GugsJr
Posts: 68
Joined: Fri Jun 20, 2014 6:30 am

Re: Cloud Wifi Attachment

Post by GugsJr »

With this attachment can I upload code with out having to tether a cable to the reef angel from my laptop?

If so can you let me know when they are in, I'd like to order this with the salinity expansion
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Cloud Wifi Attachment

Post by rimai »

No, you need the bluetooth attachment to do that.
http://forum.reefangel.com/viewtopic.php?f=3&t=3372
Roberto.
Kungpaoshizi
Posts: 52
Joined: Wed Sep 16, 2015 8:12 am

Re: Cloud Wifi Attachment

Post by Kungpaoshizi »

Can we expect code uploads via the device someday?
I think that's one thing I would really like... Though I have gotten to the point where my reef tank setup is simple enough I don't need to change anything... lol
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Cloud Wifi Attachment

Post by rimai »

I could happen. I don't think there is anything out there yet to leverage so we would need to replicate the STK500v2 protocol on the cloud wifi attachment to be able to upload remotely.
Roberto.
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Cloud Wifi Attachment

Post by slm222 »

I'm not sure what is going on, but I've had the cloud wifi app for a couple months now and it has started going to a solid green light from the blue connected light. Nothing has changed in setup or placement of it or the wifi router. I check the pins and everything is fine. It's on the side of the tank, so no moisture to speak of. I've been having to unplug it and re plug it back in. Sometime I have to do that a couple times before it reconnects. It is 12-15' away from the router
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Cloud Wifi Attachment

Post by rimai »

Do you have a computer that you can connect to the module and leave it logging to see what happens?
If so, connect the usb cable to the cloud wifi module and open Arduino. Then go to Tools->Serial monitor.
You should start seeing the log.
Roberto.
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Cloud Wifi Attachment

Post by slm222 »

I will do that and post back. What I noticed is interesting is when it is connected after a while I go and check via the U-App and then it goes to green and eventually reconnects
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Cloud Wifi Attachment

Post by slm222 »

Code: Select all

PH:809
PH:808
PWMD:0
PWMA:38
PWMD:38
PWMA:0
PWMD:0
PWMA:38
PWMD:38
PWMA:0
PWMD:0
PWMA:38
PH:809
PH:808
PWMD:38
PWMA:0
PWMD:0
PWMA:38
PWMD:38
PWMA:0
PWMD:0
PWMA:38
PH:809
PH:808
PWMD:38
PWMA:0
PWMD:0
PH:809
PH:808
Connecting to Portal Server
Connected
Disconnecting from Portal Server
PWMD:38
PH:809
PH:808
T1:786
T1:784
T1:786
T1:784
all:0
ATOLOW:0
ATOHIGH:0
EM:0
EM1:2
REM:0
BID:1
AF:0
SF:0
PWMD:38
PWMA:0
PWMDO:255
PWMAO:255
R1:0
ROFF1:0
RON1:0
R2:0
ROFF2:0
RON2:0
R3:0
ROFF3:0
RON3:0
R4:0
ROFF4:0
RON4:0
R5:0
ROFF5:0
RON5:0
R6:0
ROFF6:0
RON6:0
R7:0
ROFF7:0
RON7:0
R8:0
ROFF8:0
RON8:0
ALARM:0
PWMD2:0
PWMA2:0
PWMD2O:0
PWMA2O:0
WL:0
WL1:0
WL2:0
WL3:0
WL4:0
HUM:0
DCM:5
DCS:38
DCD:50
DCT:20
PWME0:0
PWME1:0
PWME2:0
PWME3:0
PWME4:0
PWME5:0
PWME0O:0
PWME1O:0
PWME2O:0
PWME3O:0
PWME4O:0
PWME5O:0
AIW:0
AIB:0
AIRB:0
RFM:0
RFS:0
RFD:0
RFW:0
RFRB:0
RFR:0
RFG:0
RFB:0
RFI:0
RFWO:0
RFRBO:0
RFRO:0
RFGO:0
RFBO:0
RFIO:0
IO:0
LEAK:0
C0:0
C1:0
C2:0
C3:0
C4:0
C5:0
C6:0
C7:0
R:183
ROFF:66
RON:0
T1:784
T2:0
T3:0
PH:808
ORP:0
SAL:0
PHE:0
PAR:0
CEXP0:0
CEXP1:0
CEXP2:0
CEXP3:0
CEXP4:0
CEXP5:0
CEXP6:0
CEXP7:0
Connecting to Portal Server
Connected
Disconnecting from Portal Server
T1:786
T1:784
PWMA:20
Connecting to Portal Server
Connected
Disconnecting from Portal Server
T1:786
T1:784
T1:786
T1:784
PWMA:21
PWMA:22
PWMA:23
PWMA:24
PWMA:25
PWMA:26
PWMA:27
PWMA:28
PWMA:29
Connecting to Portal Server
Connected
PWMA:30
Disconnecting from Portal Server
PWMA:31
T1:786
T1:784
PWMA:32
PWMA:33
PWMA:34
T1:786
T1:784
PWMA:35
T1:786
T1:784
PWMA:36
T1:786
T1:784
PWMA:37
T1:786
T1:784
T1:786
T1:784
PWMA:38
PWMA:37
Connecting to Portal Server
Connected
T1:786
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
MQTT Connecting...
MQTT failed
Connecting to Portal Server
Failed to connect
Disconnecting from Portal Server
MQTT Connecting... 
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Cloud Wifi Attachment

Post by rimai »

It does seem that it is loosing the connection and can't reconnect again for some reason.
Let me see if I can find anything with the firmware.
Roberto.
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Cloud Wifi Attachment

Post by slm222 »

Thank you Rimai. Most of today it has not been connected, just blinking green. If it makes any difference I had used the webwizard to program the reef angel plus.
LucianoB
Posts: 23
Joined: Fri Mar 11, 2016 4:39 pm

Re: Cloud Wifi Attachment

Post by LucianoB »

slm222 wrote:Thank you Rimai. Most of today it has not been connected, just blinking green. If it makes any difference I had used the webwizard to program the reef angel plus.
Hi. What Router are you using?
I has a lot of the problems with one mikrotik Router. I changed that so everything are working fine.. if you can only test with another Router.

Regards from Argentina.
Cheers

Enviado desde mi Nexus 5 mediante Tapatalk
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Cloud Wifi Attachment

Post by rimai »

See if this code makes any difference.

Code: Select all

#include <SPI.h>
#include <WiFi101.h>
#include <PubSubClient.h>
#include <RA_CustomSettings.h>

//char ssid[32];
//char pass[32];
//char username[16];
//char password[16];

unsigned long client_timeout = millis();
unsigned long wifi_connection = millis();
unsigned long serial_timeout = millis();
unsigned long led_blink = millis();
unsigned long MQTTReconnectmillis = millis();

boolean LED_status = false;
boolean PortalConnection = false;
boolean power_status = true;
boolean data_ready = false;
int status = WL_IDLE_STATUS;
int connection_counter=0;
WiFiServer server(2000);
WiFiClient client;
WiFiClient portalclient;
WiFiClient mqttclient;

void mqttcallback(char* topic, byte* payload, unsigned int length);

PubSubClient CloudClient(MQTTServer, MQTTPORT, mqttcallback, mqttclient);

String currentLine = "";                // make a String to hold incoming data from the client

void setup() {
  Serial.begin(57600);      // initialize serial communication
  Serial1.begin(57600);      // initialize serial communication
  pinMode(5, OUTPUT);      // set the LED pin mode
  pinMode(6, OUTPUT);      // set the LED pin mode
  pinMode(7, OUTPUT);      // set the LED pin mode
  wdt_initialize();
  wdt_enable();
}

void loop() {
  wdt_reset();
  status = WiFi.status();
  while ( status != WL_CONNECTED) {
    digitalWrite(5, false);
    digitalWrite(6, true);
    digitalWrite(7, false);
    if (millis() - wifi_connection > 1000)
    {
      wifi_connection = millis();
      Serial.print("Attempting to connect to Network named: ");
      Serial.println(WIFI_SSID);                   // print the network name (SSID);
      if (WiFi.begin(WIFI_SSID, WIFI_PASS) == WL_CONNECTED)
      {
        status = WiFi.status();
        server.begin();                           // start the web server on port 2000
        printWifiStatus();                        // you're connected now, so print out the status
        digitalWrite(6, false);
        digitalWrite(7, true);
      }
      Serial.println("Not connected...");
    }
    wdt_reset();
  }

  client = server.available();   // listen for incoming clients

  if (client) {                             // if you get a client,
    Serial.println(F("new incoming client"));           // print a message out the serial port
    client_timeout = millis();
    while (client.connected()) {            // loop while the client's connected
      if (millis() - client_timeout > 2000) client.stop();
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        Serial1.write(c);                   // send to Reef Angel
      }
      if (Serial1.available())
      {
        char c = Serial1.read();
        //Serial.write(c);
        currentLine += c;
        serial_timeout = millis();
        if (currentLine.length() == 255) {
          SendData();
        }
      }
      if (millis() - serial_timeout > 400)
      {
        if (currentLine.length() > 0) {
          SendData();
          Serial.println();
          client.println();
        }
      }
      if (millis() - led_blink > 50)
      {
        led_blink = millis();
        LED_status = !LED_status;
        digitalWrite(6, LED_status);
      }
    }
    // close the connection:
    client.stop();
    Serial.println(F("incoming client disconnected"));
    digitalWrite(6, false);
  }
  else
  {
    while (Serial1.available())
    {
      char c = Serial1.read();
      currentLine += c;
      if(c==10) data_ready=true;
      serial_timeout = millis();
      digitalWrite(6, true);
      if (millis() - serial_timeout > 200 || data_ready)
      {
        if (currentLine.length() > 0) 
        {
          data_ready=false;
          serial_timeout = millis();
          //        Serial.print(currentLine);
          if (currentLine.startsWith("GET"))
          {
            PortalConnection = true;
            Serial.println(F("Connecting to Portal Server"));
            if (portalclient.connect(PortalServer, 80)) {
              Serial.println(F("Connected"));
              // Make a HTTP request:
              portalclient.print(currentLine);
              portalclient.println(F(" HTTP/1.1"));
              portalclient.println(F("Host: forum.reefangel.com"));
              portalclient.println(F("Connection: close"));
              portalclient.println();
            }
            else
            {
              Serial.println(F("Failed to connect"));
            }
          }
          if (currentLine.startsWith("CLOUD:"))
          {
            //Serial.print(currentLine);
            if (currentLine.length() < 32)
            {
              if (CloudClient.connected())
              {
                //Serial.println(F("Publishing "));
                currentLine.replace("CLOUD:", "");
                Serial.print(currentLine);
                char pub_buffer[sizeof(CLOUD_USERNAME) + 5];
                sprintf(pub_buffer, "%s/out", CLOUD_USERNAME);
                char pub_msg[currentLine.length() + 1];
                currentLine.toCharArray(pub_msg, currentLine.length() + 1);
                CloudClient.publish(pub_buffer, pub_msg);
              }
            }
            else
            {
              Serial.print(F("Error on incoming data: "));
              Serial.println(currentLine.length());
            }
          }
          currentLine = "";
          digitalWrite(6, false);
        }
      }
    }
    digitalWrite(6, false);    
    while (portalclient.available()) {
      char c = portalclient.read();
      //      Serial.write(c);
    }
    if (PortalConnection && !portalclient.connected()) {
      PortalConnection = false;
      //      Serial.println();
      Serial.println(F("Disconnecting from Portal Server"));
      digitalWrite(6, false);
      portalclient.stop();
    }
  }

  CloudClient.loop();
  if (millis() - MQTTReconnectmillis > 5000)
  {
    if (!CloudClient.connected())
    {
      char sub_buffer[sizeof(CLOUD_USERNAME) + 6];
      MQTTReconnectmillis = millis();
      digitalWrite(6, true);
      Serial.println(F("MQTT Connecting..."));
      Serial.print(F("Attemp: "));
      Serial.println(++connection_counter);
      if (connection_counter>5)
      {
        Serial.println(F("Unable to connect. Rebooting..."));
        digitalWrite(5, true);
        digitalWrite(6, false);
        digitalWrite(7, false);        
        while(1);
      }
      sprintf(sub_buffer, "RA-%s", CLOUD_USERNAME);
      if (CloudClient.connect(sub_buffer, CLOUD_USERNAME, CLOUD_PASSWORD))
      {
        sprintf(sub_buffer, "%s/in/#", CLOUD_USERNAME);
        Serial.println(F("MQTT succeeded"));
        CloudClient.subscribe(sub_buffer);
      }
      else
      {
        MQTTReconnectmillis = millis();
        Serial.println(F("MQTT failed"));
        CloudClient.disconnect();
      }
      digitalWrite(6, false);
    }
  }
  if (analogRead(0) < 600 && power_status)
  {
    power_status = false;
  }
  if (analogRead(0) > 600 && !power_status)
  {
    power_status = true;
  }
}

void SendData()
{
  serial_timeout = millis();
  //  Serial.print(currentLine);
  client.print(currentLine);
  currentLine = "";
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

void mqttcallback(char* topic, byte* payload, unsigned int length)
{
  Serial1.print("cloud:");
  for (int a=0;a<length;a++)
  {
    Serial1.write(payload[a]);
    Serial.write(payload[a]);
  }
  Serial1.print(" ");
  Serial.println();
}

void wdt_initialize()
{
  GCLK->GENDIV.reg = GCLK_GENDIV_ID(2) | GCLK_GENDIV_DIV(4);
  GCLK->GENCTRL.reg = GCLK_GENCTRL_ID(2) |
                      GCLK_GENCTRL_GENEN |
                      GCLK_GENCTRL_SRC_OSCULP32K |
                      GCLK_GENCTRL_DIVSEL;
  while (GCLK->STATUS.bit.SYNCBUSY);  // Syncronize write to GENCTRL reg.
  GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID_WDT |
                      GCLK_CLKCTRL_CLKEN |
                      GCLK_CLKCTRL_GEN_GCLK2;
}

void wdt_enable()
{
  WDT->CTRL.reg &= ~WDT_CTRL_ENABLE;
  while (WDT->STATUS.bit.SYNCBUSY);  // Syncronize write to CTRL reg.
  WDT->CONFIG.reg = WDT_CONFIG_PER(0xA);  // 0xA = 8192 ms
  while (WDT->STATUS.bit.SYNCBUSY);  // Syncronize write to CONFIG reg.
  WDT->INTENCLR.reg |= WDT_INTENCLR_EW;
  WDT->CTRL.reg |= WDT_CTRL_ENABLE;
  while (WDT->STATUS.bit.SYNCBUSY);  // Syncronize write to CTRL reg.
}

void wdt_disable()
{
  WDT->CTRL.reg &= ~WDT_CTRL_ENABLE;
  while (WDT->STATUS.bit.SYNCBUSY);  // Syncronize write to CTRL reg.
}

void wdt_reset()
{
  WDT->CLEAR.reg = WDT_CLEAR_CLEAR_KEY;
  while (WDT->STATUS.bit.SYNCBUSY);  // Syncronize write to CLEAR reg.
}

// RA_STRING1=U2FsdGVkX19hO6KSSw/SEWReqPKC34stYAL4B8vahEY=
// RA_STRING2=U2FsdGVkX1+BPena6vAB/qszbCcvez8FgwKcXXxBbYg=
// RA_STRING3=test
Be aware that you will need to copy and paste the last 3 lines of the code to match whatever you have from your own code that you generated from the webwizard.
Roberto.
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Cloud Wifi Attachment

Post by slm222 »

LucianoB wrote:
slm222 wrote:Thank you Rimai. Most of today it has not been connected, just blinking green. If it makes any difference I had used the webwizard to program the reef angel plus.
Hi. What Router are you using?
I has a lot of the problems with one mikrotik Router. I changed that so everything are working fine.. if you can only test with another Router.

Regards from Argentina.
Cheers

Enviado desde mi Nexus 5 mediante Tapatalk
I am using an ASUS router, but no changes have been made and the intermittent issues started out of now where. I have a Linksys AC2400 coming in to try that as well.
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Cloud Wifi Attachment

Post by slm222 »

rimai wrote:See if this code makes any difference.
I will add this into my cloud device tonight. Thank you

This is your rewritten code with my info at the bottom i will add

Code: Select all

#include <SPI.h>
#include <WiFi101.h>
#include <PubSubClient.h>
#include <RA_CustomSettings.h>

//char ssid[32];
//char pass[32];
//char username[16];
//char password[16];

unsigned long client_timeout = millis();
unsigned long wifi_connection = millis();
unsigned long serial_timeout = millis();
unsigned long led_blink = millis();
unsigned long MQTTReconnectmillis = millis();

boolean LED_status = false;
boolean PortalConnection = false;
boolean power_status = true;
boolean data_ready = false;
int status = WL_IDLE_STATUS;
int connection_counter=0;
WiFiServer server(2000);
WiFiClient client;
WiFiClient portalclient;
WiFiClient mqttclient;

void mqttcallback(char* topic, byte* payload, unsigned int length);

PubSubClient CloudClient(MQTTServer, MQTTPORT, mqttcallback, mqttclient);

String currentLine = "";                // make a String to hold incoming data from the client

void setup() {
  Serial.begin(57600);      // initialize serial communication
  Serial1.begin(57600);      // initialize serial communication
  pinMode(5, OUTPUT);      // set the LED pin mode
  pinMode(6, OUTPUT);      // set the LED pin mode
  pinMode(7, OUTPUT);      // set the LED pin mode
  wdt_initialize();
  wdt_enable();
}

void loop() {
  wdt_reset();
  status = WiFi.status();
  while ( status != WL_CONNECTED) {
    digitalWrite(5, false);
    digitalWrite(6, true);
    digitalWrite(7, false);
    if (millis() - wifi_connection > 1000)
    {
      wifi_connection = millis();
      Serial.print("Attempting to connect to Network named: ");
      Serial.println(WIFI_SSID);                   // print the network name (SSID);
      if (WiFi.begin(WIFI_SSID, WIFI_PASS) == WL_CONNECTED)
      {
        status = WiFi.status();
        server.begin();                           // start the web server on port 2000
        printWifiStatus();                        // you're connected now, so print out the status
        digitalWrite(6, false);
        digitalWrite(7, true);
      }
      Serial.println("Not connected...");
    }
    wdt_reset();
  }

  client = server.available();   // listen for incoming clients

  if (client) {                             // if you get a client,
    Serial.println(F("new incoming client"));           // print a message out the serial port
    client_timeout = millis();
    while (client.connected()) {            // loop while the client's connected
      if (millis() - client_timeout > 2000) client.stop();
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        Serial1.write(c);                   // send to Reef Angel
      }
      if (Serial1.available())
      {
        char c = Serial1.read();
        //Serial.write(c);
        currentLine += c;
        serial_timeout = millis();
        if (currentLine.length() == 255) {
          SendData();
        }
      }
      if (millis() - serial_timeout > 400)
      {
        if (currentLine.length() > 0) {
          SendData();
          Serial.println();
          client.println();
        }
      }
      if (millis() - led_blink > 50)
      {
        led_blink = millis();
        LED_status = !LED_status;
        digitalWrite(6, LED_status);
      }
    }
    // close the connection:
    client.stop();
    Serial.println(F("incoming client disconnected"));
    digitalWrite(6, false);
  }
  else
  {
    while (Serial1.available())
    {
      char c = Serial1.read();
      currentLine += c;
      if(c==10) data_ready=true;
      serial_timeout = millis();
      digitalWrite(6, true);
      if (millis() - serial_timeout > 200 || data_ready)
      {
        if (currentLine.length() > 0) 
        {
          data_ready=false;
          serial_timeout = millis();
          //        Serial.print(currentLine);
          if (currentLine.startsWith("GET"))
          {
            PortalConnection = true;
            Serial.println(F("Connecting to Portal Server"));
            if (portalclient.connect(PortalServer, 80)) {
              Serial.println(F("Connected"));
              // Make a HTTP request:
              portalclient.print(currentLine);
              portalclient.println(F(" HTTP/1.1"));
              portalclient.println(F("Host: forum.reefangel.com"));
              portalclient.println(F("Connection: close"));
              portalclient.println();
            }
            else
            {
              Serial.println(F("Failed to connect"));
            }
          }
          if (currentLine.startsWith("CLOUD:"))
          {
            //Serial.print(currentLine);
            if (currentLine.length() < 32)
            {
              if (CloudClient.connected())
              {
                //Serial.println(F("Publishing "));
                currentLine.replace("CLOUD:", "");
                Serial.print(currentLine);
                char pub_buffer[sizeof(CLOUD_USERNAME) + 5];
                sprintf(pub_buffer, "%s/out", CLOUD_USERNAME);
                char pub_msg[currentLine.length() + 1];
                currentLine.toCharArray(pub_msg, currentLine.length() + 1);
                CloudClient.publish(pub_buffer, pub_msg);
              }
            }
            else
            {
              Serial.print(F("Error on incoming data: "));
              Serial.println(currentLine.length());
            }
          }
          currentLine = "";
          digitalWrite(6, false);
        }
      }
    }
    digitalWrite(6, false);    
    while (portalclient.available()) {
      char c = portalclient.read();
      //      Serial.write(c);
    }
    if (PortalConnection && !portalclient.connected()) {
      PortalConnection = false;
      //      Serial.println();
      Serial.println(F("Disconnecting from Portal Server"));
      digitalWrite(6, false);
      portalclient.stop();
    }
  }

  CloudClient.loop();
  if (millis() - MQTTReconnectmillis > 5000)
  {
    if (!CloudClient.connected())
    {
      char sub_buffer[sizeof(CLOUD_USERNAME) + 6];
      MQTTReconnectmillis = millis();
      digitalWrite(6, true);
      Serial.println(F("MQTT Connecting..."));
      Serial.print(F("Attemp: "));
      Serial.println(++connection_counter);
      if (connection_counter>5)
      {
        Serial.println(F("Unable to connect. Rebooting..."));
        digitalWrite(5, true);
        digitalWrite(6, false);
        digitalWrite(7, false);        
        while(1);
      }
      sprintf(sub_buffer, "RA-%s", CLOUD_USERNAME);
      if (CloudClient.connect(sub_buffer, CLOUD_USERNAME, CLOUD_PASSWORD))
      {
        sprintf(sub_buffer, "%s/in/#", CLOUD_USERNAME);
        Serial.println(F("MQTT succeeded"));
        CloudClient.subscribe(sub_buffer);
      }
      else
      {
        MQTTReconnectmillis = millis();
        Serial.println(F("MQTT failed"));
        CloudClient.disconnect();
      }
      digitalWrite(6, false);
    }
  }
  if (analogRead(0) < 600 && power_status)
  {
    power_status = false;
  }
  if (analogRead(0) > 600 && !power_status)
  {
    power_status = true;
  }
}

void SendData()
{
  serial_timeout = millis();
  //  Serial.print(currentLine);
  client.print(currentLine);
  currentLine = "";
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

void mqttcallback(char* topic, byte* payload, unsigned int length)
{
  Serial1.print("cloud:");
  for (int a=0;a<length;a++)
  {
    Serial1.write(payload[a]);
    Serial.write(payload[a]);
  }
  Serial1.print(" ");
  Serial.println();
}

void wdt_initialize()
{
  GCLK->GENDIV.reg = GCLK_GENDIV_ID(2) | GCLK_GENDIV_DIV(4);
  GCLK->GENCTRL.reg = GCLK_GENCTRL_ID(2) |
                      GCLK_GENCTRL_GENEN |
                      GCLK_GENCTRL_SRC_OSCULP32K |
                      GCLK_GENCTRL_DIVSEL;
  while (GCLK->STATUS.bit.SYNCBUSY);  // Syncronize write to GENCTRL reg.
  GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID_WDT |
                      GCLK_CLKCTRL_CLKEN |
                      GCLK_CLKCTRL_GEN_GCLK2;
}

void wdt_enable()
{
  WDT->CTRL.reg &= ~WDT_CTRL_ENABLE;
  while (WDT->STATUS.bit.SYNCBUSY);  // Syncronize write to CTRL reg.
  WDT->CONFIG.reg = WDT_CONFIG_PER(0xA);  // 0xA = 8192 ms
  while (WDT->STATUS.bit.SYNCBUSY);  // Syncronize write to CONFIG reg.
  WDT->INTENCLR.reg |= WDT_INTENCLR_EW;
  WDT->CTRL.reg |= WDT_CTRL_ENABLE;
  while (WDT->STATUS.bit.SYNCBUSY);  // Syncronize write to CTRL reg.
}

void wdt_disable()
{
  WDT->CTRL.reg &= ~WDT_CTRL_ENABLE;
  while (WDT->STATUS.bit.SYNCBUSY);  // Syncronize write to CTRL reg.
}

void wdt_reset()
{
  WDT->CLEAR.reg = WDT_CLEAR_CLEAR_KEY;
  while (WDT->STATUS.bit.SYNCBUSY);  // Syncronize write to CLEAR reg.
}

// RA_STRING1=U2FsdGVkX1+McuCAkIlSsRrljZrxqPemQeco0gw3Qh0=
// RA_STRING2=U2FsdGVkX182otKKK42E19GJNzbCmJB4k/bR5D12l+Q=
// RA_STRING3=Monroe
MisterTang
Posts: 58
Joined: Sat Jan 04, 2014 3:12 pm

Re: Cloud Wifi Attachment

Post by MisterTang »

Roberto,

This looks really cool - but I'm not seeing a UApp for Android in the store but do see one in the iTunes store. Is there a plan to officially support Android?
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Cloud Wifi Attachment

Post by rimai »

The Uapp should be in the apple store, but it is an outdated version.
It was originally designed to be the Apple app and got migrated to a web based application since it is entirely created as a web application natively.
I can also post on the Android store too.
I'm just waiting to get all the bugs out before I released it on both stores. It's a pain to release to the stores :(
In the mean time, you can use the browser of your phone to make it work.
Roberto.
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Cloud Wifi Attachment

Post by slm222 »

I have loaded the code and it has been in a state of trying to connect for an hr. constant solid currently. It owuld blink occasionally when i first plugged it in.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Cloud Wifi Attachment

Post by rimai »

Can you pull log again?
Roberto.
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Cloud Wifi Attachment

Post by slm222 »

Ok, I tried to pull a log and it would not show a COM port to allow me to select. I disconnected the device and replugged in with my computer and COM showed up, i think plugged into the reef angel and it is working now. I was trying to get back before you had read my inital response as a simple reset fixed it. I will keep monitoring it and report back.

Again Thank you for your promptness, we are soon to travel out of the country and not being able to see the tank was a bit worrying to me.
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Cloud Wifi Attachment

Post by slm222 »

So something interesting is going on. and it had to do with the sequence of how i plugged the unit it. when i plug the unit into the reef angel it blinks green and goes solid green with an occasional blink, then when i plug into it with the computer to run the serial monitor the computer prompts that the usb was not recognized and disables and re-enables the port and at that point the wifi unit turns blue immediately and stays running. I unplugged the computer and it stayed blue, then after a while (longer than i know as i was not paying attention) the light completely turned off. Then the cycle starts over.
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Cloud Wifi Attachment

Post by slm222 »

I re uploaded as well reset the whole system and it is functioning now
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Cloud Wifi Attachment

Post by slm222 »

This is going on with both the old and the new routers. With the modified code below i am getting "Attempting to connect to Network named:
Not connected..." on the serial monitor scrolling over and over. It is staying constant green. With the webwizard code it is connecting to the wifi and upload but only when i have the usb cable plugged into the side and plugged into the computer. as soon as i unplug it changes to teal for a couple seconds and then goes back to solid green and an occansional blink. when i plug the usb back in it states the usb is not recognized and then refreshes the connection itself by diconnecting and reconnecting and at that point it turns blue and acts normal.

*Edit: something interesting i just tried. i plugged the usb cable into the side of the wifi unit and then into the iphone wall charger. it started working with that plugged in as well and the webwizard code.... not sure what to make of that.

Code: Select all

#include <SPI.h>
#include <WiFi101.h>
#include <PubSubClient.h>
#include <RA_CustomSettings.h>

//char ssid[32];
//char pass[32];
//char username[16];
//char password[16];

unsigned long client_timeout = millis();
unsigned long wifi_connection = millis();
unsigned long serial_timeout = millis();
unsigned long led_blink = millis();
unsigned long MQTTReconnectmillis = millis();

boolean LED_status = false;
boolean PortalConnection = false;
boolean power_status = true;
boolean data_ready = false;
int status = WL_IDLE_STATUS;
int connection_counter=0;
WiFiServer server(2000);
WiFiClient client;
WiFiClient portalclient;
WiFiClient mqttclient;

void mqttcallback(char* topic, byte* payload, unsigned int length);

PubSubClient CloudClient(MQTTServer, MQTTPORT, mqttcallback, mqttclient);

String currentLine = "";                // make a String to hold incoming data from the client

void setup() {
  Serial.begin(57600);      // initialize serial communication
  Serial1.begin(57600);      // initialize serial communication
  pinMode(5, OUTPUT);      // set the LED pin mode
  pinMode(6, OUTPUT);      // set the LED pin mode
  pinMode(7, OUTPUT);      // set the LED pin mode
  wdt_initialize();
  wdt_enable();
}

void loop() {
  wdt_reset();
  status = WiFi.status();
  while ( status != WL_CONNECTED) {
    digitalWrite(5, false);
    digitalWrite(6, true);
    digitalWrite(7, false);
    if (millis() - wifi_connection > 1000)
    {
      wifi_connection = millis();
      Serial.print("Attempting to connect to Network named: ");
      Serial.println(WIFI_SSID);                   // print the network name (SSID);
      if (WiFi.begin(WIFI_SSID, WIFI_PASS) == WL_CONNECTED)
      {
        status = WiFi.status();
        server.begin();                           // start the web server on port 2000
        printWifiStatus();                        // you're connected now, so print out the status
        digitalWrite(6, false);
        digitalWrite(7, true);
      }
      Serial.println("Not connected...");
    }
    wdt_reset();
  }

  client = server.available();   // listen for incoming clients

  if (client) {                             // if you get a client,
    Serial.println(F("new incoming client"));           // print a message out the serial port
    client_timeout = millis();
    while (client.connected()) {            // loop while the client's connected
      if (millis() - client_timeout > 2000) client.stop();
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        Serial1.write(c);                   // send to Reef Angel
      }
      if (Serial1.available())
      {
        char c = Serial1.read();
        //Serial.write(c);
        currentLine += c;
        serial_timeout = millis();
        if (currentLine.length() == 255) {
          SendData();
        }
      }
      if (millis() - serial_timeout > 400)
      {
        if (currentLine.length() > 0) {
          SendData();
          Serial.println();
          client.println();
        }
      }
      if (millis() - led_blink > 50)
      {
        led_blink = millis();
        LED_status = !LED_status;
        digitalWrite(6, LED_status);
      }
    }
    // close the connection:
    client.stop();
    Serial.println(F("incoming client disconnected"));
    digitalWrite(6, false);
  }
  else
  {
    while (Serial1.available())
    {
      char c = Serial1.read();
      currentLine += c;
      if(c==10) data_ready=true;
      serial_timeout = millis();
      digitalWrite(6, true);
      if (millis() - serial_timeout > 200 || data_ready)
      {
        if (currentLine.length() > 0) 
        {
          data_ready=false;
          serial_timeout = millis();
          //        Serial.print(currentLine);
          if (currentLine.startsWith("GET"))
          {
            PortalConnection = true;
            Serial.println(F("Connecting to Portal Server"));
            if (portalclient.connect(PortalServer, 80)) {
              Serial.println(F("Connected"));
              // Make a HTTP request:
              portalclient.print(currentLine);
              portalclient.println(F(" HTTP/1.1"));
              portalclient.println(F("Host: forum.reefangel.com"));
              portalclient.println(F("Connection: close"));
              portalclient.println();
            }
            else
            {
              Serial.println(F("Failed to connect"));
            }
          }
          if (currentLine.startsWith("CLOUD:"))
          {
            //Serial.print(currentLine);
            if (currentLine.length() < 32)
            {
              if (CloudClient.connected())
              {
                //Serial.println(F("Publishing "));
                currentLine.replace("CLOUD:", "");
                Serial.print(currentLine);
                char pub_buffer[sizeof(CLOUD_USERNAME) + 5];
                sprintf(pub_buffer, "%s/out", CLOUD_USERNAME);
                char pub_msg[currentLine.length() + 1];
                currentLine.toCharArray(pub_msg, currentLine.length() + 1);
                CloudClient.publish(pub_buffer, pub_msg);
              }
            }
            else
            {
              Serial.print(F("Error on incoming data: "));
              Serial.println(currentLine.length());
            }
          }
          currentLine = "";
          digitalWrite(6, false);
        }
      }
    }
    digitalWrite(6, false);    
    while (portalclient.available()) {
      char c = portalclient.read();
      //      Serial.write(c);
    }
    if (PortalConnection && !portalclient.connected()) {
      PortalConnection = false;
      //      Serial.println();
      Serial.println(F("Disconnecting from Portal Server"));
      digitalWrite(6, false);
      portalclient.stop();
    }
  }

  CloudClient.loop();
  if (millis() - MQTTReconnectmillis > 5000)
  {
    if (!CloudClient.connected())
    {
      char sub_buffer[sizeof(CLOUD_USERNAME) + 6];
      MQTTReconnectmillis = millis();
      digitalWrite(6, true);
      Serial.println(F("MQTT Connecting..."));
      Serial.print(F("Attemp: "));
      Serial.println(++connection_counter);
      if (connection_counter>5)
      {
        Serial.println(F("Unable to connect. Rebooting..."));
        digitalWrite(5, true);
        digitalWrite(6, false);
        digitalWrite(7, false);        
        while(1);
      }
      sprintf(sub_buffer, "RA-%s", CLOUD_USERNAME);
      if (CloudClient.connect(sub_buffer, CLOUD_USERNAME, CLOUD_PASSWORD))
      {
        sprintf(sub_buffer, "%s/in/#", CLOUD_USERNAME);
        Serial.println(F("MQTT succeeded"));
        CloudClient.subscribe(sub_buffer);
      }
      else
      {
        MQTTReconnectmillis = millis();
        Serial.println(F("MQTT failed"));
        CloudClient.disconnect();
      }
      digitalWrite(6, false);
    }
  }
  if (analogRead(0) < 600 && power_status)
  {
    power_status = false;
  }
  if (analogRead(0) > 600 && !power_status)
  {
    power_status = true;
  }
}

void SendData()
{
  serial_timeout = millis();
  //  Serial.print(currentLine);
  client.print(currentLine);
  currentLine = "";
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

void mqttcallback(char* topic, byte* payload, unsigned int length)
{
  Serial1.print("cloud:");
  for (int a=0;a<length;a++)
  {
    Serial1.write(payload[a]);
    Serial.write(payload[a]);
  }
  Serial1.print(" ");
  Serial.println();
}

void wdt_initialize()
{
  GCLK->GENDIV.reg = GCLK_GENDIV_ID(2) | GCLK_GENDIV_DIV(4);
  GCLK->GENCTRL.reg = GCLK_GENCTRL_ID(2) |
                      GCLK_GENCTRL_GENEN |
                      GCLK_GENCTRL_SRC_OSCULP32K |
                      GCLK_GENCTRL_DIVSEL;
  while (GCLK->STATUS.bit.SYNCBUSY);  // Syncronize write to GENCTRL reg.
  GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID_WDT |
                      GCLK_CLKCTRL_CLKEN |
                      GCLK_CLKCTRL_GEN_GCLK2;
}

void wdt_enable()
{
  WDT->CTRL.reg &= ~WDT_CTRL_ENABLE;
  while (WDT->STATUS.bit.SYNCBUSY);  // Syncronize write to CTRL reg.
  WDT->CONFIG.reg = WDT_CONFIG_PER(0xA);  // 0xA = 8192 ms
  while (WDT->STATUS.bit.SYNCBUSY);  // Syncronize write to CONFIG reg.
  WDT->INTENCLR.reg |= WDT_INTENCLR_EW;
  WDT->CTRL.reg |= WDT_CTRL_ENABLE;
  while (WDT->STATUS.bit.SYNCBUSY);  // Syncronize write to CTRL reg.
}

void wdt_disable()
{
  WDT->CTRL.reg &= ~WDT_CTRL_ENABLE;
  while (WDT->STATUS.bit.SYNCBUSY);  // Syncronize write to CTRL reg.
}

void wdt_reset()
{
  WDT->CLEAR.reg = WDT_CLEAR_CLEAR_KEY;
  while (WDT->STATUS.bit.SYNCBUSY);  // Syncronize write to CLEAR reg.
}

// RA_STRING1=U2FsdGVkX1+AF2lnzKYQyNPLiQGZJdj0GFAKsjt2XXk=
// RA_STRING2=U2FsdGVkX1+K7xN24vw/vykDiKano9Ep9ArQL7gfcck=
// RA_STRING3=Monroe
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Cloud Wifi Attachment

Post by slm222 »

Anyone?
Post Reply