1. WiFi connection

Arduino MKR1000 has been Wi-Fi connectivity requiring minimal previous experience in networking.

It is based on the Atmel ATSAMW25 SoC (System on Chip). The ATSAMW25 is composed of three main blocks and one PCB Antenna

  • SAMD21 Cortex-M0+ 32bit low power ARM MCU
  • WINC1500 low power 2.4GHz IEEE® 802.11 b/g/n Wi-Fi
  • ECC508 CryptoAuthentication
  • 1x1 stream PCB Antenna.

Maybe it will make some effort if one try to use standard wifi library of arduino. While more appropriate choice is WiFi101 library, since it is totally compatible.

Here is one simple ping test, what you shall do is to fill in the ssid and password of your wifi. It shall be noted the ECC508 CryptoAuthentication is not standard configuration in wifi modules, it offer better security against unauthorized access.

#include <SPI.h>

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

#include "arduino_secrets.h" 
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS;     // the WiFi radio's status

// Specify IP address or hostname
String hostName = "www.google.com";
int pingResult;

void setup() {
  // Initialize serial and wait for port to open:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);

  // attempt to connect to WiFi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);

    // wait 5 seconds for connection:

  // you're connected now, so print out the data:
  Serial.println("You're connected to the network");

void loop() {
  Serial.print("Pinging ");
  Serial.print(": ");

  pingResult = WiFi.ping(hostName);

  if (pingResult >= 0) {
    Serial.print("SUCCESS! RTT = ");
    Serial.println(" ms");
  } else {
    Serial.print("FAILED! Error code: ");


The serial console output the following ,

The ping fails because the computer firewall block the process, so, it is Ok.


2. Pubnub service

Pubnub is evolving continuously. New service like chatengine is produced. While in this project IoT message is used for Securely monitor, control, provision and stream data between smart devices, sensor networks, hubs, and more. Trigger device action, monitor meta data, or stream and process incoming and outgoing data. PubNub provides the infrastructure and APIs for communication for any size IoT deployment.

It is a little more complex than wifi connection. But it is still as easy as you can image. Just fill the pubkey, subkey, pubnub channel. Then everything is Ok. The Arduino library packing everything.

For me, the challenge part is in far end of mobile application subscribe to the pubnub channel. I will take more time on it.

But the sketch returns well below.

The error code is fairly normal, since using public subkey as "demo" . The quota is exceed very soon. If using private subkey, the result will be good.

Here is the main part of the code.

Below is code, but for better understanding , this getting start blog shall be referred.

void setup() {
  // put your setup code here, to run once:
  Serial.println("Serial set up");

  // attempt to connect using WPA2 encryption:
  Serial.println("Attempting to connect to WPA network...");
  status = WiFi.begin(ssid, pass);

  // if you're not connected, stop here:
  if ( status != WL_CONNECTED) {
    Serial.println("Couldn't get a wifi connection");
    while (true);
  } else {
    Serial.print("WiFi connecting to SSID: ");

    PubNub.begin(pubkey, subkey);
    Serial.println("PubNub set up");

void loop() {

  /* Publish */
  WiFiClient *client;
  char msg[] = "\"Yo!\"";

  client = PubNub.publish(channel, msg);

  if (!client) {
    Serial.println("publishing error");
  if (PubNub.get_last_http_status_code_class() != PubNub::http_scc_success) {
    Serial.print("Got HTTP status code error from PubNub, class: ");
    Serial.print(PubNub.get_last_http_status_code_class(), DEC);
  while (client->available()) {