Skip to content

Instantly share code, notes, and snippets.

@dimme
Last active August 29, 2015 14:00
Show Gist options
  • Save dimme/11385841 to your computer and use it in GitHub Desktop.
Save dimme/11385841 to your computer and use it in GitHub Desktop.
#include <SPI.h>
#include <SFE_CC3000.h>
#include "SoftwareSerial.h"
#include <Thermal.h>
// Pins
#define CC3000_INT 2 // Needs to be an interrupt pin (D2/D3)
#define CC3000_EN 7 // Can be any digital pin
#define CC3000_CS 10 // Preferred is pin 10 on Uno
// Connection info data lengths
#define IP_ADDR_LEN 4 // Length of IP address in bytes
// Constants
int printer_RX_Pin = 5; // This is the green wire
int printer_TX_Pin = 6; // This is the yellow wire
char ap_ssid[] = "SSID"; // SSID of network
char ap_password[] = "PASSWORD"; // Password of network
unsigned int ap_security = WLAN_SEC_WPA2; // Security of network
unsigned int timeout = 30000; // Milliseconds
char remote_host[] = "google.com"; // Host to ping
// Global Variables
SFE_CC3000 wifi = SFE_CC3000(CC3000_INT, CC3000_EN, CC3000_CS);
Thermal printer(printer_RX_Pin, printer_TX_Pin, 19200);
void setup() {
ConnectionInfo connection_info;
IPAddr ip_addr;
IPAddr remote_ip;
PingReport ping_report = {0};
int i;
// Initialize CC3000 (configure SPI communications)
wifi.init();
// Connect and wait for DHCP-assigned IP address
wifi.connect(ap_ssid, ap_security, ap_password, timeout);
// Gather connection details and print IP address
wifi.getConnectionInfo(connection_info);
// Perform a DNS lookup to get the IP address of a host
wifi.dnsLookup(remote_host, remote_ip);
// Ping IP address of remote host
if (wifi.ping(remote_ip, ping_report, 3, 56, 1000) ) {
printer.println("P");
}
}
void loop() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment