GR-PEACH Special Project: Graph Indication of a Sensor’s Value

Web Server Part 2


Let's show the value of the sensor in a graph on a web browser.


You will need a GR-PEACH board, USB cable (Micro B type), LAN cable, Micro SD card, illuminance sensor (NJL7502L), and 10kΩ of resistance.

Connecting the Illuminance Sensor

Sample Program for Graph Indication of the Sensor’s Value

First, save the "index.htm" and "mbedrpc.js" file to the Micro SD for browser indication.

Right click the following links and execute “save the object in a file“ for download.

Next, insert the Micro SD into an SD socket on the back side of GR-PEACH and copy to build the following sketch program in gr_sketch.cpp, write it down to GR-PEACH.

#include <Arduino.h>
#include "HTTPServer.h"
#include "mbed_rpc.h"
#include "SdUsbConnect.h"
//#define USE_WIFI
#ifdef USE_WIFI
#include "ESP32Interface.h"
ESP32Interface network;
#define WLAN_SSID            ("xxxxxxxx")
#define WLAN_PSK             ("xxxxxxxx")
#include "EthernetInterface.h"
EthernetInterface network;
/** Network setting **/
#define USE_DHCP               (1)
#if (USE_DHCP == 0)
#define IP_ADDRESS           ("")     /* IP address      */
#define SUBNET_MASK          ("")    /* Subnet mask     */
#define DEFAULT_GATEWAY      ("")     /* Default gateway */
SdUsbConnect storage("storage");
void AnalogRead(Arguments* arg, Reply* r);
int char_to_int(char* c, int len);
int char_to_int(char* c, int len){
  int r = 0;
  for (int i = 0; i < len; i++) {
    if (c[i] == 0) break;
    r = r * 10 + c[i] - '0';
  return r;
void AnalogRead(Arguments* arg, Reply* r){
  int pin;
  int ret;
  char rpc_analogread_buf[4];
  if (arg != NULL) {
    pin = char_to_int(arg->argv[0], 2);
    /* command analysis and execute */
    ret = analogRead(pin);
    sprintf(rpc_analogread_buf, "%d", ret);
    r->putData<const char*>(rpc_analogread_buf);
void setup(void) {
  Serial.println("********* PROGRAM START ***********");
  // SD & USB
  Serial.print("Finding strage..");
  RPCFunction rpc_sensorread(&AnalogRead, "AnalogRead");
  Serial.print("Network Setting up...\r\n");
#if (USE_DHCP == 0)
  if (network.set_network(IP_ADDRESS, SUBNET_MASK, DEFAULT_GATEWAY) != 0) { //for Static IP Address (IPAddress, NetMasks, Gateway)
#ifdef USE_WIFI
  network.set_credentials(WLAN_SSID, WLAN_PSK, WLAN_SECURITY);
  if (network.connect() != 0) {
  Serial.print("MAC Address is ");
  Serial.print("IP Address is ");
  Serial.print("NetMask is ");
  Serial.print("Gateway Address is ");
  Serial.println("Network Setup OK\r\n");
  FSHandler::mount("/storage", "/");
  HTTPServerStart(&network, 80);
void loop() {

Operation Check for the Graph Indication of the Sensor’s Value

After writing to GR-PEACH, start a serial monitor such as Tera Term; then, press the reset button on GR-PEACH. The IP address acquired by DHCP will be shown.

Put the displayed IP address into the URL on the web browser.

The value of the illuminance sensor will be displayed in a graph as shown here; the point where a graph falls down means darkness.