Cloud Wifi Attachment

Expansion modules and attachments

Posts: 12309
Joined: Fri Mar 18, 2011 6:47 pm
PostPosted: Mon May 08, 2017 9:59 am
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.

Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm
PostPosted: Fri May 19, 2017 7:02 pm
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

Posts: 12309
Joined: Fri Mar 18, 2011 6:47 pm
PostPosted: Fri May 19, 2017 8:03 pm
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.

Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm
PostPosted: Fri May 19, 2017 8:46 pm
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

Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm
PostPosted: Fri May 26, 2017 11:08 am
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...

Posts: 12309
Joined: Fri Mar 18, 2011 6:47 pm
PostPosted: Mon May 29, 2017 10:04 am
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.

Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm
PostPosted: Mon May 29, 2017 6:19 pm
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.

Posts: 20
Joined: Fri Mar 11, 2016 4:39 pm
PostPosted: Tue May 30, 2017 11:12 am
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

Posts: 12309
Joined: Fri Mar 18, 2011 6:47 pm
PostPosted: Tue May 30, 2017 8:37 pm
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.

Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm
PostPosted: Wed May 31, 2017 1:39 pm
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.
PreviousNext

Return to Addons

Who is online

Users browsing this forum: No registered users and 2 guests