This solution starter was created as part of the IBM call for code.
- Johnny Chalikiopoulos
- Ioannis Katsoridas
- Eirini Lygerou
Our planet is dying. The main energy resources are being depleted and the global energy challenges are increasing, and this can only lead to catastrophic results. Today’s generation takes the natural elements for granted and does not regard for their sustainability and survival. This disrespect, though, will leave the planet in an uninhabitable state for future generations and force them into an apocalyptic scenario, despite them not being at fault. It is of vital importance, therefore, to take action now against this dystopian prediction and secure a bright and vivid next day. To achieve that, we need to protect our ecosystem and find ways with which to imprint this need to every person’s mind. This needs to be a holistic approach and we all need to collaborate for its success.
This is the problem that Sunstain comes to solve. By understanding the current landscape and the importance of the depletion of natural resources, Sunstain provides an easy and accessible solution for everyone to use. It takes advantage of one of the few elements that can assist in producing energy without harming the environment at the same time, the sun. By harvesting solar energy, most of our everyday needs can be satisfied without requiring additional sources. Several households, though, produce more that they can consume, leaving them with both wasted energy and increased costs. By using Sunstain they are given the option to sell that extra energy to willing buyers and recycle it instead of throwing it away.
The whole process takes place inside the Sunstain mobile application. Users can either sell some the solar energy they produce to assist in sustaining the environment while making financial profit along the way or buy from existing buyers. This is achieved through a bidding contest where participants share the price they are willing to pay for a given service. The seller can then select the desired user. The settled agreement with the national energy providers ensures the smooth transition and billing of the service and the recipient will be able to take advantage of the solar energy purchased without other complications.
The solution is a mobile interface and a data storage to hold the energy products. In the client side we have a mobile application (both in IOS and Android) developed with React native and on the server side we have the utilized the IBM Cloud and IBM Cloudant.
- The user sign ups and can be a buyer or seller interchangably.
- The user can buy/search or sell energy products.
- The energy provider sends a confirmation via a notification when the purchase is processed.
- The user can view previws history and edit his own products availabe for sale.
- Register for an IBM Cloud account.
- Install and configure IBM Cloud CLI.
- Install React Native CLI dependencies. See the React Native documentation for the exact steps and requirements based on your Operating System and Target OS. For example:
- iOS on macOS
- Android on Windows
- Node.js
- Java Development Kit
- Android Studio - add Android 9 (Pie) SDK & configure
ANDROID_HOME
- Create an Android Virtual Device (AVD) - with Pie image (API Level 28)
- Clone the repository.
- Provision a CouchDB instance using Cloudant.
- Run the server.
- Run the react native engine.
- Run the mobile application.
Log into the IBM Cloud and provision a CouchDB instance using Cloudant.
- From the catalog, select Databases and then the Cloudant panel.
- Once selected, you can choose your Cloudant plan -- there is a free tier for simple testing that is sufficient to run this CIR example. You should choose an appropriate region, give the service a name, and it is recommended you choose Use only IAM under Available authentication methods. You can leave the other settings with their defaults. Click the blue Create button when ready.
- Once your Cloudant instance has been created, you need to create a service credential that the CIR API Server can use to communicate with it. By selecting your running Cloudant instance, you can choose Service credentials from the left-hand menu. Create a new service credential and give it a name (it doesn't matter what you call it).
- Once created, you can display the credentials by selecting view service credentials, and then copy the credential, so you are ready to paste it into the code of the API server in Step 4.
To set up and launch the server application:
- Go to the
Sunstain/server
directory of the cloned repo. - Copy the
.env.example
file in theSunstain/server
directory, and create a new file named.env
. - Edit the name value in the
manifest.yml
file to your application name (for example, my-app-name). - From a terminal:
- Go to the
Sunstain/server
directory of the cloned repo. - Install the dependencies:
npm install
. - Launch the server application locally or deploy to IBM Cloud:
- To run locally:
- Start the application:
npm start
. - The server can be accessed at http://localhost:3000.
- Start the application:
- To deploy to IBM Cloud (Optional):
- Log in to your IBM Cloud account using the IBM Cloud CLI:
ibmcloud login
. - Target a Cloud Foundry org and space:
ibmcloud target --cf
. - Push the app to IBM Cloud:
ibmcloud app push
. - The server can be accessed at a URL using the name given in the
manifest.yml
file (for example, https://my-app-name.bluemix.net).
- Log in to your IBM Cloud account using the IBM Cloud CLI:
- To run locally:
- Go to the
To run the react-native engine
- Go to the
Sunstain
directory of the cloned repo. - Open a cmd and run
npx react-native start
To run the mobile application (using the Xcode iOS Simulator or Android Studio Emulator):
-
Go to the
Sunstain
directory of the cloned repo. -
Copy the
.env.example
file in theSunstain
directory, and create a file named.env
. -
Edit the newly created
.env
file:- Update the
SUNSTAIN_SERVER_URL
with the URL to the server app launched in the previous step.Note: If you are running the server locally and testing with the Android Emulator set the
SUNSTAIN_SERVER_URL
using the local machine's URL (e.g.,http://10.0.2.2:3000
) instead oflocalhost
- Update the
-
From a terminal:
- Go to the
Sunstain
directory. - Install the dependencies:
yarn install
. - iOS only: Go to the
ios
directory:cd ios
. - iOS only: Install pod dependencies:
pod install
. - iOS only: Return to the
mobile-app
directory:cd ../
. - Launch the app in the simulator/emulator:
- iOS only:
npm run ios
Note: You should be running at least iOS 13.0. The first time you launch the simulator, you should ensure that you set a Location in the Features menu.
- Android only:
npx react-native run-android
Note: Your Android Studio needs to have the
Android 9 (Pie)
SDK and aPie API Level 28
virtual device - Alternative way to run on Android:
react-native run-android
- Android only: Open Android Studio and setup the project with the android folder.
- Android only: Open Android Virtual Device Manager and launch the virtual device installed.
- Android only: Click on Debug in Android Studio.
- iOS only:
- Go to the
With the application running in the simulator/emulator, you should be able to navigate through the various screens:
This solution is made available under the GNU General Public License v3.0.